package com.slodon.b2b2c.starter.util;

import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.slodon.b2b2c.core.config.DomainUrlUtil;
import com.slodon.b2b2c.core.constant.OrderConst;
import com.slodon.b2b2c.core.exception.MallException;
import com.slodon.b2b2c.core.util.AssertUtil;
import com.slodon.b2b2c.starter.entity.cpcn.*;
import cpcn.institution.tools.net.RequestDgtEnvlp;
import cpcn.institution.tools.util.DigitalEnvelopeUtil;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import payment.api.system.PaymentEnvironment;
import payment.api.system.TxMessenger;
import payment.api.tx.TxBaseRequest;
import payment.api.tx.aggregate.*;
import payment.api.tx.enrollment.Tx7703Request;
import payment.api.tx.enrollment.Tx7703Response;
import payment.api.tx.enrollment.Tx7704Request;
import payment.api.tx.enrollment.Tx7704Response;
import payment.api.tx.foundationaccount.*;
import payment.api.tx.gatheringaccredit.Tx2751Request;
import payment.api.tx.gatheringaccredit.Tx2751Response;
import payment.api.tx.payroll.Tx4600Request;
import payment.api.tx.payroll.Tx4600Response;
import payment.api.util.GUIDGenerator;
import payment.api.vo.ImageInfo;
import payment.api.vo.SplitItem;

import java.math.BigDecimal;
import java.util.ArrayList;

/**
 * 中金支付工具类，用于处理非支付业务
 */
@Slf4j
public class ZjPayUtil {
    //中金支付网关地址
    public static String ZJ_PAY_SEND_URL;
    //影印件上传地址
    public static String ZJ_FILE_SEND_URL;
    //自助签约地址
    public static String ZJ_SIGN_URL;
    public static final String CALLBACK_URL_4618 = DomainUrlUtil.SLD_API_URL + "/v3/seller/seller/openAccount/callback";//开户回调
    public static final String CALLBACK_URL_7709 = DomainUrlUtil.SLD_API_URL + "/v3/seller/seller/openAccount/callbackSign";//签约回调
    public static final String CALLBACK_URL_4658 = DomainUrlUtil.SLD_API_URL + "/v3/seller/seller/withdrawal/callback";//提现回调

    //中金支付环境初始化
    static {
        String payEnvConfigPath = "/data/ym_config/";//中金支付配置文件路径
        if (DomainUrlUtil.ZJ_PAY_TEST == 1){
            //测试环境
            payEnvConfigPath = payEnvConfigPath + "test";
            ZJ_PAY_SEND_URL = "https://test.cpcn.com.cn/Gateway/InterfaceII";
            ZJ_FILE_SEND_URL = "https://test.cpcn.com.cn/Gateway4File/InterfaceII";
            ZJ_SIGN_URL = "https://test.cpcn.com.cn/EnrollmentWeb/";
        }else {
            //生产环境
            payEnvConfigPath = payEnvConfigPath + "proc";
            ZJ_PAY_SEND_URL = "https://www.china-clearing.com/Gateway/InterfaceII";
            ZJ_FILE_SEND_URL = "https://www.china-clearing.com/Gateway4File/InterfaceII";
            ZJ_SIGN_URL = "https://elr.cpcn.com.cn/EnrollmentWeb/";
        }
        try {
            PaymentEnvironment.initialize(payEnvConfigPath);
        } catch (Exception e) {
            log.error("初始化中金支付环境失败",e);
        }
    }

    /**
     * 5016查询订单支付状态
     *
     * @param txSn 支付流水号
     * @param institutionID 机构代码
     * @return  支付状态，1-支付中，2-已关闭，3-支付成功
     */
    public static Integer queryOrderState(String txSn,String institutionID) throws Exception {

        Tx5016Response txResponse = queryOrder(txSn,institutionID);
        /*
        10=未支付
        20=支付处理中
        30=支付成功
        40=支付失败
        50=订单关闭
         */
        String status = txResponse.getStatus();
        if (StringUtils.isEmpty(status)){
            //查询失败
            log.debug("查询中金支付订单[" + txSn + "]失败:" + txResponse.getMessage());
            return OrderConst.ZJ_PAY_TX_STATE_1;
        }
        log.debug("查询结果：" + JSON.toJSONString(txResponse));
        switch (status){
            case "30"://支付成功
                return OrderConst.ZJ_PAY_TX_STATE_3;
            case "40":
            case "50":
                return OrderConst.ZJ_PAY_TX_STATE_2;
            default:
                return OrderConst.ZJ_PAY_TX_STATE_1;
        }
    }

