package com.hai.config;

import com.alibaba.fastjson.JSONObject;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.DateUtil;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.WxUtils;

import org.springframework.stereotype.Component;

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
 **/
@Component
public class RechargeConfig {


    /**
    * @Author Sum1Dream
    * @name getProductsList.java
    * @Description // 获取龙阅产品
    * @Date 10:03 2022/5/24
    * @Param []
    * @return com.alibaba.fastjson.JSONObject
    */
    public  static JSONObject getProductsListByLy() throws Exception {
        Map<String,Object> paramMap = new HashMap<>();

        paramMap.put("userid" , CommonSysConst.getSysConfig().getLyMemberId());
        paramMap.put("sign", WxUtils.generateSignatureLy(paramMap , CommonSysConst.getSysConfig().getLyApiKey() , WXPayConstants.SignType.MD5));

        return HttpsUtils.doPost(CommonSysConst.getSysConfig().getLyPostUrl()+ "index/product", paramMap);
    }

    /**
    * @Author Sum1Dream
    * @name rechargeOrderByLy.java
    * @Description // 龙阅订单充值
    * @Date 09:57 2022/5/25
    * @Param [com.alibaba.fastjson.JSONObject]
    * @return com.alibaba.fastjson.JSONObject
    */
    public static JSONObject rechargeOrderByLy(JSONObject object) throws Exception {

        Map<String,Object> paramMap = new HashMap<>();

        paramMap.put("out_trade_num" , object.getString("out_trade_num"));
        paramMap.put("product_id" , object.getString("product_id"));
        paramMap.put("mobile" , object.getString("mobile"));
        paramMap.put("notify_url" , object.getString("notifyUrl"));
        paramMap.put("userid" , CommonSysConst.getSysConfig().getLyMemberId());
        paramMap.put("sign", WxUtils.generateSignatureLy(paramMap , CommonSysConst.getSysConfig().getLyApiKey() , WXPayConstants.SignType.MD5));
        return HttpsUtils.doPost(CommonSysConst.getSysConfig().getLyPostUrl()+ "index/recharge", paramMap);

    }


    /**
    * @Author Sum1Dream
    * @name checkOrderByLy.java
    * @Description // 龙阅查询订单结果
    * @Date 14:05 2022/5/24
    * @Param [com.alibaba.fastjson.JSONObject]
    * @return com.alibaba.fastjson.JSONObject
    */
    public static JSONObject checkOrderByLy(JSONObject object) throws Exception {

        Map<String,Object> paramMap = new HashMap<>();

        paramMap.put("userid" , CommonSysConst.getSysConfig().getLyMemberId());
        paramMap.put("out_trade_nums" , object.getString("out_trade_nums"));
        paramMap.put("sign", WxUtils.generateSignatureLy(paramMap , CommonSysConst.getSysConfig().getLyApiKey() , WXPayConstants.SignType.MD5));
        return HttpsUtils.doPost(CommonSysConst.getSysConfig().getLyPostUrl()+ "index/check", paramMap);
    }

    /**
     * @Author Sum1Dream
     * @name rechargeOrderByJj.java
     * @Description // 尖椒订单充值
     * @Date 09:57 2022/5/25
     * @Param [com.alibaba.fastjson.JSONObject]
     * @return com.alibaba.fastjson.JSONObject
     */
    public static JSONObject rechargeOrderByJj(JSONObject object) throws Exception {

        String timestamp = String.valueOf(System.currentTimeMillis());

        Map<String , Object> map = new HashMap<>();
        map.put("mobile" , object.getString("mobile"));
        map.put("amount" , object.getString("amount"));
        map.put("out_order_id" , object.getString("out_order_id"));
        map.put("app_key" , CommonSysConst.getSysConfig().getJjAppKey());
        map.put("timestamp" , timestamp.substring(0,timestamp.length()-3));
        map.put("notify_url" , object.getString("notifyUrl"));
        String signStr = WxUtils.generateSignatureAppSecret(map, CommonSysConst.getSysConfig().getJjAppSecret() , WXPayConstants.SignType.MD5);

        map.put("sign" , signStr);

        return HttpsUtils.doPost(CommonSysConst.getSysConfig().getJjUrl() + "createOrder" , map);

    }

    /**
     * @Author Sum1Dream
     * @name checkOrderByJj.java
     * @Description // 尖椒查询订单详情
     * @Date 09:57 2022/5/25
     * @Param [com.alibaba.fastjson.JSONObject]
     * @return com.alibaba.fastjson.JSONObject
     */
    public static JSONObject checkOrderByJj(JSONObject object) throws Exception {

        String timestamp = String.valueOf(System.currentTimeMillis());

        Map<String , Object> map = new HashMap<>();
        map.put("out_order_id" , object.getString("out_order_id"));
        map.put("app_key" , CommonSysConst.getSysConfig().getJjAppKey());
        map.put("timestamp" , timestamp.substring(0,timestamp.length()-3));
        map.put("notify_url" , CommonSysConst.getSysConfig().getLyNotifyUrl());

        String signStr = WxUtils.generateSignatureAppSecret(map, CommonSysConst.getSysConfig().getJjAppSecret() , WXPayConstants.SignType.MD5);

        map.put("sign" , signStr);

        return HttpsUtils.doPost(CommonSysConst.getSysConfig().getJjUrl() + "queryOrder" , map);

    }

    /**
    * @Author Sum1Dream
    * @name rechargeOrderByCy.java
    * @Description // 城宇话费下单
    * @Date 10:22 2022/7/14
    * @Param [com.alibaba.fastjson.JSONObject]
    * @return com.alibaba.fastjson.JSONObject
    */
    public static JSONObject rechargeOrderByCy(JSONObject object) throws Exception {

        Map<String,Object> paramMap = new HashMap<>();

        paramMap.put("agentOrderId" , object.getString("agentOrderId"));
        paramMap.put("productId" , object.getInteger("productId"));
        paramMap.put("mobile" , object.getString("mobile"));
        paramMap.put("timestamp" , DateUtil.date2String(new Date() , DateUtil.Y_M_D_HMS));
        paramMap.put("appid" , CommonSysConst.getSysConfig().getCyApiKey());
        paramMap.put("sign", WxUtils.generateSignatureCy(paramMap , CommonSysConst.getSysConfig().getCyAppSecret() , WXPayConstants.SignType.MD5));

        return HttpsUtils.doPostByCy(CommonSysConst.getSysConfig().getCyPostUrl()+ "/api/interface/recharge", paramMap);

    }

    /**
     * @Author Sum1Dream
     * @name rechargeOrderByCy.java
     * @Description // 城宇话费查询订单详情
     * @Date 10:22 2022/7/14
     * @Param [com.alibaba.fastjson.JSONObject]
     * @return com.alibaba.fastjson.JSONObject
     */
    public static JSONObject queryRechargeByCy(JSONObject object) throws Exception {

        Map<String,Object> paramMap = new HashMap<>();

        paramMap.put("orderId" , object.getString("orderNo"));
        paramMap.put("timestamp" , DateUtil.date2String(new Date() , DateUtil.Y_M_D_HMS));
        paramMap.put("appid" , CommonSysConst.getSysConfig().getCyApiKey());
        paramMap.put("sign", WxUtils.generateSignatureCy(paramMap , CommonSysConst.getSysConfig().getCyAppSecret() , WXPayConstants.SignType.MD5));

        return HttpsUtils.doPostByCy(CommonSysConst.getSysConfig().getCyPostUrl()+ "/api/interface/queryRecharge", paramMap);

    }

}
