package com.hai.config;

import com.alibaba.fastjson.JSONObject;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.MD5Util;
import com.hai.entity.OutRechargeOrder;
import com.hai.entity.OutRechargePrice;
import com.hai.service.OutRechargeOrderService;
import com.hai.service.OutRechargePriceService;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName TelConfig
 * @Author Sum1Dream
 * @Version 1.0.0
 * @Description // 话费接口配置
 * @Date  2021/7/18 14:18
 **/
public class TelConfig {

    public  static JSONObject getMemberGoods() throws Exception {
        Map<String,Object> map = new HashMap<>();

        Long time = new Date().getTime();

        String sign = CommonSysConst.getSysConfig().getTelApiSecret() + "_" + time;

        map.put("apiKey", CommonSysConst.getSysConfig().getTelApiKey());
        map.put("memberId", CommonSysConst.getSysConfig().getTelMemberId());
        map.put("time", time);
        map.put("sign", MD5Util.encode(sign.getBytes()).toLowerCase());
        return HttpsUtils.doGet(CommonSysConst.getSysConfig().getTelUrl()+ "/getMemberGoods", map);
    }

    public static JSONObject order(Map<String,Object> mapOrder) throws Exception {

        Map<String,Object> map = new HashMap<>();
        Long time = new Date().getTime();

        String sign = CommonSysConst.getSysConfig().getTelApiSecret() + "_" + time;

        for (Map.Entry<String, Object> entry : mapOrder.entrySet()) {
            map.put(entry.getKey(), entry.getValue().toString());
        }

        map.put("apiKey", CommonSysConst.getSysConfig().getTelApiKey());
        map.put("memberId", CommonSysConst.getSysConfig().getTelMemberId());
        map.put("time", time);

        map.put("sign", MD5Util.encode(sign.getBytes()).toLowerCase());
        return HttpsUtils.doGet(CommonSysConst.getSysConfig().getTelUrl()+ "/getMemberGoods", map);
    }


    public static JSONObject checkingOrder(Map<String,Object> mapOrder) throws Exception {

        Map<String,Object> map = new HashMap<>();
        Long time = new Date().getTime();

        String sign = CommonSysConst.getSysConfig().getTelApiSecret() + "_" + time;

        for (Map.Entry<String, Object> entry : mapOrder.entrySet()) {
            map.put(entry.getKey(), entry.getValue().toString());
        }

        map.put("apiKey", CommonSysConst.getSysConfig().getTelApiKey());
        map.put("memberId", CommonSysConst.getSysConfig().getTelMemberId());
        map.put("time", time);

        map.put("sign", MD5Util.encode(sign.getBytes()).toLowerCase());
        return HttpsUtils.doGet(CommonSysConst.getSysConfig().getTelUrl()+ "/order", map);
    }


}
