package com.jeesharp.business.modules.pay.util;

import api.ApiResponse;
import api.SPDBSMEncryptor;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.jeesharp.business.modules.pay.enums.pufapay.TranTypeEnum;
import com.jeesharp.business.modules.pay.paymerchant.entity.PayMerchant;
import com.jeesharp.business.modules.pay.paytype.pufapay.PfPayUtils;
import com.jeesharp.business.modules.pay.paytype.pufapay.baseutil.DigestUtils;
import com.jeesharp.business.modules.pay.paytype.pufapay.order.dto.AppPayCancel;
import com.jeesharp.business.modules.pay.paytype.pufapay.order.dto.AppPayReturn;
import com.jeesharp.business.modules.pay.paytype.pufapay.order.dto.AppPayStatus;
import com.jeesharp.business.modules.pay.paytype.pufapay.order.dto.AppPayTrade;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @Author: wangmeng
 * @CreateTime: 2023-05-17  17:13
 * @Description: 浦发银行操作工具类
 */
@Component
public class SPDBSUtil {

    private static Logger logger = LoggerFactory.getLogger(SPDBSUtil.class);

    /*
     *请求头ContentType,一般为application/json,API对外接口文档中有报文体格式
     *图文上传接口为form-data,如果是图文信息上传,请参考国密普通验签图片上传接口测试工程.zip
     */
    private static final String contentType = "application/json;charset=utf-8";
    /**
     * 请求编码格式
     */
    private static final String charset = "UTF-8";