    /**
     * 5016查询订单支付状态
     *
     * @param txSn 支付流水号
     * @param institutionID 机构代码
     * @return  支付响应
     */
    public static Tx5016Response queryOrder(String txSn,String institutionID) throws Exception {
        //拼接请求参数
        Tx5016Request tx5016Request = new Tx5016Request();
        tx5016Request.setInstitutionID(institutionID);
        tx5016Request.setTxSN(txSn);

        //获取响应
        String[] respMsg = sendAndGet(tx5016Request);
        return new Tx5016Response(respMsg[0], respMsg[1]);
    }

    /**
     * 5014关闭支付订单
     *
     * @param txSn 支付流水号
     */
    public static void closeOrder(String txSn,String institutionID) throws Exception {
        Tx5014Request request = new Tx5014Request();
        request.setInstitutionID(institutionID);
        request.setTxSN(GUIDGenerator.genGUID());
        request.setPaymentTxSN(txSn);
        request.setCloseType("10");
        sendAndGet(request);
    }

    /**
     * 2751根据银行卡号获取银行信息
     *
     * @param bankAccount 银行卡号
     * @param institutionID 机构号
     * @return 银行编码
     */
    public static String getBankInfo(String bankAccount,String institutionID) throws Exception {
        Tx2751Request request = new Tx2751Request();
        request.setInstitutionID(institutionID);
        request.setTxSN(GUIDGenerator.genGUID());
        request.setAccountNumber(bankAccount);

        String[] respMsg = sendAndGet(request);
        Tx2751Response txResponse = new Tx2751Response(respMsg[0], respMsg[1]);
        if (!"2000".equals(txResponse.getCode())){
            //请求失败
            log.error("查询银行信息异常：" + txResponse.getMessage());
            throw new MallException("银行卡号有误请确认后重新输入");
        }
        if (!"2000".equals(txResponse.getResponseCode())){
            //请求失败
            log.error("查询银行信息异常：" + txResponse.getResponseMessage());
            throw new MallException("银行卡号有误请确认后重新输入");
        }
        AssertUtil.notEmpty(txResponse.getBankID(),"银行卡号有误请确认后重新输入");
        return txResponse.getBankID();
    }

    /**
     * 4600 上传商户资质信息
     * 不校验结果
     *
     * @param request 资质请求信息
     */
    public static Tx4600Response uploadSellerQualification(TxSellerQualificationRequest request) throws Exception {
        Tx4600Request tx4600Request = new Tx4600Request();
        tx4600Request.setInstitutionID(request.getInstitutionId());
        tx4600Request.setTxSN(request.getTxSn());
        tx4600Request.setBusinessType("10");
        tx4600Request.setOCRFlag("20");
        tx4600Request.setUserID(request.getUserId());
        request.getImageList().forEach(qualificationImage -> {
            if (CollectionUtils.isEmpty(tx4600Request.getImageInfoList())){
                tx4600Request.setImageInfoList(new ArrayList<>());
            }
            ImageInfo imageInfo = new ImageInfo();
            imageInfo.setImageType(qualificationImage.getImageType());
            imageInfo.setImageContent(qualificationImage.getImageContent());
            imageInfo.setItemNo(qualificationImage.getItemNo());
            tx4600Request.getImageInfoList().add(imageInfo);
        });

        String[] respMsg = sendAndGet(tx4600Request);
        return new Tx4600Response(respMsg[0], respMsg[1]);
    }

