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.FinanceWithdrawMtpayDto;
import com.crm.pay.entity.callback.MtPayCallbackEntity;
import com.crm.pay.entity.property.MtPayMerchantPropertyEntity;
import com.crm.pay.entity.property.MtWithdrawPropertyEntity;
import com.crm.pay.service.FinanceDepositService;
import com.crm.pay.service.MtPayService;
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.FinanceDepositCallbackUpdateEntity;
import com.crm.pay.entity.finance.withdraw.FinanceWithdrawApproveChannelEntity;
import com.crm.pay.entity.finance.withdraw.FinanceWithdrawApproveChannelSubmitEntity;
import com.crm.pay.entity.finance.withdraw.automatic.FinanceWithdrawInfoEntity;
import com.crm.pay.entity.finance.withdraw.automatic.FinanceWithdrawMtpayEntity;
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.util.AESUtil;
import com.crm.rely.backend.util.HAMCSHA256Util;
import com.crm.rely.backend.util.HttpUtil;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.Map;

@Slf4j
@Service
public class MtPayServiceImpl extends BasePayServiceImpl implements MtPayService {

    @Autowired
    private FinanceDepositService financeDepositService;

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

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

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

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


    /**
     * 回调处理数据
     *
     * @param callbackEntity
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String callback(MtPayCallbackEntity callbackEntity) throws Exception {
        log.info(String.format("callback data:%s", JSON.toJSONString(callbackEntity)));
        if(Strings.isNullOrEmpty(callbackEntity.getSignature())){
            return Constants.FAIL;
        }
        //获取配置
        MtPayMerchantPropertyEntity payProperty = getPayProperty(PayConstants.MT_PAY_KEY, false,MtPayMerchantPropertyEntity.class);

        String signHMACSHA256 = HAMCSHA256Util.sha256_HMAC(payProperty.getAccessKey()+"_"+callbackEntity.getTimestamp(), payProperty.getSecretKey()).toUpperCase();
        if (!callbackEntity.getSignature().equals(signHMACSHA256)) {
            return Constants.FAIL;
        }

        //验证传输数据
        MtPayCallbackEntity callDataEntity = JSON.parseObject(callbackEntity.getData(),MtPayCallbackEntity.class);
        int status = PayConstants.CALLBACE_PROCESSING_STATUS;
        if("Finished".equals(callDataEntity.getRequestStatus())) {
            status = PayConstants.CALLBACE_SUCCESS_STATUS;
        }else if("Failed".equals(callDataEntity.getRequestStatus()) || "Cancelled".equals(callDataEntity.getRequestStatus())) {
            status = PayConstants.CALLBACE_FAIL_STATUS;
        }

        String timestamp = String.valueOf(System.currentTimeMillis());
        //对生成的字符串使用HMAC-SHA256进行加密
        String signHMACSHA256query = HAMCSHA256Util.sha256_HMAC(payProperty.getAccessKey()+"_"+timestamp, payProperty.getSecretKey()).toUpperCase();

        Map<String, String> heardMap = new LinkedHashMap<>();
        heardMap.put("Content-Type", "application/json;charset=UTF-8");
        heardMap.put("access_key", payProperty.getAccessKey());
        heardMap.put("signature", signHMACSHA256query);
        heardMap.put("timestamp", timestamp);
        Connection.Response response = HttpUtil.get(payProperty.getBaseUrl()+payProperty.getQueryUrl()+callDataEntity.getMerchantOrderNo(), heardMap);
        log.info(String.format("url:%s,body:%s", payProperty.getQueryUrl()+callDataEntity.getMerchantOrderNo() , response.body()));

        JSONObject requestEntity = JSON.parseObject(response.body());
        if (requestEntity == null || (requestEntity.get("isSuccess") != null && !(Boolean) requestEntity.get("isSuccess"))) {
            log.error("Payment platform is abnormal, please try again later or contact customer service.");
            return Constants.FAIL;
        }
        JSONObject jsonData = JSONObject.parseObject(requestEntity.get("data").toString());

        if (!callDataEntity.getRequestStatus().equals(jsonData.get("status").toString()) || !callDataEntity.getMerchantOrderNo().equals(jsonData.get("merchantOrderNo").toString())
                || !callDataEntity.getRequestCode().equals(jsonData.get("requestCode").toString()) || callDataEntity.getPaymentAmount().compareTo(new BigDecimal(jsonData.get("paymentAmount").toString()) )!=0 )  {
            return Constants.FAIL;
        }

        FinanceDepositCallbackUpdateEntity balanceCallbackUpdateEntity =
                getFinanceDepositCallbackUpdateEntity(callDataEntity.getMerchantOrderNo(), callDataEntity.getRequestCode(),
                        status,callbackEntity);
        balanceCallbackUpdateEntity.setTransformAmount(callDataEntity.getPaymentAmount());

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

    /**
     * 获取支付url
     *
     * @param balanceTable
     * @return
     * @throws ServiceException
     */
    private String getUrl(MtPayMerchantPropertyEntity propertyEntity, FinanceDepositTable balanceTable, FinanceDepositAddEntity balanceSaveEntity) throws ServiceException, IOException, PayValidatedException {
        String orderNo = balanceTable.getSerial() + "_" + balanceTable.getLogin();
        String timestamp = String.valueOf(System.currentTimeMillis());

        //对生成的字符串使用HMAC-SHA256进行加密
        String signHMACSHA256 = HAMCSHA256Util.sha256_HMAC(propertyEntity.getAccessKey()+"_"+timestamp, propertyEntity.getSecretKey()).toUpperCase();

        JSONObject clientJson = new JSONObject();
        clientJson.put("realName",  balanceTable.getName());        //真实姓名
        clientJson.put("registeredAt", timestamp);                  //注册时间的毫秒时间戳（可选）

        JSONObject codeJson = new JSONObject();
        //codeJson.put("method", balanceSaveEntity.getBankCode());   //银行卡 → 1  微信支付 → 2 支付宝 → 4 区块链 → 8（即将推出） 账户 → 16（即将推出）
        switch (balanceSaveEntity.getBankCode()){
            case PayConstants.MT_BANK:
                codeJson.put("method", 1);
                break;
            case PayConstants.MT_WECHAT:
                codeJson.put("method", 2);
                break;
            case PayConstants.MT_ALIPAY:
                codeJson.put("method", 4);
                break;
            case PayConstants.MT_BLOCKCHIN:
                codeJson.put("method", 8);
                break;
            case PayConstants.MT_ACCOUNT:
                codeJson.put("method", 16);
                break;
            default:
                break;
        }

        Map<String, Object> map = new LinkedHashMap<>();
        map.put("client", clientJson);
        map.put("depositCurrency",balanceTable.getTransformCurrency());                     //存款的货币类型（例如 MTC/CNY/HKD）
        map.put("fiatCurrency",balanceTable.getTransformCurrency());                        //法定货币代码（例如 CNY/HKD
        map.put("depositAmount", String.format("%.2f", balanceTable.getTransformAmount().doubleValue()));                  //存款金额
        map.put("merchantOrderNo", orderNo);                                                //商户订单号
        map.put("webhookUrl", propertyEntity.getCallbackUrl());                               //异步通知URL
        map.put("language", "zh_CN");                                                       //首选语言（默认为 en）
        map.put("paymentMethod", codeJson);

        Map<String, String> heardMap = new LinkedHashMap<>();
        heardMap.put("Content-Type", "application/json;charset=UTF-8");
        heardMap.put("access_key", propertyEntity.getAccessKey());
        heardMap.put("signature", signHMACSHA256);
        heardMap.put("timestamp", timestamp);

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

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

        JSONObject jsonData = JSONObject.parseObject(requestEntity.get("data").toString());
        String url = String.valueOf(jsonData.get("checkoutUrl"));
        log.info(String.format("支付请求,请求orderNo:%s,请求url:%s", map.get("merchantOrderNo"), url));

        return url;
    }