    private static final OkHttpClient client = new OkHttpClient.Builder()
            .connectionPool(new ConnectionPool(500, 5, TimeUnit.MINUTES)).connectTimeout(10000, TimeUnit.MILLISECONDS)
            .readTimeout(60000, TimeUnit.MILLISECONDS).build();

//    public static AppBaseResp getPayResponseData(Class<? extends AppBaseReq> cls, AppBaseReq requestData, PayMerchant payMerchant) throws IllegalAccessException, IOException {
//        if (StrUtil.isBlank(payMerchant.getId())) {
//            PayCommonUtil.wrapPayExceptionAndThrow(PayMessageConstants.PAY_APP_ERROR.getCode(), "浦发商户配置为空");
//        }
//
//        if (payMerchant.getStatus() != 0) {
//            PayCommonUtil.wrapPayExceptionAndThrow(PayMessageConstants.PAY_APP_ERROR.getCode(), "当前浦发商户状态未开启,请开启");
//        }
//
//        if (StrUtil.isBlank(payMerchant.getClientId()) || StrUtil.isBlank(payMerchant.getSecret()) || StrUtil.isBlank(payMerchant.getPrivateKey()) || StrUtil.isBlank(payMerchant.getSpdbPublicKey())) {
//            PayCommonUtil.wrapPayExceptionAndThrow(PayMessageConstants.PAY_APP_ERROR.getCode(), "当前浦发商户必填项目不正确");
//        }
//
//        PfPayUtils.validRequestMessage(cls, requestData);//验证参数
//        String httpUrl = null;
//        String requestMethod = null;
//        requestMethod = requestData.getRequestMethod();
//        if (cls == AppPayTrade.class) {
//            if (StrUtil.isBlank(payMerchant.getPayNotifyUrl())) {
//                PayCommonUtil.wrapPayExceptionAndThrow(PayMessageConstants.PAY_APP_ERROR.getCode(), "支付回调地址为空");
//            }
//            httpUrl = PuFaPayConfig.APP_PAY_TRADE;
//            AppPayTradeResp appPayTradeResp = JSONUtil.toBean(getSignAndSendData(payMerchant, requestMethod, httpUrl, requestData), AppPayTradeResp.class);
//            return appPayTradeResp;
//        }
//        if (cls == AppPayStatus.class) {
//            httpUrl = PuFaPayConfig.APP_PAY_STATUS;
//            AppPayStatusResp appPayStatusResp = JSONUtil.toBean(getSignAndSendData(payMerchant, requestMethod, httpUrl, requestData), AppPayStatusResp.class);
//            return appPayStatusResp;
//        }
//        if (cls == AppPayReturn.class) {
//            if (StrUtil.isBlank(payMerchant.getRefundNotifyUrl())) {
//                PayCommonUtil.wrapPayExceptionAndThrow(PayMessageConstants.PAY_APP_ERROR.getCode(), "退款回调地址为空");
//            }
//            httpUrl = PuFaPayConfig.APP_PAY_RETURN;
//            AppPayReturnResp appPayReturnResp = JSONUtil.toBean(getSignAndSendData(payMerchant, requestMethod, httpUrl, requestData), AppPayReturnResp.class);
//            return appPayReturnResp;
//        }
//        if (cls == AppPayCancel.class) {
//            httpUrl = PuFaPayConfig.APP_PAY_CANCEL;
//            AppPayCancelResp appPayCancelResp = JSONUtil.toBean(getSignAndSendData(payMerchant, requestMethod, httpUrl, requestData), AppPayCancelResp.class);
//            return appPayCancelResp;
//        }
//        return null;
//    }

//    public static Request createRequest(PayMerchant payMerchant, String requestMethod, String httpUrl, String data, String signature) {
//        Request request = null;
//        if ("GET".equals(requestMethod) || "get".equals(requestMethod)) {
//            httpUrl = httpUrl + "?" + data;
//            request = new Request.Builder().url(httpUrl).get()
//                    .addHeader("Content-Type", contentType)
//                    .addHeader("X-SPDB-Client-ID", payMerchant.getClientId())
//                    .addHeader("X-SPDB-SIGNATURE", signature)
//                    .addHeader("X-SPDB-SM", "true")
//                    .addHeader("X-SPDB-SINGLE-ENCRY", "true")
//                    .build();
//
//        } else if ("POST".equals(requestMethod) || "post".equals(requestMethod)) {
//            MediaType mediaType = MediaType.parse(contentType);
//            RequestBody body = RequestBody.create(mediaType, data);
//            request = new Request.Builder().url(httpUrl).post(body)
//                    .addHeader("Content-Type", contentType)
//                    .addHeader("X-SPDB-Client-ID", payMerchant.getClientId())
//                    .addHeader("X-SPDB-SIGNATURE", signature)
//                    .addHeader("X-SPDB-SM", "true")
//                    .addHeader("X-SPDB-SINGLE-ENCRY", "true")
//                    .build();
//        } else {
//            throw new NullPointerException("request is null");
//        }
//        return request;
//    }

//    private static String getSignAndSendData(PayMerchant payMerchant, String requestMethod, String httpUrl, AppBaseReq requestData) throws IOException {
//        String data = SM2Cryptor.encrypt(payMerchant.getSecret(), JSONUtil.toJsonStr(requestData));
//        //获取防重放参数
//        //String newBodyData = getNonceParam(false, data+data1);
//        long t1 = System.currentTimeMillis();
//        //获取签名
//        String signature = getSign(payMerchant, data, false, false);
//        long t2 = System.currentTimeMillis();
//        logger.info("时间：{}", (t2 - t1));
//        //发送HTTP请求
//        Request request = createRequest(payMerchant, requestMethod, httpUrl, data, signature);
//        Response response = client.newCall(request).execute();
//        PuFaHttpStatusEnum httpEnum = PuFaHttpStatusEnum.getHttpEnum(response.code());
//        String resBody = null;
//        switch (httpEnum) {
//            case SUCCESS:
//                resBody = new String(response.body().bytes(), "UTF-8");
//                break;
//            default:
//                PayCommonUtil.wrapPayExceptionAndThrow(PayMessageConstants.PAY_HTTP_ERROR.getCode(), httpEnum.getDetailMessage());
//                break;
//        }
//        logger.info("响应报文:{}", resBody);
//        return resBody;
//    }

    /**
     * 获取签名
     *
     * @param newBodyData 报文参数
     * @param isUpFile    是否是文件上传
     * @param isBody      是否是文件上传
     * @return
     */
    public static String getSign(PayMerchant payMerchant, String newBodyData, boolean isUpFile, boolean isBody) {
        String bodyMD5 = "";
        String fileDate = "";
        String sign = "";
        if (isUpFile) {
            String[] filePath = {"D:/content.jpg"};
            fileDate = DigestUtils.fileMD5(filePath);
            sign = DigestUtils.sign(payMerchant.getSecret(), fileDate);
            logger.info("X-SPDB-FilesMD5:{} ", fileDate);
            logger.info("X-SPDB-ClientID-Secret：{}", payMerchant.getSecret());
            logger.info("X-SPDB-SIGNATURE:{}", sign);//签名结果
            logger.info("————————文件上传签名结束————————");
        } else if (isBody) {//是否为大报文
            bodyMD5 = DigestUtils.bodyMD5(newBodyData);
            sign = DigestUtils.sign(payMerchant.getSecret(), bodyMD5);
            logger.info("X-SPDB-BodyMD5: {}", bodyMD5);
            logger.info("原报文体：{}", newBodyData);
            logger.info("X-SPDB-ClientID-Secret：{}", payMerchant.getSecret());
            logger.info("X-SPDB-SIGNATURE:{}", sign);//签名结果
            logger.info("————————大报文签名结束————————");
        } else {
            logger.info("原报文体:{}", newBodyData);
            sign = DigestUtils.sign(payMerchant.getSecret(), newBodyData);//签名
            logger.info("X-SPDB-SIGNATURE:{}", sign);//签名结果
        }
        return sign;
    }