    /**
     * 4601 商户开户、绑卡
     * 不校验结果
     *
     * @param request 开户绑卡信息
     */
    public static Tx4601Response openAccount(TxOpenAccountRequest request) throws Exception {
        Tx4601Request tx4601Request = new Tx4601Request();
        tx4601Request.setInstitutionID(request.getInstitutionId());
        tx4601Request.setTxSN(request.getTxSn());
        tx4601Request.setUserID(request.getUserId());
        tx4601Request.setUserType(request.getUserType());
        tx4601Request.setImageCollectionTxSN(request.getImageCollectionTxSN());
        tx4601Request.setBusinessType(request.getBusinessType());

        if ("11".equals(request.getUserType())){
            //个人开户
            TxOpenAccountRequest.PersonalInfo personalInfo = request.getPersonalInfo();
            tx4601Request.setPhoneNumber(personalInfo.getPhoneNumber());
            tx4601Request.setUserName(personalInfo.getUserName());
            tx4601Request.setCredentialType(personalInfo.getCredentialType());
            tx4601Request.setCredentialNumber(personalInfo.getCredentialNumber());
            tx4601Request.setIssDate(personalInfo.getIssDate());
            tx4601Request.setExpiryDate(personalInfo.getExpiryDate());
            tx4601Request.setIndAddress(personalInfo.getIndAddress());
            tx4601Request.setIndEmail(personalInfo.getIndEmail());
        }else if ("12".equals(request.getUserType())){
            //企业开户
            TxOpenAccountRequest.EnterpriseInfo enterpriseInfo = request.getEnterpriseInfo();
            tx4601Request.setCorporationName(enterpriseInfo.getCorporationName());
            tx4601Request.setCorporationShort(enterpriseInfo.getCorporationShort());
            tx4601Request.setCategoryType(enterpriseInfo.getCategoryType());
            tx4601Request.setCorEmail(enterpriseInfo.getCorEmail());
            tx4601Request.setCorAddress(enterpriseInfo.getCorAddress());
            tx4601Request.setProvince(enterpriseInfo.getProvince());
            tx4601Request.setCity(enterpriseInfo.getCity());
            tx4601Request.setDistrict(enterpriseInfo.getDistrict());
            tx4601Request.setScale(enterpriseInfo.getScale());
            tx4601Request.setBasicAcctNo(enterpriseInfo.getBasicAcctNo());
            tx4601Request.setApprovalNo(enterpriseInfo.getApprovalNo());
            tx4601Request.setUnifiedSocialCreditCode(enterpriseInfo.getUnifiedSocialCreditCode());
            tx4601Request.setAllLicenceIssDate(enterpriseInfo.getAllLicenceIssDate());
            tx4601Request.setAllLicenceExpiryDate(enterpriseInfo.getAllLicenceExpiryDate());
            tx4601Request.setLegalPersonName(enterpriseInfo.getLegalPersonName());
            tx4601Request.setLegalCredentialType(enterpriseInfo.getLegalCredentialType());
            tx4601Request.setLegalCredentialNumber(enterpriseInfo.getLegalCredentialNumber());
            tx4601Request.setLegalPersonIssDate(enterpriseInfo.getLegalPersonIssDate());
            tx4601Request.setLegalPersonExpiryDate(enterpriseInfo.getLegalPersonExpiryDate());
            tx4601Request.setLegalPersonContactNumber(enterpriseInfo.getLegalPersonContactNumber());
        }else if ("13".equals(request.getUserType())){
            //个体工商户开户
            TxOpenAccountRequest.IndividualInfo individualInfo = request.getIndividualInfo();
            tx4601Request.setManagerName(individualInfo.getManagerName());
            tx4601Request.setManagerCredentialType(individualInfo.getManagerCredentialType());
            tx4601Request.setManagerCredentialNumber(individualInfo.getManagerCredentialNumber());
            tx4601Request.setManagerIssDate(individualInfo.getManagerIssDate());
            tx4601Request.setManagerExpiryDate(individualInfo.getManagerExpiryDate());
            tx4601Request.setManagerContactNumber(individualInfo.getManagerContactNumber());
            tx4601Request.setManagerEmail(individualInfo.getManagerEmail());
            tx4601Request.setRetailerRegNumber(individualInfo.getRetailerRegNumber());
            tx4601Request.setRetailerName(individualInfo.getRetailerName());
            tx4601Request.setRetailerLicenseIssDate(individualInfo.getRetailerLicenseIssDate());
            tx4601Request.setRetailerLicenseExpiryDate(individualInfo.getRetailerLicenseExpiryDate());
            tx4601Request.setRetailerAddress(individualInfo.getRetailerAddress());
            tx4601Request.setRetailerProvince(individualInfo.getRetailerProvince());
            tx4601Request.setRetailerCity(individualInfo.getRetailerCity());
            tx4601Request.setRetailerDistrict(individualInfo.getRetailerDistrict());
        }

        tx4601Request.setNoticeURL(CALLBACK_URL_4618);

        String[] respMsg = sendAndGet(tx4601Request);
        return new Tx4601Response(respMsg[0], respMsg[1]);
    }

