package com.thinkgem.jeesite.modules.pay.huanqiuhuiju.service;

import com.alibaba.fastjson.JSONObject;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.constant.ComCode;
import com.thinkgem.jeesite.common.utils.IdGen;
import com.thinkgem.jeesite.modules.pay.huanqiuhuiju.utils.HttpUtil;
import com.thinkgem.jeesite.modules.pay.huanqiuhuiju.utils.SignUtils;
import com.thinkgem.jeesite.modules.pay.juhezhong.utils.Bean2Map;
import com.thinkgem.jeesite.modules.pay.juhezhong.utils.MakeOrderNum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.SortedMap;

/**
 * 也是一种快捷支付的方式  接口文档：快捷支付接口说明V1.1.2
 */
@Transactional
@Service
public class HuanqiuhuijuService {

    /**
     * 支付
     * @param dto
     * @return
     * @throws Exception
     */
    public JSONObject huanqiuhuijuPay(JSONObject dto) throws Exception {
        SortedMap map = Bean2Map.JSONObject2SortedMap(dto);
        String sign = SignUtils.createSign(map, ComCode.HUANQIUHUIJU_MERCHANT_KEY);
        map.put("sign",sign);

        String result = HttpUtil.postRequest(ComCode.HUANQIUHUIJU_PAYURL,JSONObject.toJSONString(map));
        System.out.println("result:"+result);
        return JSONObject.parseObject(result);

    }

}