    @Override
    public FinanceWithdrawMtpayDto 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.MT_PAY_TYPE_REMIT);

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

        FinanceWithdrawMtpayDto dto = new FinanceWithdrawMtpayDto();
        dto.setWithdrawAmount(withdrawDto.getTransformAmount() == null ? null :
                withdrawDto.getTransformAmount().setScale(2, BigDecimal.ROUND_DOWN));
        dto.setRealName(withdrawDto.getName());
        dto.setBankName(withdrawDto.getBankName());
        dto.setCardNumber(withdrawDto.getBankCardNum());
        dto.setBankBranchName(withdrawDto.getBankBranchName());
        dto.setWithdrawCurrency(withdrawDto.getWithdrawCurrency());
        dto.setFiatCurrency(withdrawDto.getTransformCurrency());

        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(FinanceWithdrawMtpayEntity 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());

        MtWithdrawPropertyEntity proxpayWithdrawProperty = getWithdrawProperty(PayConstants.MT_PAY_TYPE_REMIT, MtWithdrawPropertyEntity.class);

        payout(entity, proxpayWithdrawProperty);

        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);
        }

        return null;
    }

    private void payout(FinanceWithdrawMtpayEntity entity, MtWithdrawPropertyEntity propertyEntity) throws ServiceException, IOException, PayValidatedException {
        String timestamp = String.valueOf(System.currentTimeMillis());

        //对生成的字符串使用HMAC-SHA256进行加密
        String signHMACSHA256 = HAMCSHA256Util.sha256_HMAC(propertyEntity.getAccessKey()+"_"+timestamp, propertyEntity.getSecretKey()).toUpperCase();

        JSONObject clientJson = new JSONObject();
        clientJson.put("realName",  entity.getRealName());              //真实姓名
        clientJson.put("registeredAt", timestamp);                  //注册时间的毫秒时间戳（可选）

        JSONObject bankJson = new JSONObject();
        bankJson.put("cardNumber",  entity.getCardNumber());
        bankJson.put("bankName", entity.getBankName());
        bankJson.put("bankBranchName", entity.getBankBranchName());

        Map<String, Object> map = new LinkedHashMap<>();
        map.put("client", clientJson);
        map.put("withdrawCurrency",entity.getWithdrawCurrency());                       //存款的货币类型（例如 MTC/CNY/HKD）
        map.put("fiatCurrency",entity.getFiatCurrency());                               //法定货币代码（例如 CNY/HKD
        map.put("withdrawAmount", String.format("%.2f", entity.getWithdrawAmount().doubleValue()));                  //提现金额
        map.put("bankCard", bankJson);
        map.put("requiresReview", true);
        map.put("merchantOrderNo", entity.getSerial());                                                    //异步通知URL
        if (entity.getWithdrawInfoType() == null || entity.getWithdrawInfoType().equals(1)) {
            map.put("webhookUrl", propertyEntity.getCallbackUrl());
        } else {
            map.put("webhookUrl", propertyEntity.getAgentCallbackUrl());
        }

        Map<String, String> heardMap = new LinkedHashMap<>();
        heardMap.put("Content-Type", "application/json;charset=UTF-8");
        heardMap.put("access_key", propertyEntity.getAccessKey());
        heardMap.put("signature", signHMACSHA256);
        heardMap.put("timestamp", timestamp);

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

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

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String withdrawCallback(Integer withdrawType, MtPayCallbackEntity callbackEntity) throws Exception {
        log.info(String.format("callback data:%s", JSON.toJSONString(callbackEntity)));
        if(Strings.isNullOrEmpty(callbackEntity.getSignature())){
            return Constants.FAIL;
        }
        //获取配置
        MtWithdrawPropertyEntity payProperty = getWithdrawProperty(PayConstants.MT_PAY_TYPE_REMIT, MtWithdrawPropertyEntity.class);

        String signHMACSHA256 = HAMCSHA256Util.sha256_HMAC(payProperty.getAccessKey()+"_"+callbackEntity.getTimestamp(), payProperty.getSecretKey()).toUpperCase();
        if (!callbackEntity.getSignature().equals(signHMACSHA256)) {
            return Constants.FAIL;
        }

        //验证传输数据
        MtPayCallbackEntity callDataEntity = JSON.parseObject(callbackEntity.getData(),MtPayCallbackEntity.class);

        String timestamp = String.valueOf(System.currentTimeMillis());
        //对生成的字符串使用HMAC-SHA256进行加密
        String signHMACSHA256query = HAMCSHA256Util.sha256_HMAC(payProperty.getAccessKey()+"_"+timestamp, payProperty.getSecretKey()).toUpperCase();

        Map<String, String> heardMap = new LinkedHashMap<>();
        heardMap.put("Content-Type", "application/json;charset=UTF-8");
        heardMap.put("access_key", payProperty.getAccessKey());
        heardMap.put("signature", signHMACSHA256query);
        heardMap.put("timestamp", timestamp);
        Connection.Response response = HttpUtil.get(payProperty.getBaseUrl()+payProperty.getQueryUrl()+callDataEntity.getMerchantOrderNo(),heardMap);//查询订单是否和回调数据一致
        log.info(String.format("url:%s,body:%s", payProperty.getBaseUrl()+payProperty.getQueryUrl()+callDataEntity.getMerchantOrderNo() , response.body()));

        JSONObject requestEntity = JSON.parseObject(response.body());
        if (requestEntity == null || (requestEntity.get("isSuccess") != null && !(Boolean) requestEntity.get("isSuccess"))) {
            log.error("Payment platform is abnormal, please try again later or contact customer service.");
            return Constants.FAIL;
        }
        JSONObject jsonData = JSONObject.parseObject(requestEntity.get("data").toString());
        if (!callDataEntity.getRequestStatus().equals(jsonData.get("status").toString()) || !callDataEntity.getMerchantOrderNo().equals(jsonData.get("merchantOrderNo").toString()) || !callDataEntity.getRequestCode().equals(jsonData.get("requestCode").toString()))  {
            return Constants.FAIL;
        }

        FinanceWithdrawApproveChannelEntity financeWithdrawApproveChannelEntity =
                new FinanceWithdrawApproveChannelEntity();
        financeWithdrawApproveChannelEntity.setChannelSerial(callbackEntity.getRequestCode());

        if("Finished".equals(callDataEntity.getRequestStatus())) {
            financeWithdrawApproveChannelEntity.setCallbackStatus(PayConstants.CALLBACE_SUCCESS_STATUS);
        }else {
            financeWithdrawApproveChannelEntity.setCallbackStatus(PayConstants.CALLBACE_FAIL_STATUS);
        }
        financeWithdrawApproveChannelEntity.setSerial(callbackEntity.getMerchantOrderNo());

        /**
         * 更新数据
         */

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

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

        return Constants.SUCCESS;
    }


    public static void main(String[] args) throws IOException {
        String con = "{\n" +
                "   \"accessKey\":\"TzSdXguHuM8xcSrPzcz4yomXWuXuq2QS\",\n" +
                "   \"secretKey\":\"2r7VY5QmwxGEwfqFKvEyaakeyBjDJsLFr2vluUqhWomZ76ArlrAIna40zT2g5GOG\",\n" +
                "   \"baseUrl\":\"https://core-api.mtpay.biz\",\n" +
                "   \"withdrawUrl\":\"/api/v2/merchant/withdraw/bank-card\",\n" +
                "   \"queryUrl\":\"/api/v2/merchant/transaction-request?merchantOrderNo=\",\n" +
                "   \"callbackUrl\":\"https://testpay.cwgvu.com/mtpay/withdraw/callback\",\n" +
                "   \"agentCallbackUrl\":\"https://testpay.cwgvu.com//agent/mtpay/withdraw/callback\"\n" +
                "}";
        System.out.println(AESUtil.encrypt(con,"bfa5559109f94c78af615bcf00d52060"));

        //String orderNo = balanceTable.getSerial() + "_" + balanceTable.getLogin();
        /*String orderNo = "20250324234323424";
        Long times = System.currentTimeMillis();
        String timestamp = String.valueOf(times);
        System.out.println(timestamp);
        *//*Map<String, String> params = new LinkedHashMap<>();
        params.put("access_key", "TzSdXguHuM8xcSrPzcz4yomXWuXuq2QS");
        params.put("timestamp", timestamp);
        String signString = MapUtil.getStringSortByKey(params);*//*

        //对生成的字符串使用HMAC-SHA256进行加密
        String signHMACSHA256 = HAMCSHA256Util.sha256_HMAC("TzSdXguHuM8xcSrPzcz4yomXWuXuq2QS_" + timestamp,
                "2r7VY5QmwxGEwfqFKvEyaakeyBjDJsLFr2vluUqhWomZ76ArlrAIna40zT2g5GOG").toUpperCase();
        System.out.println(signHMACSHA256);

        *//*System.out.println(HAMCSHA256Util.sha256_HMAC("B6QKwx0NnKaQ14zf24Ux5Oc9Gy1xlf2R_1625546438154",
                "WUYx7DTQZakugtP9gOAimYUphcnc3jWuPRi1UVnWmwXSnMnsCVBzz1ILdaxisvz9").toUpperCase());*//*

        Map<String, String> heardMap = new LinkedHashMap<>();
        heardMap.put("Content-Type", "application/json;charset=UTF-8");
        heardMap.put("access_key", "TzSdXguHuM8xcSrPzcz4yomXWuXuq2QS");
        heardMap.put("signature", signHMACSHA256);
        heardMap.put("timestamp", timestamp);

        JSONObject clientJson = new JSONObject();
        clientJson.put("realName", "张三");       //真实姓名
        clientJson.put("registeredAt", times); //注册时间的毫秒时间戳（可选）

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("method", 8);

        Map<String, Object> map = new LinkedHashMap<>();
        map.put("client", clientJson);
        map.put("depositCurrency", "CNY");               //存款的货币类型（例如 MTC/CNY/HKD）
        map.put("fiatCurrency", "CNY");                  //法定货币代码（例如 CNY/HKD
        map.put("depositAmount", 2001.00);                  //存款金额
        map.put("merchantOrderNo", orderNo);                               //商户订单号
        map.put("webhookUrl", "/mtpay/callback");       //异步通知URL
        map.put("language", "zh_CN");                 //首选语言（默认为 en）
        map.put("paymentMethod", jsonObject1);

        JSONObject bankJson = new JSONObject();
        bankJson.put("cardNumber", "6217000160009490222");
        bankJson.put("bankName", "中国建设银行");
        bankJson.put("bankBranchName", "中国建设银行股份有限公司枣强支行");

        *//*map.put("client", clientJson);
        map.put("withdrawCurrency","CNY");                     //存款的货币类型（例如 MTC/CNY/HKD）
        map.put("fiatCurrency","CNY");                           //法定货币代码（例如 CNY/HKD
        map.put("withdrawAmount", 5000.00);                       //提现金额
        map.put("bankCard", bankJson);                                                       //异步通知URL
        map.put("requiresReview", true);
        map.put("merchantOrderNo", "2345436345345345");
        map.put("webhookUrl", "/callback");*//*

        String heard = JSON.toJSONString(heardMap);
        System.out.println("heard:" + heard);

        String data = JSON.toJSONString(map);
        System.out.println("request:" + data);

        Connection.Response response = HttpUtil.post("https://core-api.mtpay.biz/api/v2/merchant/deposit", heardMap, data);
        //Connection.Response response = HttpUtil.post("https://core-api.mtpay.biz/api/v2/merchant/withdraw/bank-card", heardMap, map);

        System.out.println("result:" + JSON.parseObject(response.body()).toJSONString());


        //{"data":{"checkoutUrl":"https://checkout.mtpay.biz/api/buy-coin/7c25a438339e41cbbc79e827406d2f66?lang=zh-CN","requestCode":"7c25a438339e41cbbc79e827406d2f66",
        //        "isAvailable":false,"expiresAt":0,"createdAt":1743152712189},"isSuccess":true,"statusCode":"SUCCESS","message":"","version":"2.0"}%

        //{"data":{"checkoutUrl":"https://checkout.mtpay.biz/api/buy-coin/a199695bb73b4e41be3898d4b63c27d7?lang=zh-CN","requestCode":"a199695bb73b4e41be3898d4b63c27d7",
        //        "isAvailable":false,"expiresAt":0,"createdAt":1743153163787},"isSuccess":true,"statusCode":"SUCCESS","message":"","version":"2.0"}%

        *//*Connection.Response response = HttpUtil.get("https://core-api.mtpay.biz/api/v2/merchant/transaction-request?merchantOrderNo=20250101215411411123", heardMap);*//*


        // result:{"data":{"unitPrice":0,"clientName":"张三","modifiedAt":0,"endedReason":"","source":"API_V2","internalOrderNo":"","receivedAmount":0,"requestAmount":5500.2000,
        //"merchantOrderNo":"20250101215411411123","paymentAmount":0,"expiredAt":0,"createdAt":1743153163787,"transactionFee":0,"fiatCurrency":"CNY","endedAt":0,"transactionAmount":0,"requestCode":"a199695bb73b4e41be3898d4b63c27d7","requestCurrency":"CNY","tradeType":"Deposit","status":"Cancelled"},"message":"","version":"2.0","isSuccess":true,"statusCode":"SUCCESS"}
*/
    }

}