    public static void main(String[] args) throws Exception {

        String en = "oV6Impr+Q9agNc9wLp5vTAjmtD5dd5WaPf3LobfKoEm3xyOecRsz4B3fkw+HrcQNvh/O+/gZx5tLL/8OEI2Dq1lGcW+9zinndg9k4N1j4TPiFhuNuri6j/ZwwRjk6wtXIVGT+pdoTeEb/fDd3M+GjiGUuVuq35UE4UqAvg7eGVeXtikILqXZMydzFBNqPVev1T7w+nMjABt0xut1YFd1mJqruf2eMp+8bvSycxU8n6f6JavC7cbk5CbqXUGhGUJLDHTzc0oY9lOHk18JGEUBfA7hkAV8akKUZj7e2SThFEmJLYoWGP4F/nhgAwnrYlEWo542mSIyQ9xNnJ3FVzum9kKSH0JVvHA+MoaUrrmgBfAC1P0p0Pp2dMqWrP/RYtUx98dhqc78ngq3fwPZ1koLmS1tqSL7Wb4RfGV89LHCpgIwyE88DS69uxeKU4KIgeKfdDXvMEhdcidBB4nw1IMDfqKhUh7JPomzy6NdksIVqXkI+V+3XB8kGbQXyIjHJxURFANc0zqecp5ZBMLoONEBUnqqgoLBwGO98u2B6rFJ9txdVn5Atm38uldpXh777qLEXPI1WxK5QZZg3IsRS191z/TCVlpJGzlp2fN6gYEfmnDuQwYJBkA/wW9oDoTI8f0b0BPeCXtI0MFun6W8wHOvJ9iEArOfwWpapvUIdcQ9Tv0=";// 加密
        //-----------------解密
        //String data = RSASign.decrypt(en);
        //System.out.println("解密结果：" + data);
        String spdbMrchNo = "31016006513G001";//商户号
        String terminalNo = "68ZY1933";//终端号
        /*ClientID和密钥：X-SPDB-ClientID、X-SPDB-ClientID-Secret
         * 浦发API开发平台上创建APP给您邮件返回的，或我们提供给您测试使用的
         * 生产请使用API开发平台上创建APP给您邮件返回的生产环境密钥
         */
        String clientId = "ae86bdf8-804e-4a91-a2da-d4a63a9a86db";

        //加解密样例仅供参考，秘钥有过期时间，建议在生产环境不要将秘钥硬编码在代码中
        String secret = "N2RwMy00NTU3LTkpOTYtM2Z2NDg4M2V5NDQxMC4wNTc5MzA3OTPwODAwNDP5MjUw";//解密后
        //解密前：RDNEMDFGMkZBQ0UyRTQ5RTFENURCOTc2OEY5ODFFQzk2RUExM0VDMzU5RTlFMTE3RTdGMEVEMzlEQUY4NzVCOTkyQTc3M0ZGMTUyNjU2ODkzODU1MTZGRTAwQTM4MUIzRTYyNjIxMjkwMzg5NTk4QUNBMzFDRTk1N0VEMzc0RUVFMEMyMEVBRjA0MjIxQkJBM0YyM0JGNEZEMzAzOEM3RQ==
        /*您的私钥，测试环境中请将您对应的公钥请提供给我们，我们需要在门户配置，否则无法通过验签
         * 公私钥生成可进入本项目下nodejs文件夹下运行 node getKeyPaireHex.js 即可生成公私密钥
         * 加解密样例仅供参考，秘钥有过期时间，建议在生产环境不要将秘钥硬编码在代码中(请替换)
         */
        String privatekey = "8f3dd651f687e29ca1bc469c36fe6f49b9142b7ecbd9af8bdfd419ade8e50b71";
        //04e35714264e50a8bb3dff350f2e08958ec75ad390afb559e55ad21af28788357f870b2448801067a3540328c3a5b162b9f507993789cda1b8bb99e11175faed3c

        //浦发公钥，在用户中心我的APP开发者公钥中查看
        //加解密样例仅供参考，秘钥有过期时间，建议在生产环境不要将秘钥硬编码在代码中
        String spdbPublicKey = "04874ee6285b82c2f1876d497cc84f954d952425d26e6be5794c2e6da19f13f8caac20fb1571804afc2b57954a670e84b6a559978ce5b2adba1386176949af38d0";
        //System.out.println("spdbMrchNo：" + spdbMrchNo);
        //System.out.println("terminalNo：" + terminalNo);
        //System.out.println("clientId：" + clientId);
        //System.out.println("secret：" + secret);
        //System.out.println("privatekey：" + privatekey);
        //System.out.println("spdbPublicKey：" + spdbPublicKey);
        //响应解密报文{"statusCode":"0000","transNo":"04972310161191727365316102","subMechNoAcctID":"","terminalNo":"","usrFlg":"","isSbscrbFlg":"","usrChildFlg":"","isFlag":"","afdsPayBank":"","ccy":"","marginTotalAmt":"","busnPckt":"","clueDtl":"","byrOfAlipayAcctNO":"","actRcvAmt":"","byrPayAmt":"","usPntsPayAmt":"","toUsEstbInvAmt":"","inrChlCnlNo":"","alPayCdBal":"","mrchStrNm":"山西建投城市运营集团有限公司","byrAlpayID":"","addItInNal":"","fldData":"","clrgDate":"","ordrSt":"09","tranType":"OK","tranAmt":"0.01","thdPtySeq":"","tranOrdrNo":"23101615200011546019","tranDate":"20231016","qrCdLink":"https://qr.95516.com/03100000/ccas/uasp/unifiedNative?token=74df221ac721c41b2b7d1cf9c398a80df","praPayCmmFlg":"","spdbMrchNo":"31016006513G001","mrchOrdrNo":"23101601000015298792","mrchTm":"","signature":"","sgnData":"","alTrnCrc":"","pymtMd":"","busInfo":"","mdsctAmnt":"","dscntAmnt":"","byUserType":"","apndPyMd":"","pblcAcctId":"","trdMerMechNo":"","weChatSubMechNo":"","bussDealRsltInfo":"SUCCESS","thdPtyErrCd":"","errInfo":"","trdChnl":"","rsrvFld1":"","rsrvFld2":"","rsrvFld3":"","rsrvFld4":"","rsrvFld5":"","rsrvFld6":"","rsrvFld7":"","rsrvFld8":""}
        //SPDBSUtil.payTest(spdbMrchNo, terminalNo, clientId, secret, privatekey, spdbPublicKey);
        //SPDBSUtil.cancelTest(spdbMrchNo, terminalNo, clientId, secret, privatekey, spdbPublicKey,"23101815200011645331","5002312023101814303761336130");
        SPDBSUtil.refundTest(spdbMrchNo, terminalNo, clientId, secret, privatekey, spdbPublicKey, "23111615200013364718", "5002312023111619562435282609");
        //SPDBSUtil.statusTest(spdbMrchNo, terminalNo, clientId, secret, privatekey, spdbPublicKey, "23101815200011647643", "23101801000015425316");
    }