    /**
     * 4611 绑卡
     *
     * @param request 绑卡参数
     */
    public static Tx4611Response bindCard(TxBindCardRequest request) throws Exception {
        Tx4611Request tx4611Request = new Tx4611Request();
        tx4611Request.setInstitutionID(request.getInstitutionId());
        tx4611Request.setBindingTxSN(request.getBindingTxSn());
        tx4611Request.setUserID(request.getUserId());
        tx4611Request.setBankCardType(request.getBankCardType());
        tx4611Request.setOperationFlag(request.getOperationFlag());
        tx4611Request.setBindingWay(request.getBindingWay());
        tx4611Request.setCredentialType(request.getCredentialType());
        tx4611Request.setCredentialNumber(request.getCredentialNumber());
        tx4611Request.setBankID(request.getBankId());
        tx4611Request.setBankAccountType(request.getBankAccountType());
        tx4611Request.setBankAccountName(request.getBankAccountName());
        tx4611Request.setBankAccountNumber(request.getBankAccountNumber());
        tx4611Request.setBankPhoneNumber(request.getBankPhoneNumber());
        tx4611Request.setBranchName(request.getBranchName());
        tx4611Request.setProvince(request.getProvince());
        tx4611Request.setCity(request.getCity());
        tx4611Request.setNoticeURL(request.getNoticeURL());
        tx4611Request.setPageURL(request.getPageURL());

        String[] respMsg = sendAndGet(tx4611Request);
        return new Tx4611Response(respMsg[0], respMsg[1]);
    }

    /**
     * 4613 确认绑卡
     *
     * @param request 确认绑卡参数
     */
    public static Tx4613Response confirmBindCard(TxBindCardConfirmRequest request) throws Exception {
        Tx4613Request tx4613Request = new Tx4613Request();
        tx4613Request.setInstitutionID(request.getInstitutionId());
        tx4613Request.setTxSN(request.getBindingTxSn());
        tx4613Request.setVerifyWay(request.getVerifyWay());
        tx4613Request.setSMSCode(request.getSmsCode());
        tx4613Request.setAmount(request.getAmount());

        String[] respMsg = sendAndGet(tx4613Request);
        return new Tx4613Response(respMsg[0], respMsg[1]);
    }


    /**
     * 4616 开户、绑卡进度查询
     *
     * @param txSn 开户申请流水号
     * @param institutionID 机构号
     * @param userType 用户类型，11-个人用户，12-企业用户，13-个体工商用户
     * @param sourceTxCode 原业务交易编码：4601-开户，4611-绑卡
     */
    public static Tx4616Response getOpenAccountProcess(String txSn,String institutionID,String userType,String sourceTxCode) throws Exception {
        Tx4616Request tx4616Request = new Tx4616Request();
        tx4616Request.setInstitutionID(institutionID);
        tx4616Request.setSourceTxSN(txSn);
        tx4616Request.setSourceTxCode(sourceTxCode);
        tx4616Request.setUserType(userType);

        String[] respMsg = sendAndGet(tx4616Request);
        Tx4616Response txResponse = new Tx4616Response(respMsg[0], respMsg[1]);
        if (!"2000".equals(txResponse.getCode())){
            //请求失败
            log.error("查询开户、绑卡进度查询异常：" + txResponse.getMessage());
            throw new MallException("查询开户、绑卡进度查询异常：" + txResponse.getMessage());
        }
        return txResponse;
    }

