package com.crm.pay.service.impl.pay;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.crm.pay.dto.finance.withdraw.automatic.FinanceWithdrawXfgPayDto;
import com.crm.pay.entity.FinanceDepositCallbackUpdateEntity;
import com.crm.pay.entity.callback.XfgPayCallbackEntity;
import com.crm.pay.entity.finance.withdraw.FinanceWithdrawApproveChannelEntity;
import com.crm.pay.entity.finance.withdraw.FinanceWithdrawApproveChannelSubmitEntity;
import com.crm.pay.entity.property.XfgPayPropertyEntity;
import com.crm.pay.entity.property.XfgPayWithdrawPropertyEntity;
import com.crm.pay.service.FinanceDepositService;
import com.crm.pay.service.XfgPayService;
import com.crm.pay.service.impl.base.BasePayServiceImpl;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.model.constant.PayConstants;
import com.crm.rely.backend.model.dto.finance.withdraw.FinanceWithdrawDto;
import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositAddEntity;
import com.crm.pay.entity.finance.withdraw.automatic.FinanceWithdrawInfoEntity;
import com.crm.pay.entity.finance.withdraw.automatic.FinanceWithdrawXfgPayEntity;
import com.crm.rely.backend.model.pojo.table.FinanceDepositTable;
import com.crm.rely.backend.model.pojo.table.SysRemitChannelTable;
import com.crm.rely.backend.model.pojo.table.SysRemittanceChannelTable;
import com.crm.rely.backend.core.exception.PayValidatedException;
import com.crm.rely.backend.core.exception.ServiceException;
import com.crm.rely.backend.service.MqSendService;
import com.crm.rely.backend.util.*;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Connection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Slf4j
@Service
public class XfgPayServiceImpl extends BasePayServiceImpl implements XfgPayService {

    @Autowired
    private FinanceDepositService financeDepositService;
    @Autowired
    private MqSendService mqSendService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String pay(FinanceDepositAddEntity balanceSaveEntity) throws Exception {
        //通道配置
        SysRemittanceChannelTable channel = getPayChannel(PayConstants.XFG_PAY_KEY);
        //通道配置实体
        XfgPayPropertyEntity payProperty = getPayProperty(channel, XfgPayPropertyEntity.class);

        balanceSaveEntity.setCurrency(channel.getCurrency());
        balanceSaveEntity.setTransformCurrency(channel.getTransformCurrency());

        FinanceDepositTable balanceTable = financeDepositService.save(balanceSaveEntity, channel);

        String url = getUrl(payProperty, balanceTable, balanceSaveEntity);
        
        return url;

    }

