xuekang
2024-05-11 bac0878349a1db23e7b420ea164e22fb9db73a99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
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<ImageInfo> 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<String, String> map = new HashMap<String, String>();
        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<ShareholderPart> shareholderPartsList = null;
//        if(shareholderNames != null && shareholderNames.length > 0){
//            shareholderPartsList = new ArrayList<ShareholderPart>();
//            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<String, String> map = new HashMap<String, String>();
        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<SplitItem> 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<SplitItem> 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<SplitItem> 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<SplitItem> 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<String, String> map = new HashMap<String, String>();
       /* 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<String, String> putCommonParam(HashMap<String, String> 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 extends TxBaseResponse> T
    dealRequestResult(HashMap<String, String> map, Class<T> 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 <T>
     * @return
     */
    private static <T extends TxBaseResponse> T
    getResponse(String responseMessage, String responseSignature, Class<T> responseType) {
        // 创建并返回对应的子类对象
        T response = null;
        try {
            Constructor<T> 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<Tx4611Response> 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);
    }
 
}