    /**
     * 5031 延迟分账
     *
     * @param request 分账信息
     */
    public static Tx5031Response splitAccount(TxSplitAccountRequest request) throws Exception{
        Tx5031Request tx5031Request = new Tx5031Request();
        tx5031Request.setInstitutionID(request.getInstitutionId());
        tx5031Request.setTxSN(request.getTxSn());
        tx5031Request.setPaymentTxSN(request.getPaymentTxSN());
        tx5031Request.setRemainFundsProcess(request.getRemainFundsProcess());
        tx5031Request.setNoticeURL(request.getNoticeURL());
        tx5031Request.setSourceTxTime(request.getSourceTxTime());
        request.getSplitSellerInfoList().forEach(splitSellerInfo -> {
            if (CollectionUtils.isEmpty(tx5031Request.getSplitItemsList())){
                tx5031Request.setSplitItemsList(new ArrayList<>());
            }
            SplitItem splitItem = new SplitItem();
            splitItem.setSplitTxSN(splitSellerInfo.getSplitTxSN());
            splitItem.setSplitUserID(splitSellerInfo.getSplitUserID());
            splitItem.setSplitAccountNumber(splitSellerInfo.getSplitAccountNumber());
            splitItem.setSplitAmount(splitSellerInfo.getSplitAmount());
            splitItem.setNote(splitSellerInfo.getNote());
            tx5031Request.getSplitItemsList().add(splitItem);
        });

        String[] respMsg = sendAndGet(tx5031Request);
        return new Tx5031Response(respMsg[0], respMsg[1]);
    }

    /**
     * 商户签约
     *
     * @param request 签约信息
     */
    public static Tx7703Response sellerSign(SellerSignRequest request) throws Exception {
        Tx7703Request tx7703Request = new Tx7703Request();
        tx7703Request.setInstitutionID(request.getInstitutionId());
        tx7703Request.setApplyNo(request.getApplyNo());
        tx7703Request.setUserID(request.getUserId());
        tx7703Request.setProtocolNumber(request.getProtocolNumber());
        tx7703Request.setProtocolSignerType("10");
        tx7703Request.setImmediatelySign("20");
        tx7703Request.setNoticeURL(CALLBACK_URL_7709);
        String[] respMsg = sendAndGet(tx7703Request);

        return new Tx7703Response(respMsg[0], respMsg[1]);
    }

    /**
     * 商户签约查询
     *
     * @param applyNo 申请流水号
     * @param institutionID 申请流水号
     */
    public static Tx7704Response querySellerSign(String applyNo, String institutionID) throws Exception {
        Tx7704Request tx7704Request = new Tx7704Request();
        tx7704Request.setInstitutionID(institutionID);
        tx7704Request.setApplyNo(applyNo);

        String[] respMsg = sendAndGet(tx7704Request);

        return new Tx7704Response(respMsg[0], respMsg[1]);
    }

    /**
     * 商户账户信息查询
     *
     * @param userId 用户id，店铺id
     * @param institutionID 申请流水号
     */
    public static Tx4691Response querySellerAccountInfo(String userId,String institutionID) throws Exception {
        Tx4691Request tx4691Request = new Tx4691Request();
        tx4691Request.setInstitutionID(institutionID);
        tx4691Request.setUserID(userId);

        String[] respMsg = sendAndGet(tx4691Request);

        return new Tx4691Response(respMsg[0], respMsg[1]);
    }

    /**
     * 商户提现
     *
     * @param userId 用户id，店铺id
     * @param institutionID 申请流水号
     */
    public static Tx4643Response sellerWithdrawal(String userId, String institutionID, String bindTxSn, BigDecimal amount) throws Exception {
        Tx4643Request tx4643Request = new Tx4643Request();
        tx4643Request.setInstitutionID(institutionID);
        tx4643Request.setTxSN(GUIDGenerator.genGUID());
        tx4643Request.setUserID(userId);
        tx4643Request.setArrivalType("10");//T+1到账
        tx4643Request.setBindingTxSN(bindTxSn);
        tx4643Request.setAmount(String.valueOf(amount.multiply(new BigDecimal(100)).intValue()));
        tx4643Request.setNoticeURL(CALLBACK_URL_4658);

        String[] respMsg = sendAndGet(tx4643Request);

        return new Tx4643Response(respMsg[0], respMsg[1]);
    }

