package com.nuvole.util; import cn.hutool.core.convert.Convert; import com.alibaba.fastjson.JSONObject; import com.nuvole.common.domain.emnu.CommonResultEmnu; import com.nuvole.common.domain.result.CommonResult; import cpcn.institution.tools.net.RequestDgtEnvlp; import cpcn.institution.tools.util.DigitalEnvelopeUtil; import cpcn.institution.tools.util.StringUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import payment.api.system.AggregateEnvironment; import payment.api.system.Gateway4FileEnvironment; import payment.api.system.PaymentEnvironment; import payment.api.system.TxMessenger; import payment.api.tx.TxBaseRequest; import payment.api.tx.TxBaseResponse; import payment.api.tx.aggregate.Tx5011Request; import payment.api.tx.aggregate.Tx5011Response; 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.tx.statement.Tx1850Request; import payment.api.tx.statement.Tx1850Response; import payment.api.util.GUIDGenerator; import payment.api.vo.ImageInfo; import payment.api.vo.SplitItem; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; /** * @ClassName CncpUtil * @Author cy * @Date 2023/7/13 * @Description * @Version 1.0 **/ @Slf4j public class CncpUtil { public static void initUtil(String configPath) { try { PaymentEnvironment.initialize(configPath); } catch (Exception e) { e.printStackTrace(); } CncpUtil.paymentConfigPath = configPath; } private static String paymentConfigPath; public static String getPaymentConfigPath() { return paymentConfigPath; } /** * 影印件采集 * * @param businessType 业务类型: 10-壹企付-开户上传身份影印图片(默认) 11-壹企付-实名用户补充影印件 12-壹企付-开户信息修改影印件 20-薪享付-签约上传身份影印图片 30-信用支付-准入授权影像件 40-信用支付-用信申请凭证 * @return */ public static Tx4600Response tx4600(short businessType, String userId, ArrayList imageTypes) { Tx4600Request txRequest = new Tx4600Request(); txRequest.setInstitutionID(PaymentEnvironment.institutionID); txRequest.setTxSN(IdGenerator.getUUID()); txRequest.setBusinessType(businessType + ""); txRequest.setUserID(userId); txRequest.setImageInfoList(imageTypes); // 3.执行报文处理 try { txRequest.process(); } catch (Exception e) { e.printStackTrace(); } HashMap map = new HashMap(); map.put("Flag", "50"); putCommonParam(map, txRequest); return dealRequestResult(map, Tx4600Response.class); } /** * 开户接口用于个人、企业用户或个体工商户在机构系统开立银行电子账户环节。 * * @return * @throws Exception */ public static Tx4601Response tx4601(String userId) throws Exception { // 1.取得参数 String institutionID = PaymentEnvironment.institutionID; String txSN = GUIDGenerator.genGUID(); // String userID = null; String userID = "cy88888888"; String userType = "11"; String parentUserID = null; String phoneNumber = "17721229769"; String userName = "常远"; String credentialType = "0"; String credentialNumber = "410105199603076114"; String issDate = "20230130"; String expiryDate = "20231230"; String indAddress = "中国河南省郑州市金水区北林路街道"; String indEmail = "166459@qq.com"; String province = "41"; String city = "410100"; String district = "410105"; // String credentialAddress = request.getParameter("CredentialAddress"); // String occupation = request.getParameter("Occupation"); // String corporationName = "CorporationName"; // String corporationShort = "CorporationShort"; // String categoryType = "CategoryType"; // String corEmail = "CorEmail"; // String corAddress = "CorAddress"; // String industryBelongType = "IndustryBelongType"; // String industry = "Industry"; // String scale = "Scale"; // String basicAcctNo = "BasicAcctNo"; // String approvalNo = "ApprovalNo"; // String authCapital = "AuthCapital"; // String businessScope = "BusinessScope"; // String corType = "CorType"; // String unifiedSocialCreditCode = "UnifiedSocialCreditCode"; // String AllLicenceIssDate = "AllLicenceIssDate"; // String allLicenceExpiryDate = "AllLicenceExpiryDate"; // String legalPersonName = "LegalPersonName"; // String legalCredentialType = "LegalCredentialType"; // String legalCredentialNumber = "LegalCredentialNumber"; // String legalPersonIssDate = "LegalPersonIssDate"; // String legalPersonExpiryDate = "LegalPersonExpiryDate"; // String legalPersonContactNumber = "LegalPersonContactNumber"; // String legalPersonEmail = "LegalPersonEmail"; // String shareholder = "Shareholder"; // String controller = "Controller"; // String beneficiary = "Beneficiary"; // String consigneeName = "ConsigneeName"; // String consigneeCredentialType = "ConsigneeCredentialType"; // String consigneeCredentialNumber = "ConsigneeCredentialNumber"; // String consigneeIssDate = "ConsigneeIssDate"; // String consigneeExpiryDate = "ConsigneeExpiryDate"; // String consigneeContactNumber = "ConsigneeContactNumber"; //// // String[] shareholderNames = "ShareholderName"; // String[] shCredentialTypes = "ShCredentialType"; // String[] shCredentialNumbers = "ShCredentialNumber"; // String[] shPersonIssDates = "ShPersonIssDate"; // String[] shPersonExpiryDates = "ShPersonExpiryDate"; // // String managerName = "ManagerName"; // String managerCredentialType = "ManagerCredentialType"; // String managerCredentialNumber = "ManagerCredentialNumber"; // String managerIssDate = "ManagerIssDate"; // String managerExpiryDate = "ManagerExpiryDate"; // String managerContactNumber = "ManagerContactNumber"; // String managerEmail = "ManagerEmail"; // String managerCredentialAddress = "ManagerCredentialAddress"; // String managerOccupation = "ManagerOccupation"; // String retailerRegNumber = "RetailerRegNumber"; // String retailerName = "RetailerName"; // String retailerLicenseIssDate = "RetailerLicenseIssDate"; // String retailerLicenseExpiryDate = "RetailerLicenseExpiryDate"; // String retailerFormation = "RetailerFormation"; // String retailerAddress = "RetailerAddress"; // String retailerProvince = "RetailerProvince"; // String retailerCity = "RetailerCity"; // String retailerDistrict = "RetailerDistrict"; // String retailerBusinessScope = "RetailerBusinessScope"; // // String bankAbilityFlag = "BankAbilityFlag"; // String bindingTxSN = "BindingTxSN"; // String bankID = "BankID"; // String bankAccountNumber = "BankAccountNumber"; // String bankPhoneNumber = "BankPhoneNumber"; // String cNAPSCode = "CNAPSCode"; // String branchName = "BranchName"; // String bankProvince = "BankProvince"; // String bankCity = "BankCity"; // 2.创建交易请求对象 Tx4601Request tx4601Request = new Tx4601Request(); tx4601Request.setInstitutionID(institutionID); tx4601Request.setTxSN(txSN); tx4601Request.setUserID(userID); tx4601Request.setParentUserID(parentUserID); tx4601Request.setUserType(userType); // tx4601Request.setAcceptanceConfirmType(acceptanceConfirmType); // tx4601Request.setAccountLevel(accountLevel); // tx4601Request.setImageCollectionTxSN(imageCollectionTxSN); // tx4601Request.setNoticeURL(noticeURL); tx4601Request.setBusinessType("10"); tx4601Request.setPhoneNumber(phoneNumber); tx4601Request.setUserName(userName); tx4601Request.setCredentialType(credentialType); tx4601Request.setCredentialNumber(credentialNumber); tx4601Request.setIssDate(issDate); tx4601Request.setExpiryDate(expiryDate); tx4601Request.setIndAddress(indAddress); tx4601Request.setIndEmail(indEmail); // tx4601Request.setCredentialAddress(credentialAddress); // tx4601Request.setOccupation(occupation); // tx4601Request.setCorporationName(corporationName); // tx4601Request.setCorporationShort(corporationShort); // tx4601Request.setCategoryType(categoryType); // tx4601Request.setCorEmail(corEmail); // tx4601Request.setCorAddress(corAddress); tx4601Request.setProvince(province); tx4601Request.setCity(city); tx4601Request.setDistrict(district); // tx4601Request.setIndustryBelongType(industryBelongType); // tx4601Request.setIndustry(industry); // tx4601Request.setScale(scale); // tx4601Request.setBasicAcctNo(basicAcctNo); // tx4601Request.setApprovalNo(approvalNo); // tx4601Request.setAuthCapital(authCapital); // tx4601Request.setBusinessScope(businessScope); // tx4601Request.setCorType(corType); // tx4601Request.setUnifiedSocialCreditCode(unifiedSocialCreditCode); // tx4601Request.setAllLicenceIssDate(AllLicenceIssDate); // tx4601Request.setAllLicenceExpiryDate(allLicenceExpiryDate); // tx4601Request.setLegalPersonName(legalPersonName); // tx4601Request.setLegalCredentialType(legalCredentialType); // tx4601Request.setLegalCredentialNumber(legalCredentialNumber); // tx4601Request.setLegalPersonIssDate(legalPersonIssDate); // tx4601Request.setLegalPersonExpiryDate(legalPersonExpiryDate); // tx4601Request.setLegalPersonContactNumber(legalPersonContactNumber); // tx4601Request.setLegalPersonEmail(legalPersonEmail); // tx4601Request.setShareholder(shareholder); // tx4601Request.setController(controller); // tx4601Request.setBeneficiary(beneficiary); // tx4601Request.setConsigneeName(consigneeName); // tx4601Request.setConsigneeCredentialType(consigneeCredentialType); // tx4601Request.setConsigneeCredentialNumber(consigneeCredentialNumber); // tx4601Request.setConsigneeIssDate(consigneeIssDate); // tx4601Request.setConsigneeExpiryDate(consigneeExpiryDate); // tx4601Request.setConsigneeContactNumber(consigneeContactNumber); // // ArrayList shareholderPartsList = null; // if(shareholderNames != null && shareholderNames.length > 0){ // shareholderPartsList = new ArrayList(); // for(int i = 0; i < shareholderNames.length; i ++){ // ShareholderPart shareholderPart = new ShareholderPart(); // shareholderPart.setShareholderName(shareholderNames[i]); // shareholderPart.setShCredentialType(shCredentialTypes[i]); // shareholderPart.setShCredentialNumber(shCredentialNumbers[i]); // shareholderPart.setShPersonIssDate(shPersonIssDates[i]); // shareholderPart.setShPersonExpiryDate(shPersonExpiryDates[i]); // // shareholderPartsList.add(shareholderPart); // } // } // tx4601Request.setShareholderPartsList(shareholderPartsList); // // tx4601Request.setManagerName(managerName); // tx4601Request.setManagerCredentialType(managerCredentialType); // tx4601Request.setManagerCredentialNumber(managerCredentialNumber); // tx4601Request.setManagerIssDate(managerIssDate); // tx4601Request.setManagerExpiryDate(managerExpiryDate); // tx4601Request.setManagerContactNumber(managerContactNumber); // tx4601Request.setManagerEmail(managerEmail); // tx4601Request.setManagerCredentialAddress(managerCredentialAddress); // tx4601Request.setManagerOccupation(managerOccupation); // tx4601Request.setRetailerRegNumber(retailerRegNumber); // tx4601Request.setRetailerName(retailerName); // tx4601Request.setRetailerLicenseIssDate(retailerLicenseIssDate); // tx4601Request.setRetailerLicenseExpiryDate(retailerLicenseExpiryDate); // tx4601Request.setRetailerFormation(retailerFormation); // tx4601Request.setRetailerAddress(retailerAddress); // tx4601Request.setRetailerProvince(retailerProvince); // tx4601Request.setRetailerCity(retailerCity); // tx4601Request.setRetailerDistrict(retailerDistrict); // tx4601Request.setRetailerBusinessScope(retailerBusinessScope); // tx4601Request.setBankAbilityFlag(bankAbilityFlag); // tx4601Request.setBindingTxSN(bindingTxSN); // tx4601Request.setBankID(bankID); // tx4601Request.setBankAccountNumber(bankAccountNumber); // tx4601Request.setBankPhoneNumber(bankPhoneNumber); // tx4601Request.setCNAPSCode(cNAPSCode); // tx4601Request.setBranchName(branchName); // tx4601Request.setBankProvince(bankProvince); // tx4601Request.setBankCity(bankCity); // 3.执行报文处理 tx4601Request.process(); // 4.将参数放置到request对象 /* map.put("plainText", tx4601Request.getRequestPlainText()); map.put("message", tx4601Request.getRequestMessage()); map.put("signature", tx4601Request.getRequestSignature()); map.put("txCode", "4601"); map.put("txName", "开户");*/ HashMap map = new HashMap(); putCommonParam(map, tx4601Request); // 5.转向Request.jsp页面 return dealRequestResult(map, Tx4601Response.class); } /** * 用户信息查询 * * @return */ public static Tx4691Response tx4691(String userId) { Tx4691Request txRequest = new Tx4691Request(); txRequest.setInstitutionID(PaymentEnvironment.institutionID); txRequest.setUserID(userId); // 3.执行报文处理 try { txRequest.process(); } catch (Exception e) { e.printStackTrace(); return null; } return dealRequestResult(putCommonParam(null, txRequest), Tx4691Response.class); } public static Tx4691Response tx4691QueryUserInfo(Long businessId, char businessType) { return tx4691(getUserId(businessId, businessType)); } /** * 绑定银行卡,解绑银行卡 * * @param operationFlag 操作标识: 10=绑卡 20=解绑 30=升级 * @param bankAccountType 账户类型: 11=个人账户 12=企业账 户 * @param credentialNumber 身份证号 * @return */ public static Tx4611Response tx4611(short operationFlag, String userId, short bankAccountType, String credentialNumber , String bankAccountName, String bankAccountNumber, String bankPhoneNumber, String validDate, String cvn2) { // 查询 银行卡 //绑定银行 ID 参考《银行编码表》 String bankID = null; //卡类型 10借记账户 20贷记账户 String bankCardType = null; Tx2751Response tx2751Response = tx2751(bankAccountNumber); if (tx2751Response != null && "2000".equals(tx2751Response.getCode())) { bankCardType = tx2751Response.getCardMediaType(); bankID = tx2751Response.getBankID(); } Tx4611Request txRequest = new Tx4611Request(); txRequest.setInstitutionID(PaymentEnvironment.institutionID); txRequest.setOperationFlag(operationFlag + ""); txRequest.setBindingTxSN(IdGenerator.getUUID()); txRequest.setUserID(userId); txRequest.setBindingWay("10"); //账户类型: 11=个人账户 12=企业账 户 txRequest.setBankAccountType(bankAccountType + ""); txRequest.setBankCardType(bankCardType + ""); txRequest.setCredentialType("0"); txRequest.setCredentialNumber(credentialNumber); txRequest.setBankID(bankID); txRequest.setBankAccountName(bankAccountName); txRequest.setBankAccountNumber(bankAccountNumber); txRequest.setBankPhoneNumber(bankPhoneNumber); txRequest.setValidDate(validDate); txRequest.setCVN2(cvn2); // 3.执行报文处理 try { txRequest.process(); } catch (Exception e) { return null; } // 4.将参数放置到request对象 /*map.put("txCode", "4611"); map.put("txName", "绑卡&解绑(API)");*/ Tx4611Response tx4611Response = dealRequestResult(putCommonParam(null, txRequest), Tx4611Response.class); return tx4611Response; } public static Tx2751Response tx2751(String accountNumber) { // 2.创建交易请求对象 Tx2751Request txRequest = new Tx2751Request(); txRequest.setInstitutionID(PaymentEnvironment.institutionID); txRequest.setTxSN(IdGenerator.getUUID()); txRequest.setAccountNumber(accountNumber); // 3.执行报文处理 try { txRequest.process(); } catch (Exception e) { e.printStackTrace(); return null; } Tx2751Response tx4613Response = dealRequestResult(putCommonParam(null, txRequest), Tx2751Response.class); return tx4613Response; } /** * 绑卡确认 * * @param bindingTxSN tx4611返回值中 银行账户绑定流水号 * @param businessType 业务类型: 10=绑卡 20=开户 * @param verifyWay 验证方式:10 短信验证 20 小额打款验证 * @return */ public static Tx4613Response tx4613(String bindingTxSN, short businessType, short verifyWay, String smsCode, Long amount) { Tx4613Request txRequest = new Tx4613Request(); txRequest.setInstitutionID(PaymentEnvironment.institutionID); txRequest.setBusinessType(businessType + ""); txRequest.setVerifyWay(verifyWay + ""); txRequest.setSMSCode(smsCode); txRequest.setAmount(Convert.toStr(amount)); txRequest.setTxSN(bindingTxSN); // 3.执行报文处理 try { txRequest.process(); } catch (Exception e) { return null; } Tx4613Response tx4613Response = dealRequestResult(putCommonParam(null, txRequest), Tx4613Response.class); return tx4613Response; } /** * 支付API * * @param orderId 订单id * @param payerUserID 付款用户 ID * @param payeeUserID 收款用户 ID * @param paymentWay 支付方式: 00=余额支付 02=信用支付 10=快捷支付 12-钱包支付 20=网银支付 30=代收支付 40=聚合支付(停止接入新商户) * 42=条码支付 43-扫码预授权 50=O2O 60=POS(暂不支持) 70=信用支付 80-跳转支付 * @param amount 单位:分, * PaymentWay=42,ScanPaymentType =40 时,金额可为 0 * PaymentWay=42,InstallmentType=20,ScanPaymentType=20 时,Amount 必须大于等于 100 元 * PaymentWay=80,InstallmentType=20,PayType=32 时,Amount 必须大于等于 100 元 * @param pageURL 回调 URL 地址 * @param goodsName 商品名称 PaymentWay=02/12/40/42/80 必填 * @param platformName 平台名称 PaymentWay=80 必填 * @param clientIP 用户 IP PaymentWay=12,80 必填 * @param hasSubsequentSplit 是否有后续分账:1-否 2-是 默认为否 * @param hasSubsequentSplit 是否有后续分账:1-否 2-是 默认为否 * @param remark 备注 Payment=30 且是对公支付业务时,必传 * @param payWay 支付方式 45=H5支付(PayType=30、31、32、33) * 46=APP 支付(PayType=30、31、32、33) * 47=手机迷你付(PayType=33) * 48=手机 Pay (PayType=34、35) * 50=JSAPI(PayType=31、32) * 51=小程序支付(PayType=31、32) * @param payType 支付类型 30=手机网银 31=微信 32=支付宝 33=银联 34=Apple Pay 35=Android Pay * @param subAppID AppID(商户进件录入)微信必填PayType=31 支付宝选填(支付宝直连、支付宝小程序必填) * @param subOpenID 用户 ID 微信:openid 支付宝: buyer_user_id (PayWay=50/51 必填) * @param redirectSource 跳转前来源 10=App,20=H5, 30=公众号,40=小程序 * @param scanPaymentType 条码支付类型: 10=微信 20=支付宝 30=银联 40=聚合码 50=数字人民币支付 * @param scanPaymentWay 条码支付方式: 41=正扫 42=反扫 * @param scanPaymentCode 条反扫支付授权码 ScanPaymentWay=42 时必填 * @param scanPageUrlType 页面跳转方式 10=公众号 20=小程序 ScanPaymentType=10-微信扫码时此字段为必填项,默认为公众号。 * @param splitItemsList 分账结算域 * @return */ public static Tx5011Response tx5011(String orderId, String payerUserID, String payeeUserID, String paymentWay, Long amount, String pageURL , String goodsName, String platformName, String clientIP, Short hasSubsequentSplit, String remark, JSONObject extension , String agreeId, String payWay, String payType, String subAppID, String subOpenID, String redirectSource // 条码参数 , String scanPaymentType, String scanPaymentWay, String scanPaymentCode, String scanPageUrlType //分账结算参数 , ArrayList splitItemsList ) { Tx5011Request txRequest = new Tx5011Request(); txRequest.setInstitutionID(PaymentEnvironment.institutionID); txRequest.setTxSN(orderId); txRequest.setOrderNo(orderId); txRequest.setPayerUserID(payerUserID); txRequest.setPayeeUserID(payeeUserID); txRequest.setPaymentWay(paymentWay); txRequest.setAmount(Convert.toStr(amount, "0")); txRequest.setPageURL(pageURL); txRequest.setGoodsName(goodsName); txRequest.setPlatformName(platformName); txRequest.setClientIP(clientIP); txRequest.setHasSubsequentSplit(Convert.toStr(hasSubsequentSplit, "1")); txRequest.setRemark(remark); txRequest.setExtension(extension == null ? null : extension.toJSONString()); //10=快捷支付 if ("10".equals(paymentWay)) { txRequest.setBindingTxSN(agreeId); } else if ("80".equals(paymentWay)) { // 跳转支付 txRequest.setPayWay(payWay); txRequest.setPayType(payType); //支付方式限制:10=不限定 txRequest.setLimitPay("10"); txRequest.setSubAppID(subAppID); txRequest.setSubOpenID(subOpenID); //installmentType 分期控制标识 10-不指定分期 20-指定分期 PayType=32、33,PayWay=45-H5支付时必填 txRequest.setInstallmentType("10"); txRequest.setRedirectSource(redirectSource); } else if ("42".equals(paymentWay)) { //条码支付方式选择域 txRequest.setScanPaymentType(scanPaymentType); txRequest.setScanPaymentWay(scanPaymentWay); txRequest.setScanPaymentCode(scanPaymentCode); txRequest.setScanPageUrlType(scanPageUrlType); } txRequest.setSplitItemsList(splitItemsList); // 3.执行报文处理 try { txRequest.process(); } catch (Exception e) { e.printStackTrace(); } Tx5011Response tx5011Response = dealRequestResult(putCommonParam(null, txRequest), Tx5011Response.class); return tx5011Response; } /** * 微信h5 jsapi支付 * * @return */ public static Tx5011Response tx5011WxH5Pay(String orderId, String payerUserID, String payeeUserID, Long amount, String pageURL , String goodsName, String shopName, String clientIP, Short hasSubsequentSplit, String remark, JSONObject extension , String subAppID, String subOpenID, String redirectSource //分账结算参数 , ArrayList splitItemsList ) { return tx5011(orderId, payerUserID, payeeUserID, "80", amount, pageURL, goodsName, shopName, clientIP, hasSubsequentSplit, remark, extension , null, "50", "31", subAppID, subOpenID, redirectSource, null, null, null, null , splitItemsList); } /** * 微信小程序支付 * * @return */ public static Tx5011Response tx5011WxMiniPay(String orderId, String payerUserID, String payeeUserID, Long amount, String pageURL , String goodsName, String shopName, String clientIP, Short hasSubsequentSplit, String remark, JSONObject extension , String subAppID, String subOpenID, String redirectSource //分账结算参数 , ArrayList splitItemsList ) { return tx5011(orderId, payerUserID, payeeUserID, "80", amount, pageURL, goodsName, shopName, clientIP, hasSubsequentSplit, remark, extension , null, "51", "31", subAppID, subOpenID, redirectSource, null, null, null, null , splitItemsList); } /** * 银行卡快捷支付 * * @return */ public static Tx5011Response tx5011BankCardKjPay(String orderId, String payerUserID, String payeeUserID, Long amount, String pageURL , String goodsName, String shopName, String clientIP, Short hasSubsequentSplit, String remark, JSONObject extension , String agreeId //分账结算参数 , ArrayList splitItemsList) { return tx5011(orderId, payerUserID, payeeUserID, "10", amount, pageURL, goodsName, shopName, null, hasSubsequentSplit, remark, extension , agreeId, null, null, null, null, null, null, null, null, null , splitItemsList); } public static Tx1850Response tx1850(LocalDate billDate) throws Exception { // 1.取得参数 // String batchNO = request.getParameter("BatchNO"); // String payeeUserID = request.getParameter("PayeeUserID"); // 2.创建交易请求对象 Tx1850Request txRequest = new Tx1850Request(); txRequest.setInstitutionID(PaymentEnvironment.institutionID); // txRequest.setBatchNO(batchNO); txRequest.setBillDate(billDate.toString().replace("-", "")); // txRequest.setPayeeUserID(payeeUserID); // 3.执行报文处理 txRequest.process(); // 4.将参数放置到request对象 HashMap map = new HashMap(); /* map.put("plainText", txRequest.getRequestPlainText()); map.put("message", txRequest.getRequestMessage()); map.put("signature", txRequest.getRequestSignature()); map.put("txCode", "1850"); map.put("txName", "对账文件下载");*/ map.put("Flag", "50"); putCommonParam(map, txRequest); return dealRequestResult(map, Tx1850Response.class); } /** * 用于查询账户中可解冻的金额信息 * * @param businessId * @return */ public static Tx4660Response tx4660QueryDjBalance(Long businessId, char businessType) { return tx4660(getUserId(businessId, businessType)); } private static Tx4660Response tx4660(String userId) { Tx4660Request txRequest = new Tx4660Request(); txRequest.setInstitutionID(PaymentEnvironment.institutionID); txRequest.setUserID(userId); // 3.执行报文处理 try { txRequest.process(); } catch (Exception e) { e.printStackTrace(); return null; } return dealRequestResult(putCommonParam(null, txRequest), Tx4660Response.class); } /** * 业务ID 生成规则 * * @param businessId * @param businessType * @return */ public static String getUserId(Long businessId, char businessType) { return businessType + "" + businessId; } /** * 放入公共参数 * * @param map * @param baseRequest */ public static HashMap putCommonParam(HashMap map, TxBaseRequest baseRequest) { if (map == null) { map = new HashMap<>(); } map.put("plainText", baseRequest.getRequestPlainText()); map.put("message", baseRequest.getRequestMessage()); map.put("signature", baseRequest.getRequestSignature()); map.put("txCode", baseRequest.getTxCode()); map.put("isDgEnv", PaymentEnvironment.isDgEnv); map.put("dgtlEnvlp", baseRequest.getDgtlEnvlp()); map.put("signAlgorithm", baseRequest.getSignAlgorithm()); map.put("signSN", baseRequest.getSignSN()); map.put("encryptSN", baseRequest.getEncryptSN()); map.put("institutionID", PaymentEnvironment.institutionID); return map; } /** * 发送请求,解析请求 * * @param map * @return */ public static T dealRequestResult(HashMap map, Class responseType) { try { // 获得参数message和signature String message = map.get("message"); String signature = map.get("signature"); String txCode = map.get("txCode"); String flag = map.get("Flag"); // 与支付平台进行通讯 TxMessenger txMessenger = new TxMessenger(); String[] respMsg = null; // Flag=10:cmb, 20:paymentAccount RequestDgtEnvlp requestDgtEnvlp = new RequestDgtEnvlp(); if ("YES".equals(map.get("isDgEnv"))) { requestDgtEnvlp.setIsDgEnv(map.get("isDgEnv")); } else { requestDgtEnvlp.setIsDgEnv("NO"); } requestDgtEnvlp.setDgtlEnvlp(map.get("dgtlEnvlp")); requestDgtEnvlp.setSignAlgorithm(map.get("signAlgorithm")); requestDgtEnvlp.setSignSN(map.get("signSN")); requestDgtEnvlp.setEncryptSN(map.get("encryptSN")); requestDgtEnvlp.setInstitutionID(map.get("institutionID")); if ("50".equals(flag)) { respMsg = txMessenger.send(message, signature, requestDgtEnvlp, Gateway4FileEnvironment.GATEWAY4FILE_URL); } else if ("90".equals(flag)) { respMsg = txMessenger.send(message, signature, requestDgtEnvlp, AggregateEnvironment.aggregateTxURL);// 0:message; } else { respMsg = txMessenger.send(message, signature, requestDgtEnvlp);// 0:message; } String plainText; if ("YES".equals(respMsg[2])) { //如果响应是数字信封,对消息进行对称解密 try { log.info("开始对响应消息做对称解密。。。。。。"); if ("YES".equals(PaymentEnvironment.isDoubleCert)) { log.info("双证解密。。。。。。"); respMsg[0] = DigitalEnvelopeUtil.doubleDecryptResponse(respMsg[0], respMsg[3], respMsg[5], respMsg[6]); } else { respMsg[0] = DigitalEnvelopeUtil.decryptResponse(respMsg[0], respMsg[3], respMsg[5], respMsg[6]); } plainText = respMsg[0]; respMsg[0] = cpcn.institution.tools.util.Base64.encode(respMsg[0], "UTF-8"); respMsg[0] = respMsg[0] + "," + respMsg[5] + "," + respMsg[4] + "," + respMsg[2]; log.info("响应消息做对称解密完成。。。。。。"); log.info("响应消息报文:[" + plainText + "]"); } catch (Exception e) { System.out.println("异常内容:" + e); throw new Exception(e + "对称解密异常!"); } } else { // 1:signature plainText = new String(cpcn.institution.tools.util.Base64.decode(respMsg[0]), "UTF-8"); if (StringUtil.isNotEmpty(respMsg[5])) { respMsg[0] = respMsg[0] + "," + respMsg[5] + "," + respMsg[4] + "," + respMsg[2]; } } log.debug("[message]=[" + respMsg[0] + "]"); log.debug("[signature]=[" + respMsg[1] + "]"); log.debug("[plainText]=[" + plainText + "]"); // 将结果保存在request中,以备在Response.jsp页面显示 return getResponse(respMsg[0], respMsg[1], responseType); } catch (Exception e) { e.printStackTrace(); return null; } } /** * 反射创建返回值对象 * * @param responseMessage * @param responseSignature * @param responseType * @param * @return */ private static T getResponse(String responseMessage, String responseSignature, Class responseType) { // 创建并返回对应的子类对象 T response = null; try { Constructor constructor = responseType.getDeclaredConstructor(String.class, String.class); response = constructor.newInstance(responseMessage, responseSignature); } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { e.printStackTrace(); } return response; } //```````````````````````````````````````````````````````````` public static CommonResult testTx4611() { String userId = "cy88888888"; Tx4611Response tx4611Response = tx4611((short) 10, userId, (short) 11, "410105199603076114", "常远", "6255861234567897910", "17721229769", null, null); if ("2000".equals(tx4611Response.getCode())) { String status = tx4611Response.getStatus(); if ("40".equals(status)) { return new CommonResult(CommonResultEmnu.ERROR, tx4611Response.getResponseMessage()); } else { return new CommonResult(tx4611Response); } // if ("15".equals(status)) { // log.info("待短信验证,此状态时支付平台已经给用户手机号发送短信验证码,机构系统需要调用4613-绑卡确认接口回填短信验证码,支付平台验证后返回绑卡结果"); // } else if ("17".equals(status)) { // log.info("待被动打款验证,表示支付平台没有向企业账户进行打款,机构系统可通过 4616-绑卡查询接口查询企业账户绑卡状态"); // } else if ("18".equals(status)) { // log.info("被动已打款待验证,表示支付平台已向企业账户进行打款,机构系统可以调用 4613-绑卡确认接口回填打款金额,支付平台验证后返回绑卡结果。"); // } else if ("40".equals(status)) { // log.info("失败,表示用户提交的身份信息有误,需要核实后重新发起绑卡请求"); // } } else { return new CommonResult(CommonResultEmnu.ERROR, tx4611Response.getMessage()); } } /** * 绑卡测试 */ public static CommonResult testTx4613(String bindingTxSN) { Tx4613Response tx4613Response = tx4613(bindingTxSN, (short) 10, (short) 10, "134679", null); if (!"2000".equals(tx4613Response.getCode())) { return new CommonResult(CommonResultEmnu.ERROR, tx4613Response.getMessage()); } return new CommonResult(); } /** * 绑卡测试 */ public static CommonResult testTx2751() { Tx2751Response response = tx2751("6255861234567897910"); if (!"2000".equals(response.getCode())) { return new CommonResult(CommonResultEmnu.ERROR, response.getMessage()); } return new CommonResult(); } public static CommonResult test4660() { Tx4660Response response = tx4660("cy88888888"); if (!"2000".equals(response.getCode())) { return new CommonResult(CommonResultEmnu.ERROR, response.getMessage()); } return new CommonResult(); } public static void main(String[] args) { // 初始化支付环境 try { PaymentEnvironment.initialize("D:\\MyProjects\\jmy\\ecosphere\\ecosphere-merchant\\src\\main\\resources\\cncpConfig\\payment"); } catch (Exception e) { e.printStackTrace(); } String userId = "cy88888888"; tx4691(userId); } }