    /**
     * 回调处理数据
     *
     * @param callbackEntity
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String callback(XfgPayCallbackEntity callbackEntity) throws Exception {
        log.info(String.format("callback data:%s", JSON.toJSONString(callbackEntity)));

        if (Strings.isNullOrEmpty(callbackEntity.getSign())) {
            return Constants.FAIL;
        }
        //获取配置
        XfgPayPropertyEntity payProperty = getPayProperty(PayConstants.XFG_PAY_KEY, XfgPayPropertyEntity.class);

        boolean validate = validate(callbackEntity, payProperty);
        if (!validate) {
            return Constants.FAIL;
        }

        Map<String, String> map = new LinkedHashMap<>();
        map.put("pid", payProperty.getPid());
        map.put("out_trade_no", callbackEntity.getOut_trade_no());
        map.put("timestamp", DateUtil.getTimestamp());

        String sign = getSign(payProperty.getPrivateKey(), map);
        map.put("sign", sign);
        map.put("sign_type", "RSA");

        Map<String, String> headers = new HashMap<>(1);
        headers.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

        Connection.Response response = HttpUtil.post(
                headers, payProperty.getBaseUrl() + payProperty.getDepositQueryUrl(), map);
        log.info(String.format("url:%s,request:%s,body:%s", payProperty.getDepositQueryUrl(), JSON.toJSONString(map),response.body()));

        JSONObject requestEntity = JSON.parseObject(response.body());
        if (requestEntity == null || requestEntity.getInteger("code") == null || requestEntity.getInteger("code") != 0) {
            log.error("Payment platform is abnormal, please try again later or contact customer service.");
            return Constants.FAIL;
        }

        if (!callbackEntity.getTrade_no().equals(requestEntity.getString("trade_no"))
                || !callbackEntity.getOut_trade_no().equals(requestEntity.getString("out_trade_no")) || new BigDecimal(callbackEntity.getMoney()).compareTo(new BigDecimal(requestEntity.getString("money"))) != 0) {
            return Constants.FAIL;
        }

        int status = PayConstants.CALLBACE_PROCESSING_STATUS;
        if (1 == requestEntity.getInteger("status")) {
            status = PayConstants.CALLBACE_SUCCESS_STATUS;
        }  else if ( 2 == requestEntity.getInteger("status") || 3 == requestEntity.getInteger("status")){
            status = PayConstants.CALLBACE_FAIL_STATUS;
        }

        FinanceDepositCallbackUpdateEntity balanceCallbackUpdateEntity =
                getFinanceDepositCallbackUpdateEntity(callbackEntity.getOut_trade_no(), callbackEntity.getTrade_no(),
                        status, callbackEntity);
        balanceCallbackUpdateEntity.setTransformAmount(new BigDecimal(callbackEntity.getMoney()));

        /**
         * 更新数据
         */
        financeDepositService.updateCallback(balanceCallbackUpdateEntity);
        return Constants.SUCCESS;
    }

    /**
     * 获取支付url
     *
     * @param balanceTable
     * @return
     * @throws ServiceException
     */
    private String getUrl(XfgPayPropertyEntity propertyEntity, FinanceDepositTable balanceTable,
                          FinanceDepositAddEntity balanceSaveEntity) throws Exception {
        String orderNo = balanceTable.getSerial() + "_" + balanceTable.getLogin();

        Map<String, String> map = new LinkedHashMap<>();
        map.put("pid", propertyEntity.getPid());
        map.put("method", "web");
        map.put("device", "jump");
        map.put("type", balanceSaveEntity.getBankCode());
        map.put("out_trade_no", orderNo);
        map.put("notify_url", propertyEntity.getNotifyUrl());
        map.put("return_url", propertyEntity.getReturnUrl());    //https://pay.44a5c8109e4.com/kubp/pickup
        map.put("name", propertyEntity.getName());
        map.put("money", String.format("%.2f", balanceTable.getTransformAmount().doubleValue()));
        map.put("clientip", balanceSaveEntity.getIp());
        map.put("timestamp", DateUtil.getTimestamp());

        String sign = getSign(propertyEntity.getPrivateKey(), map);
        map.put("sign", sign);
        map.put("sign_type", "RSA");

        Map<String, String> headers = new HashMap<>(1);
        headers.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

        Connection.Response response = HttpUtil.post(
                headers, propertyEntity.getBaseUrl() + propertyEntity.getDepositUrl(), map);
        log.info(String.format("url:%s,json:%s,body:%s", propertyEntity.getBaseUrl() + propertyEntity.getDepositUrl(), JSON.toJSONString(map), response.body()));

        JSONObject requestEntity = JSON.parseObject(response.body());
        if (requestEntity == null || requestEntity.getInteger("code") == null || requestEntity.getInteger("code") != 0) {
            throw new PayValidatedException("Payment platform is abnormal, please try again later or contact customer service.");
        }

        String url = requestEntity.getString("pay_info");
        log.info(String.format("支付请求,请求orderNo:%s,请求url:%s", map.get("out_trade_no"), url));

        return url;
    }

    @Override
    public FinanceWithdrawXfgPayDto withdrawInfo(FinanceWithdrawInfoEntity entity) throws Exception {
        FinanceWithdrawDto withdrawDto = null;
        if (entity.getWithdrawInfoType() == null || entity.getWithdrawInfoType().equals(1)) {
            withdrawDto = financeWithdrawService.searchSingle(entity.getId());

        } else {
            //withdrawDto = financeAgentWithdrawService.searchSingle(entity.getId());
        }
        entity.setPayType(PayConstants.XFG_PAY_TYPE_REMIT);

        SysRemitChannelTable withdrawChannel = getWithdrawChannel(entity.getPayType());

        FinanceWithdrawXfgPayDto dto = new FinanceWithdrawXfgPayDto();
        dto.setMoney(withdrawDto.getTransformAmount() == null ? null :
                withdrawDto.getTransformAmount().setScale(2, BigDecimal.ROUND_DOWN));
        dto.setName(withdrawDto.getName());
        dto.setType(withdrawDto.getBankCode());
        dto.setAccount(withdrawDto.getAddress());

        dto.setId(withdrawDto.getId());
        dto.setWithdrawUrl(withdrawChannel.getWithdrawUrl());
        dto.setSerial(withdrawDto.getSerial());
        dto.setPayType(entity.getPayType());
        return dto;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String withdraw(FinanceWithdrawXfgPayEntity entity) throws Exception {
        FinanceWithdrawDto withdrawDto = null;
        if (entity.getWithdrawInfoType() == null || entity.getWithdrawInfoType().equals(1)) {
            withdrawDto = financeWithdrawService.searchSingle(entity.getId());
        } else {
            //withdrawDto = financeAgentWithdrawService.searchSingle(entity.getId());
        }
        entity.setCId(withdrawDto.getCId());
        entity.setSerial(withdrawDto.getSerial());
        entity.setLogin(withdrawDto.getLogin());

        XfgPayWithdrawPropertyEntity propertyEntity =
                getWithdrawProperty(PayConstants.XFG_PAY_TYPE_REMIT, XfgPayWithdrawPropertyEntity.class);

        Integer status = payout(entity, propertyEntity);

        FinanceWithdrawApproveChannelSubmitEntity financeWithdrawApproveChannelSubmitEntity =
                new FinanceWithdrawApproveChannelSubmitEntity();
        financeWithdrawApproveChannelSubmitEntity.setSubmitStatus(PayConstants.PASSED_STATUS);
        financeWithdrawApproveChannelSubmitEntity.setId(entity.getId());
        financeWithdrawApproveChannelSubmitEntity.setActualPayType(entity.getPayType());
        if (entity.getWithdrawInfoType() == null || entity.getWithdrawInfoType().equals(1)) {
            financeWithdrawService.approve(financeWithdrawApproveChannelSubmitEntity);

        } else {
            //financeAgentWithdrawService.approve(financeWithdrawApproveChannelSubmitEntity);
        }

        if(status != null && status.equals(1)){
            mqSendService.send(PayConstants.XFG_PAY_REMIT_QUERY, entity);
        }else{
            for (int i = 0; i < 13; i++) {
                mqSendService.send(PayConstants.XFG_PAY_REMIT_QUERY, entity, (2 + i * 30) * 60 * 1000);
            }
        }

        return null;
    }

    private Integer payout(FinanceWithdrawXfgPayEntity entity, XfgPayWithdrawPropertyEntity propertyEntity) throws Exception {
        Map<String, String> map = new LinkedHashMap<>();
        map.put("pid", propertyEntity.getPid());
        map.put("type", entity.getType());
        map.put("account", entity.getAccount());
        map.put("name", entity.getName());
        map.put("money", String.format("%.2f", entity.getMoney().doubleValue()));
        if(!Strings.isNullOrEmpty(entity.getRemark())){
            map.put("remark", entity.getRemark());
        }
        map.put("out_biz_no", entity.getSerial());
        map.put("timestamp", DateUtil.getTimestamp());

        String sign = getSign(propertyEntity.getPrivateKey(), map);
        map.put("sign", sign);
        map.put("sign_type", "RSA");

        Map<String, String> headers = new HashMap<>(1);
        headers.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

        Connection.Response response = HttpUtil.post(
                headers,propertyEntity.getBaseUrl() + propertyEntity.getWithdrawUrl(), map );
        log.info(String.format("url:%s,json:%s,body:%s", propertyEntity.getBaseUrl() + propertyEntity.getWithdrawUrl(), JSON.toJSONString(map), response.body()));

        JSONObject requestEntity = JSON.parseObject(response.body());
        if (requestEntity == null || requestEntity.getInteger("code") == null || requestEntity.getInteger("code") != 0) {
            throw new PayValidatedException("Payment platform is abnormal, please try again later or contact customer service.");
        }

        return requestEntity.getInteger("status");
    }

    @JmsListener(destination = PayConstants.XFG_PAY_REMIT_QUERY)
    @Transactional(rollbackFor = Exception.class)
    public void withdrawCallback(String content) throws Exception {
        log.info(String.format("XFG_PAY_REMIT_QUERY,content:%s", content));
        FinanceWithdrawXfgPayEntity entity  = JSON.parseObject(content,FinanceWithdrawXfgPayEntity.class);
        if (entity == null) {
            return;
        }

        //获取配置
        XfgPayWithdrawPropertyEntity payProperty = getWithdrawProperty(PayConstants.XFG_PAY_TYPE_REMIT,
                XfgPayWithdrawPropertyEntity.class);


        Map<String, String> map = new LinkedHashMap<>();
        map.put("pid", payProperty.getPid());
        map.put("out_biz_no", entity.getSerial());
        map.put("timestamp", DateUtil.getTimestamp());

        String sign = getSign(payProperty.getPrivateKey(), map);
        map.put("sign", sign);
        map.put("sign_type", "RSA");

        Map<String, String> headers = new HashMap<>(1);
        headers.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

        Connection.Response response = HttpUtil.post(
                headers, payProperty.getBaseUrl() + payProperty.getWithdrawQueryUrl(), map);
        log.info(String.format("url:%s,json:%s,body:%s", payProperty.getBaseUrl() + payProperty.getWithdrawQueryUrl(), JSON.toJSONString(map), response.body()));

        JSONObject requestEntity = JSON.parseObject(response.body());
        if (requestEntity == null || requestEntity.getInteger("code") == null || requestEntity.getInteger("code") != 0) {
            throw new PayValidatedException("Payment platform is abnormal, please try again later or contact customer service.");
        }

        if (!entity.getSerial().equals(requestEntity.getString("out_biz_no")) ) {
            return;
        }

        FinanceWithdrawApproveChannelEntity financeWithdrawApproveChannelEntity =
                new FinanceWithdrawApproveChannelEntity();
        financeWithdrawApproveChannelEntity.setChannelSerial(requestEntity.getString("biz_no"));

        if (1 == requestEntity.getInteger("status")) {
            financeWithdrawApproveChannelEntity.setCallbackStatus(PayConstants.CALLBACE_SUCCESS_STATUS);
        }  else if ( 2 == requestEntity.getInteger("status")){
            financeWithdrawApproveChannelEntity.setCallbackStatus(PayConstants.CALLBACE_FAIL_STATUS);
        }

        financeWithdrawApproveChannelEntity.setSerial(entity.getSerial());

        /**
         * 更新数据
         */

        if (entity.getWithdrawInfoType() == null || entity.getWithdrawInfoType().equals(1)) {
            financeWithdrawService.approve(financeWithdrawApproveChannelEntity);

        } else {
            //financeAgentWithdrawService.channel(financeWithdrawApproveChannelEntity);
        }

    }

    /**
     * 验证回调参数是否被篡改
     *
     * @param callbackEntity
     * @return
     * @throws ServiceException
     */
    private boolean validate(XfgPayCallbackEntity callbackEntity, XfgPayPropertyEntity payProperty) throws Exception {
        Map<String, String> map = new LinkedHashMap<>();
        map.put("pid", String.valueOf(callbackEntity.getPid()));
        map.put("trade_no", callbackEntity.getTrade_no());
        map.put("out_trade_no", callbackEntity.getOut_trade_no());
        map.put("api_trade_no", callbackEntity.getApi_trade_no());
        map.put("type", callbackEntity.getType());
        map.put("trade_status", callbackEntity.getTrade_status());
        map.put("addtime", callbackEntity.getAddtime());
        map.put("endtime", callbackEntity.getEndtime());
        map.put("name", callbackEntity.getName());
        map.put("money", callbackEntity.getMoney());
        map.put("param", callbackEntity.getParam());
        map.put("buyer", callbackEntity.getBuyer());
        map.put("timestamp", callbackEntity.getTimestamp());

        String signString = MapUtil.getStringSortByKey(map,false,false);

        return SignUtil.verifySignSHA256withRSA(payProperty.getPublicKey(), signString, callbackEntity.getSign());
    }

    private static String getSign(String privateKey, Map<String, String> map) throws Exception {
        //构建字符串
        String signString = MapUtil.getStringSortByKey(map,false,false);
        String sign = SignUtil.signSHA256withRSA(privateKey, signString);

        log.info(String.format("加密处理--请求orderNo:%s,sign string:%s,sign:%s", map.get("out_trade_no"), signString, sign));
        return sign;
    }

    public static void main(String[] args) throws Exception {
        /*String con = "{\n" +
                "    \"baseUrl\":\"https://pay.dongfugui.xyz\",\n" +
                "    \"depositUrl\":\"/api/pay/create\",\n" +
                "    \"depositQueryUrl\":\"/api/pay/query\",\n" +
                "    \"notifyUrl\":\"https://pay.44a5c8109e4.com/xfgpay/callback\",\n" +
                "    \"returnUrl\":\"https://pay.44a5c8109e4.com/kubp/pickup\",\n" +
                "    \"pid\":\"1000\",\n" +
                "    \"name\":\"在线支付\",\n" +
                "    \"privateKey\":\"MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDCCS5bPrDo35remNAVMh0GfKGQ0v0bkyLZZTcBX+37m/5MR7wl07CtODf92dPF+4UW2BGmPfpaFcJFj5mOc+yFc08o2tq/jppA4HIkiSiRcqdFwoiq0owO5FiucR5tfz635mX1iCyvH10m7O/ivZs5AO/Gi/uIQqAf102gNaO6KVtGbhylZQMWDkBD7wOlF+3v428oo32Adxxu4vXOs1qbMtjC47mi5dUi1IkferjAR8eGbZErxI8WVNMUR8oLvAW7fZYANXGcnjunl2rxr85bTCe1uRutaTYGkZ2tBPQxVE8HJtWL9ZVOfl5b6Sd2XiqEh95BkdkdAyThwMi7YcrfAgMBAAECggEBAKQhOAEeym5xloLsKDeFqF+wVMo4brlAgJ37q8eR6bCHh1fm5hPpOO2NPG+SLjyuQSnNo0BH9Nj2xtooWe/RxyQrIa6hUZ/vdDOkp2iYTKSbozqzDv/QEYEXTpxgOyjMFbVhQqWqhoGruhQPH+tgD0jsreX4ys+7686DRLpcJR52GuWRZq0uTSZHCpU5VcTd4UJMZeDrxQxd/JWGMQtzEmyRcKwDjHBDI1zGxd1X4DpcJizkQlfTFxrlX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IY7RuTXL/wPRvL6Ms5vj4pTOdxYDTXaJJJGbzCG4EIu6xxsXaKsyiLR6BOuggWCGjo4EYvYpXNzXk1JlQzbG/CpK2ddjllVmpEvL1iqJkTnZY8LHMbB71VglxxUB7aFIr8/ljojw87jppWRyKlYjk57+7+e64IPLv1SOYkOO20SKek0W4kmLxxFiUjig226krKuxH3Ix78BjAUEWqyjg0jYupb6uhikInO8sfJC7bUBZIUwC50J8b4ql/vOfL0zQSZe7SOJ034ZFWpGpDedqDyYzYtEhGH/lLZq2A4N5UsxsPUx2BG4MWAdD9wIDAQAB\",\n" +
                "}";*/
        String con = "{\n" +
                "    \"baseUrl\":\"https://pay.dongfugui.xyz\",\n" +
                "    \"withdrawUrl\":\"/api/transfer/submit\",\n" +
                "    \"withdrawQueryUrl\":\"/api/transfer/query\",\n" +
                "    \"pid\":\"1000\",\n" +
                "    \"privateKey\":\"MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDCCS5bPrDo35remNAVMh0GfKGQ0v0bkyLZZTcBX+37m/5MR7wl07CtODf92dPF+4UW2BGmPfpaFcJFj5mOc+yFc08o2tq/jppA4HIkiSiRcqdFwoiq0owO5FiucR5tfz635mX1iCyvH10m7O/ivZs5AO/Gi/uIQqAf102gNaO6KVtGbhylZQMWDkBD7wOlF+3v428oo32Adxxu4vXOs1qbMtjC47mi5dUi1IkferjAR8eGbZErxI8WVNMUR8oLvAW7fZYANXGcnjunl2rxr85bTCe1uRutaTYGkZ2tBPQxVE8HJtWL9ZVOfl5b6Sd2XiqEh95BkdkdAyThwMi7YcrfAgMBAAECggEBAKQhOAEeym5xloLsKDeFqF+wVMo4brlAgJ37q8eR6bCHh1fm5hPpOO2NPG+SLjyuQSnNo0BH9Nj2xtooWe/RxyQrIa6hUZ/vdDOkp2iYTKSbozqzDv/QEYEXTpxgOyjMFbVhQqWqhoGruhQPH+tgD0jsreX4ys+7686DRLpcJR52GuWRZq0uTSZHCpU5VcTd4UJMZeD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FAAOCAQ8AMIIBCgKCAQEA7bpcyOYNAoVi8euI6/9DnQF4EkP8IY7RuTXL/wPRvL6Ms5vj4pTOdxYDTXaJJJGbzCG4EIu6xxsXaKsyiLR6BOuggWCGjo4EYvYpXNzXk1JlQzbG/CpK2ddjllVmpEvL1iqJkTnZY8LHMbB71VglxxUB7aFIr8/ljojw87jppWRyKlYjk57+7+e64IPLv1SOYkOO20SKek0W4kmLxxFiUjig226krKuxH3Ix78BjAUEWqyjg0jYupb6uhikInO8sfJC7bUBZIUwC50J8b4ql/vOfL0zQSZe7SOJ034ZFWpGpDedqDyYzYtEhGH/lLZq2A4N5UsxsPUx2BG4MWAdD9wIDAQAB\",\n" +
                "}";
        System.out.println(AESUtil.encrypt(con, "bfa5559109f94c78af615bcf00d52060"));

        Map<String, String> map = new LinkedHashMap<>();
        map.put("pid", "1000");
        map.put("method", "web");
        map.put("device", "jump");
        map.put("type", "alipay");
        map.put("out_trade_no", "202656814263");
        map.put("notify_url", "https://pay.44a5c8109e4.com/Xfgpay/callback");
        map.put("return_url", "https://pay.44a5c8109e4.com/kubp/pickup");    //https://pay.44a5c8109e4.com/kubp/pickup
        map.put("name", "cwg deposit");
        map.put("money", "100.00");
        map.put("clientip", "103.158.191.66");
        map.put("timestamp", DateUtil.getTimestamp());

        /*String sign = getSign("MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDE9gwmvvWD1qg0XQ9YlT+Z+Umb2jFHvc9z8OBzFFmO0pLI/cKbkiiB2/qyhnm3+axRcM1urFFmUpzOYz10qvfrZmeK0/TzhqL6sitab+uOwwc9NZTngWfLSmuGD7x81C8AxPgs01W8h+LTX6addR7RIzErj7EzMR4FZCMhbYLBNgBo4FQtQcLrtc+5B6KwZjfIY8nkrsnpDQHspRrm5Ue6H1NU9ph0RdA5IZHNpi1h1RHDEzJVEH8gdYu1GOxQX1LianHQpzxxq0lUr3SNKcfGJP/Kew8qcyGz0iUjyxClj16/1h1Otvu4oAKm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MIEs3cqQuaaRLLPfnQKBgFP6yNpY358J/Nk1T08I6ht9LTTH1NLQmGWi1q/uGyxUtNJtOBoqM26aZCvA3y7aDVXEGGEVUhTdBTMAGI1yrXwmf92YPER+SJqlsj19RtbNze4LcYzhQ4BRPsDFY2Uz0vT3BLxGpum20oJ8Ak9RSVmeLwH/fq1oJwbfEUf2gEtF", map);
        map.put("sign", sign);
        map.put("sign_type", "RS2");

        Map<String, String> headers = new HashMap<>(1);
        headers.put("Content-Type", "application/x-www-form-urlencoded");

        System.out.println("request: "+JSON.toJSONString(map));
        Connection.Response response = HttpUtil.post(headers,"https://pay.dongfugui.xyz/api/pay/create", map);
        System.out.println(response.body());*/

        /*map.put("pid", 1001);
        map.put("type", "alipay");
        map.put("account", "18326559131");
        map.put("name", "zhangsan");
        map.put("money", "100.00");
        map.put("remark", null);
        map.put("out_biz_no", "202648486244");
        map.put("timestamp", String.valueOf(System.currentTimeMillis()));

        String sign = getSign("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDhqS/PRNq7H0uL2yZmSxyT2aaf+6z1EC2EIB0skW82elfg2scgTdZdetoWQ8WT7uFOgN+hv+8clrgKrW3/MbHGoqYAbwWht/u+fJRsyzi3v5sbhow+Zj4pSeHXNZLxJ/iNiap3XM/Ilo6EDNe3T0t1Dhlyl6CZOJI2cJlPvXTmx9BO+orhO0MQlrm8mxob99wMaJoGVmW80KLtiJLhsf7WichGhDShU1VBj0IRlymunhqOei1tzOFInkaykpBEiYwFQvLO1StoOWNGGC0q8JKkT+hDfg7oc9waLdYn6Nt6yRFAmOqEHrI++WCNCZ4q1OgQk9xicfn/3zUxTQjE8gUJAgMBAAECggEAKYr9CzpQzjwPq1qX8iMHysw52Z/6kk79IiLLXCYWBEB3pyR/nhnWSfVQ6uJlIDvM7KfbA6sS+P9iOEz/QAjFAp101AWcUs5NIR9ML88lzOYQRvv5G4+1B+LbGcR6Hb1PC7d5U2oZsoLND9BRciS97nm/A5KYd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put("sign", sign);
        map.put("sign_type", "RSA");

        Map<String, String> headers = new HashMap<>(1);
        headers.put("Content-Type", "application/x-www-form-urlencoded");

        System.out.println("request: "+JSON.toJSONString(map));
        Connection.Response response = HttpUtil.post("https://pay.xiaofugui.xyz/api/transfer/submit", headers, JSON.toJSONString(map) );
        System.out.println(response.body());*/

    }

}