    /**
     * 向支付平台发送请求获取响应
     *
     * @param txBaseRequest 支付请求
     * @return 响应数组
     * @throws Exception 异常信息
     */
    public static String[] sendAndGet(TxBaseRequest txBaseRequest) throws Exception {
        //执行报文处理
        txBaseRequest.process();

        //发送消息到中金支付平台，接收响应
        TxMessenger txMessenger = new TxMessenger();
        RequestDgtEnvlp dgtEnvlp = new RequestDgtEnvlp();
        dgtEnvlp.setIsDgEnv(PaymentEnvironment.isDgEnv);
        dgtEnvlp.setDgtlEnvlp(txBaseRequest.getDgtlEnvlp());
        dgtEnvlp.setSignAlgorithm(txBaseRequest.getSignAlgorithm());
        dgtEnvlp.setSignSN(txBaseRequest.getSignSN());
        dgtEnvlp.setEncryptSN(txBaseRequest.getEncryptSN());
        dgtEnvlp.setInstitutionID("007660");

        String[] respMsg;
        if (txBaseRequest.getTxCode().equals("4600")){
            respMsg = txMessenger.send(txBaseRequest.getRequestMessage(), txBaseRequest.getRequestSignature(), dgtEnvlp, ZJ_FILE_SEND_URL);
        }else {
            respMsg = txMessenger.send(txBaseRequest.getRequestMessage(), txBaseRequest.getRequestSignature(), dgtEnvlp, ZJ_PAY_SEND_URL);
        }
        String plainText;
        if ("YES".equals(respMsg[2])) {
            //如果响应是数字信封，对消息进行对称解密
            try {
                log.info("开始对响应消息做对称解密。。。。。。");
                respMsg[0] = DigitalEnvelopeUtil.decryptResponse(respMsg[0], respMsg[3], respMsg[5], respMsg[6]);
                plainText = respMsg[0];
                respMsg[0] = Base64.encode(respMsg[0], "UTF-8");
                respMsg[0] = respMsg[0] + "," + respMsg[5] + "," + respMsg[4] + "," + respMsg[2];
                log.info("响应消息做对称解密完成。。。。。。");
                log.info("响应消息报文：[" + plainText + "]");
            } catch (Exception e) {
                log.error("中金查询支付信息异常：" ,e);
                throw new MallException("对称解密异常！");
            }
        } else {
            // 1:signature
            log.debug("respMsg[0]========" + respMsg[0]);
            log.debug("respMsg[5]========" + respMsg[5]);
            log.debug("respMsg[1]========" + respMsg[1]);
            if (StringUtil.isNotEmpty(respMsg[5])) {
                respMsg[0] = respMsg[0] + "," + respMsg[5] + "," + respMsg[4] + "," + respMsg[2];
            }
        }

        return respMsg;
    }

    public static String institutionId = "007660";

    //账户查询
    public static void main(String[] args) throws Exception {
        Tx4691Response tx4691Response = querySellerAccountInfo("4", institutionId);
        System.out.println(tx4691Response);
    }

    //提现
//    public static void main(String[] args) throws Exception {
//        Tx4643Response tx4643Response = sellerWithdrawal("4", institutionId, "202204201945369655628867592", new BigDecimal(200));
//        System.out.println(tx4643Response);
//    }

    //商户签约
//    public static void main(String[] args) throws Exception {
//        SellerSignRequest sellerSignRequest = new SellerSignRequest();
//        sellerSignRequest.setInstitutionId(institutionId);
//        sellerSignRequest.setApplyNo(GUIDGenerator.genGUID());
//        sellerSignRequest.setUserId("510008");
//
//        Tx7703Response tx7703Response = sellerSign(sellerSignRequest);
//        System.out.println(JSON.toJSONString(tx7703Response));
//    }