    /**
     * 支付测试
     *
     * @param spdbMrchNo
     * @param terminalNo
     * @param clientId
     * @param secret
     * @param privatekey
     * @param spdbPublicKey
     * @author wangmeng
     * @date 2023/10/16 17:07
     */
    private static void payTest(String spdbMrchNo, String terminalNo, String clientId, String secret, String privatekey, String spdbPublicKey) {
        AppPayTrade appPayTrade = new AppPayTrade();
        appPayTrade.setCmdtyDsc("门店品牌名-城市分店名-实际商品名称");//商品描述
        appPayTrade.setSpdbMrchNo(spdbMrchNo);//商户号
        appPayTrade.setTranAmt("0.01");//交易金额
        appPayTrade.setTerminalNo(terminalNo);//终端号
        appPayTrade.setPrblmNo("0002");//门店编号
        appPayTrade.setTerminaIP("10.0.0.179");
        //微信子商户号：597423242
        appPayTrade.setUsrChildFlg("wxfc874904c414bf86");
        appPayTrade.setSubMechNoAcctID("597423242");//app支付
        appPayTrade.setTranType(TranTypeEnum.WX_APPLET_PAY.getType());//交易类型
        appPayTrade.setMrchlInfmAdr("http://sxtc.com:10009/apiApp/pay/payOrder/pfNotify");//异步通知地址
        try {
            PfPayUtils.validRequestMessage(AppPayTrade.class, appPayTrade);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //请求方法
        String method = "POST";
        // 请求的URL,请使用对API外接口文档中提供的URL
        String url = "https://api.spdb.com.cn/spdb/prd/api/acquiring/appPay/initiation";
        /*
         * 请求报文体 {"name":"zhangshan"} 注意换行符和空格
         * 如果是图文信息上传，请参考国密普通验签图片上传接口测试工程.zip
         */
        //String requestBody = "{\"name\":\"zhangshan\"}";
        JSONConfig jsonConfig = new JSONConfig();
        jsonConfig.setIgnoreNullValue(false);
        String requestBody = JSONUtil.toJsonStr(appPayTrade, jsonConfig);
        System.out.println("请求体：" + JSONUtil.toXmlStr(JSONUtil.parse(appPayTrade)));
        // 是否获取防重放参数
        Boolean forbidden = false;
        //是否是全报文
        Boolean encryption = true;

        try {
            ApiResponse apiResponse = SPDBSMEncryptor.requestApi(clientId, secret, privatekey, spdbPublicKey, method, url, requestBody, forbidden, encryption);
            System.out.println("响应状态码" + apiResponse.getCode());
            System.out.println("响应报文" + apiResponse.getBody());
            System.out.println("响应解密报文" + apiResponse.getDecryptBody());
            System.out.println("响应签名验签" + apiResponse.getVerify());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 撤销测试
     *
     * @param spdbMrchNo
     * @param terminalNo
     * @param clientId
     * @param secret
     * @param privatekey
     * @param spdbPublicKey
     * @author wangmeng
     * @date 2023/10/16 17:07
     */
    private static void cancelTest(String spdbMrchNo, String terminalNo, String clientId, String secret, String privatekey, String spdbPublicKey, String mrchOrigOrdrNo, String frmrMrchOrdrNo) {
        AppPayCancel appPayTrade = new AppPayCancel();
        appPayTrade.setSpdbMrchNo(spdbMrchNo);//商户号
        appPayTrade.setMrchOrigOrdrNo(mrchOrigOrdrNo);//原收单系统订单号
        appPayTrade.setMrchOrdrNo(PayCommonUtil.getFangShiOrder());
        appPayTrade.setMrchTm(DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN));
        appPayTrade.setFrmrMrchOrdrNo(frmrMrchOrdrNo);//原商户订单号
        appPayTrade.setSubMechNoAcctID("wx4f56e9b3398a7fb3");

        //请求方法
        String method = "POST";
        // 请求的URL,请使用对API外接口文档中提供的URL
        String url = "https://api.spdb.com.cn/spdb/prd/api/acquiring/appPay/cancel";
        /*
         * 请求报文体 {"name":"zhangshan"} 注意换行符和空格
         * 如果是图文信息上传，请参考国密普通验签图片上传接口测试工程.zip
         */
        //String requestBody = "{\"name\":\"zhangshan\"}";
        JSONConfig jsonConfig = new JSONConfig();
        jsonConfig.setIgnoreNullValue(false);
        String requestBody = JSONUtil.toJsonStr(appPayTrade, jsonConfig);
        System.out.println("请求体：" + JSONUtil.toXmlStr(JSONUtil.parse(appPayTrade)));
        // 是否获取防重放参数
        Boolean forbidden = false;
        //是否是全报文
        Boolean encryption = true;

        try {
            ApiResponse apiResponse = SPDBSMEncryptor.requestApi(clientId, secret, privatekey, spdbPublicKey, method, url, requestBody, forbidden, encryption);
            System.out.println("响应状态码" + apiResponse.getCode());
            System.out.println("响应报文" + apiResponse.getBody());
            System.out.println("响应解密报文" + apiResponse.getDecryptBody());
            System.out.println("响应签名验签" + apiResponse.getVerify());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 退货测试
     *
     * @param spdbMrchNo
     * @param terminalNo
     * @param clientId
     * @param secret
     * @param privatekey
     * @param spdbPublicKey
     * @author wangmeng
     * @date 2023/10/16 17:07
     */
    private static void refundTest(String spdbMrchNo, String terminalNo, String clientId, String secret, String privatekey, String spdbPublicKey, String mrchOrigOrdrNo, String frmrMrchOrdrNo) {
        AppPayReturn appPayReturn = new AppPayReturn();
        appPayReturn.setSpdbMrchNo(spdbMrchNo);//商户号
        appPayReturn.setTranAmt("0.01");
        appPayReturn.setMrchOrigOrdrNo(mrchOrigOrdrNo);//原收单系统订单号
        appPayReturn.setMrchOrdrNo(PayCommonUtil.getFangShiOrder());
        appPayReturn.setMrchTm(DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN));

        //请求方法
        String method = "POST";
        // 请求的URL,请使用对API外接口文档中提供的URL
        String url = "https://api.spdb.com.cn/spdb/prd/api/acquiring/appPay/return";
        /*
         * 请求报文体 {"name":"zhangshan"} 注意换行符和空格
         * 如果是图文信息上传，请参考国密普通验签图片上传接口测试工程.zip
         */
        //String requestBody = "{\"name\":\"zhangshan\"}";
        JSONConfig jsonConfig = new JSONConfig();
        jsonConfig.setIgnoreNullValue(false);
        String requestBody = JSONUtil.toJsonStr(appPayReturn, jsonConfig);
        System.out.println("请求体：" + JSONUtil.toXmlStr(JSONUtil.parse(appPayReturn)));
        // 是否获取防重放参数
        Boolean forbidden = false;
        //是否是全报文
        Boolean encryption = true;

        try {
            ApiResponse apiResponse = SPDBSMEncryptor.requestApi(clientId, secret, privatekey, spdbPublicKey, method, url, requestBody, forbidden, encryption);
            System.out.println("响应状态码" + apiResponse.getCode());
            System.out.println("响应报文" + apiResponse.getBody());
            System.out.println("响应解密报文" + apiResponse.getDecryptBody());
            System.out.println("响应签名验签" + apiResponse.getVerify());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 查证测试
     *
     * @param spdbMrchNo
     * @param terminalNo
     * @param clientId
     * @param secret
     * @param privatekey
     * @param spdbPublicKey
     * @author wangmeng
     * @date 2023/10/16 17:07
     */
    private static void statusTest(String spdbMrchNo, String terminalNo, String clientId, String secret, String privatekey, String spdbPublicKey, String tranOrdrNo, String mrchOrdrNo) {
        AppPayStatus appPayReturn = new AppPayStatus();
        appPayReturn.setTranOrdrNo(tranOrdrNo);
        appPayReturn.setTranDate(DateUtil.format(DateUtil.date(), DatePattern.PURE_DATE_PATTERN));
        appPayReturn.setSpdbMrchNo(spdbMrchNo);//商户号
        appPayReturn.setMrchOrdrNo(mrchOrdrNo);

        //请求方法
        String method = "GET";
        // 请求的URL,请使用对API外接口文档中提供的URL
        String url = "https://api.spdb.com.cn/spdb/prd/api/acquiring/appPay/status";
        /*
         * 请求报文体 {"name":"zhangshan"} 注意换行符和空格
         * 如果是图文信息上传，请参考国密普通验签图片上传接口测试工程.zip
         */
        //String requestBody = "{\"name\":\"zhangshan\"}";
        JSONConfig jsonConfig = new JSONConfig();
        jsonConfig.setIgnoreNullValue(false);
        String requestBody = JSONUtil.toJsonStr(appPayReturn, jsonConfig);
        System.out.println("请求体：" + JSONUtil.toXmlStr(JSONUtil.parse(appPayReturn)));
        // 是否获取防重放参数
        Boolean forbidden = false;
        //是否是全报文
        Boolean encryption = true;

        try {
            ApiResponse apiResponse = SPDBSMEncryptor.requestApi(clientId, secret, privatekey, spdbPublicKey, method, url, requestBody, forbidden, encryption);
            System.out.println("响应状态码" + apiResponse.getCode());
            System.out.println("响应报文" + apiResponse.getBody());
            System.out.println("响应解密报文" + apiResponse.getDecryptBody());
            System.out.println("响应签名验签" + apiResponse.getVerify());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