    //签约查询
//    public static void main(String[] args) throws Exception {
//        Tx7704Response tx7704Response = querySellerSign("510008000000", institutionId);
//        System.out.println(JSON.toJSONString(tx7704Response));
//    }

//    public static void main(String[] args) throws Exception {
//        Tx5016Response tx5016Response = queryOrder("202204291142355714445836832", institutionId);
//        System.out.println(tx5016Response);
//    }

//    public static void main(String[] args) throws Exception {
//        TxSellerQualificationRequest request = new TxSellerQualificationRequest();
//        request.setInstitutionId(institutionId);
//        request.setTxSn(GUIDGenerator.genGUID());
//        request.setUserId("admin");
//
//        TxSellerQualificationRequest.QualificationImage image = new TxSellerQualificationRequest.QualificationImage();
//        image.setItemNo(GUIDGenerator.genGUID());
//        image.setImageType("10");
//        image.setImageContent(" ");
//
//        TxSellerQualificationRequest.QualificationImage image2 = new TxSellerQualificationRequest.QualificationImage();
//        image2.setItemNo(GUIDGenerator.genGUID());
//        image2.setImageType("11");
//        image2.setImageContent(" ");
//
//        TxSellerQualificationRequest.QualificationImage image3 = new TxSellerQualificationRequest.QualificationImage();
//        image3.setItemNo(GUIDGenerator.genGUID());
//        image3.setImageType("20");
//        image3.setImageContent(" ");
//
//        TxSellerQualificationRequest.QualificationImage image4 = new TxSellerQualificationRequest.QualificationImage();
//        image4.setItemNo(GUIDGenerator.genGUID());
//        image4.setImageType("21");
//        image4.setImageContent(" ");
//
//        request.getImageList().add(image);
//        request.getImageList().add(image2);
//        request.getImageList().add(image3);
//        request.getImageList().add(image4);
//        Tx4600Response tx4600Response = uploadSellerQualification(request);
//        System.out.println(request.getTxSn());
//        System.out.println(JSON.toJSONString(tx4600Response));
//    }


    //开户
//    public static void main(String[] args) throws Exception {
//        TxOpenAccountRequest txOpenAccountRequest = new TxOpenAccountRequest();
//        txOpenAccountRequest.setInstitutionId(institutionId);
//        txOpenAccountRequest.setTxSn(GUIDGenerator.genGUID());
//        txOpenAccountRequest.setUserId("admin");
//        txOpenAccountRequest.setUserType("12");
//        txOpenAccountRequest.setImageCollectionTxSN("202204291915212955135260664");
//        txOpenAccountRequest.setBusinessType("10");
//
////        TxOpenAccountRequest.PersonalInfo personalInfo = new TxOpenAccountRequest.PersonalInfo();
////        personalInfo.setPhoneNumber("13555555555");
////        personalInfo.setUserName("董大羡");
////        personalInfo.setCredentialNumber("542322195005103362");
////        personalInfo.setIssDate("20200101");
////        personalInfo.setExpiryDate("20400101");
////        personalInfo.setIndAddress("aaaaaa");
////        personalInfo.setIndEmail("111@163.com");
////        txOpenAccountRequest.setPersonalInfo(personalInfo);
//
//        TxOpenAccountRequest.EnterpriseInfo enterpriseInfo = new TxOpenAccountRequest.EnterpriseInfo();
//        enterpriseInfo.setCorporationName("未迟数字公司");
//        enterpriseInfo.setCorporationShort("slodon");
////        enterpriseInfo.setCategoryType();
//        enterpriseInfo.setCorEmail("slodon@slodon.com");
//        enterpriseInfo.setCorAddress("北京北京西小口");
//        enterpriseInfo.setProvince("11");
//        enterpriseInfo.setCity("110000");
//        enterpriseInfo.setDistrict("110101");
//        enterpriseInfo.setBasicAcctNo("6255862222222222210");
//        enterpriseInfo.setApprovalNo("11111111111111");
//        enterpriseInfo.setUnifiedSocialCreditCode("111111111111111111");
//        enterpriseInfo.setAllLicenceIssDate("20200101");
//        enterpriseInfo.setAllLicenceExpiryDate("99991231");
//        enterpriseInfo.setLegalPersonName("王大");
//        enterpriseInfo.setLegalCredentialNumber("320102199701015234");
//        enterpriseInfo.setLegalPersonIssDate("19800101");
//        enterpriseInfo.setLegalPersonExpiryDate("99991231");
//        enterpriseInfo.setLegalPersonContactNumber("13333333333");
////        enterpriseInfo.setConsigneeName("");
////        enterpriseInfo.setConsigneeCredentialType("");
////        enterpriseInfo.setConsigneeCredentialNumber("");
////        enterpriseInfo.setConsigneeIssDate("");
////        enterpriseInfo.setConsigneeExpiryDate("");
////        enterpriseInfo.setConsigneeContactNumber("");
//
//        txOpenAccountRequest.setEnterpriseInfo(enterpriseInfo);
////        txOpenAccountRequest.setIndividualInfo();
//
//        System.out.println(txOpenAccountRequest.getTxSn());
//        Tx4601Response tx4601Response = openAccount(txOpenAccountRequest);
//        System.out.println(JSON.toJSONString(tx4601Response));
//    }

    //绑卡
//    public static void main(String[] args) throws Exception {
//        TxBindCardRequest txBindCardRequest = new TxBindCardRequest();
//        txBindCardRequest.setInstitutionId(institutionId);
//        txBindCardRequest.setBindingTxSn(GUIDGenerator.genGUID());
//        txBindCardRequest.setUserId("admin");
//        txBindCardRequest.setBankCardType("10");
//        txBindCardRequest.setOperationFlag("10");
//        txBindCardRequest.setBindingWay("20");
////        txBindCardRequest.setCredentialNumber("542322195005103362");
//        txBindCardRequest.setBankId("100");
//        txBindCardRequest.setBankAccountType("12");
//        txBindCardRequest.setBankAccountName("未迟数字公司");
//        txBindCardRequest.setBankAccountNumber("6255862222222222220");
////        txBindCardRequest.setBankPhoneNumber("13555555555");
//        txBindCardRequest.setBranchName("北京支行");
//        txBindCardRequest.setProvince("110000");
//        txBindCardRequest.setCity("110100");
////        txBindCardRequest.setNoticeURL();
////        txBindCardRequest.setPageURL();
//        Tx4611Response tx4611Response = bindCard(txBindCardRequest);
//        System.out.println(txBindCardRequest.getBindingTxSn());
//        System.out.println(JSON.toJSONString(tx4611Response));
//
//    }


    //确认绑卡
//    public static void main(String[] args) throws Exception {
//        TxBindCardConfirmRequest txBindCardConfirmRequest = new TxBindCardConfirmRequest();
//        txBindCardConfirmRequest.setInstitutionId(institutionId);
//        txBindCardConfirmRequest.setBindingTxSn("202204291910412663938364208");
//        txBindCardConfirmRequest.setVerifyWay("20");
////        txBindCardConfirmRequest.setSmsCode("134679");
//        txBindCardConfirmRequest.setAmount("1");
//
//        Tx4613Response tx4613Response = confirmBindCard(txBindCardConfirmRequest);
//        System.out.println(JSON.toJSONString(tx4613Response));
//    }

    //开户绑卡查询
//    public static void main(String[] args) throws Exception {
//        Tx4616Response openAccountProcess = getOpenAccountProcess("202204201945369655628867592", institutionId, "12","4611");
//        System.out.println(openAccountProcess);
//    }

    //支付查询
//    public static void main(String[] args) throws Exception {
//        System.out.println(queryOrderState("202204221130571545367125681", institutionId));
//    }

    //延迟分账
//    public static void main(String[] args) throws Exception {
//        TxSplitAccountRequest txSplitAccountRequest = new TxSplitAccountRequest();
//        txSplitAccountRequest.setInstitutionId(institutionId);
//        txSplitAccountRequest.setTxSn(GUIDGenerator.genGUID());
//        txSplitAccountRequest.setPaymentTxSN("202204221129245832269044956");
////        txSplitAccountRequest.setSourceTxTime();
//        txSplitAccountRequest.setRemainFundsProcess("1");
////        txSplitAccountRequest.setNoticeURL();
//
//        TxSplitAccountRequest.SplitSellerInfo splitSellerInfo1 = new TxSplitAccountRequest.SplitSellerInfo();
//        splitSellerInfo1.setSplitTxSN(GUIDGenerator.genGUID());
//        splitSellerInfo1.setSplitUserID("3");
//        splitSellerInfo1.setSplitAmount("200");
//        splitSellerInfo1.setNote("分账2元");
//
//        TxSplitAccountRequest.SplitSellerInfo splitSellerInfo2 = new TxSplitAccountRequest.SplitSellerInfo();
//        splitSellerInfo2.setSplitTxSN(GUIDGenerator.genGUID());
//        splitSellerInfo2.setSplitUserID("4");
//        splitSellerInfo2.setSplitAmount("800");
//        splitSellerInfo2.setNote("分账8元");
//        txSplitAccountRequest.getSplitSellerInfoList().add(splitSellerInfo1);
//        txSplitAccountRequest.getSplitSellerInfoList().add(splitSellerInfo2);
//        Tx5031Response tx5031Response = splitAccount(txSplitAccountRequest);
//        System.out.println(JSON.toJSONString(tx5031Response));
//
//    }
}
