shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
package com.walker.pay.allinpaycloud;
 
import com.allinpay.sdk.OpenClient;
import com.allinpay.sdk.bean.BizParameter;
import com.allinpay.sdk.bean.OpenConfig;
import com.allinpay.sdk.bean.OpenResponse;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.walker.infrastructure.utils.JsonUtils;
import com.walker.infrastructure.utils.KeyValue;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.pay.Order;
import com.walker.pay.ResponsePay;
import com.walker.pay.SplitAccount;
import com.walker.pay.allinpaycloud.pojo.BankCardInfo;
import com.walker.pay.allinpaycloud.pojo.MemberEnterprise;
import com.walker.pay.allinpaycloud.pojo.MemberPerson;
import com.walker.pay.allinpaycloud.pojo.RequestApplyBindBankCard;
import com.walker.pay.allinpaycloud.pojo.RequestBalance;
import com.walker.pay.allinpaycloud.pojo.RequestBindAcct;
import com.walker.pay.allinpaycloud.pojo.RequestBindBankCard;
import com.walker.pay.allinpaycloud.pojo.RequestBindPhone;
import com.walker.pay.allinpaycloud.pojo.RequestConfirmPay;
import com.walker.pay.allinpaycloud.pojo.RequestMember;
import com.walker.pay.allinpaycloud.pojo.RequestRealName;
import com.walker.pay.allinpaycloud.pojo.RequestSendVerifyCode;
import com.walker.pay.allinpaycloud.pojo.RequestSetCompany;
import com.walker.pay.allinpaycloud.pojo.RequestSignAcct;
import com.walker.pay.allinpaycloud.pojo.RequestSignContractQuery;
import com.walker.pay.allinpaycloud.pojo.RequestUnbindBankCard;
import com.walker.pay.allinpaycloud.pojo.RequestUploadGather;
import com.walker.pay.allinpaycloud.pojo.ResponseApplyBindBankCard;
import com.walker.pay.allinpaycloud.pojo.ResponseBalance;
import com.walker.pay.allinpaycloud.pojo.ResponseBindAcct;
import com.walker.pay.allinpaycloud.pojo.ResponseBindBankCard;
import com.walker.pay.allinpaycloud.pojo.ResponseBindPhone;
import com.walker.pay.allinpaycloud.pojo.ResponseCardBinInfo;
import com.walker.pay.allinpaycloud.pojo.ResponseConfirmPay;
import com.walker.pay.allinpaycloud.pojo.ResponseMember;
import com.walker.pay.allinpaycloud.pojo.ResponseMemberInfo;
import com.walker.pay.allinpaycloud.pojo.ResponseRealName;
import com.walker.pay.allinpaycloud.pojo.ResponseSetCompany;
import com.walker.pay.allinpaycloud.pojo.ResponseUnBindPhone;
import com.walker.pay.allinpaycloud.pojo.ResponseUnbindBankCard;
import com.walker.pay.allinpaycloud.pojo.ResponseUploadGather;
import com.walker.pay.allinpaycloud.pojo.ResponseWithdraw;
import com.walker.pay.allinpaycloud.util.MemberUtils;
import com.walker.pay.allinpaycloud.util.OrderUtils;
import com.walker.pay.response.OrderStatusResponsePay;
import com.walker.pay.support.BankCardOrder;
import com.walker.pay.support.allinpaycloud.AlipayServiceOrder;
import com.walker.pay.support.allinpaycloud.CouponOrder;
import com.walker.pay.support.allinpaycloud.ScanWechatOrder;
import com.walker.pay.support.allinpaycloud.WechatJsOrder;
import com.walker.pay.support.allinpaycloud.WechatMiniProgramOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
/**
 * 通商云 SDK 封装。
 * @author 时克英
 * @date 2023-02-17
 */
public class SdkClient {
 
    private final transient Logger logger = LoggerFactory.getLogger(getClass());
 
    private OpenConfig openConfig = null;
 
    private OpenClient openClient = null;
 
    public SdkClient(OpenConfig openConfig){
        if(openConfig == null){
            throw new IllegalArgumentException("OpenConfig 必须提供!");
        }
        this.openConfig = openConfig;
        this.createOpenClient();
    }
 
    public OpenClient getOpenClient() {
        return openClient;
    }
 
    /**
     * 验证签名
     * @param signedValue 请求原始内容
     * @param sign 签名字段内容
     * @return
     */
    public boolean checkSign(String signedValue, String sign){
        return this.openClient.checkSign(signedValue, sign);
    }
 
    /**
     * 消费订单(预下单)
     * @param order
     * @return
     * @date 2023-02-21
     */
    public OpenResponse consumeApply(Order order){
        BizParameter param = new BizParameter();
        param.put("payerId", order.getBuyerId());
        param.put("recieverId", order.getReceiverId());
//        param.put("bizOrderNo", String.valueOf(order.getId()));
        param.put("bizOrderNo", order.getIdString());
        param.put("amount", order.getTotalMoney());
        param.put("fee", order.getFee());
 
        // 0 无验证,1 短信验证,2 支付密码
//        param.put("validationType", 0L);
        param.put("validateType", 0L);
 
        // *** split rule
        // 2023-04-03 消费分账添加。
        List<SplitAccount> splitAccountList = order.getSplitAccountList();
        if(!StringUtils.isEmptyList(splitAccountList)){
            Object splitAccountJsonArray = OrderUtils.acquireSplitAccountParam(splitAccountList);
            if(this.logger.isDebugEnabled()){
                this.logger.debug(splitAccountJsonArray.toString());
            }
            param.put("splitRule", splitAccountJsonArray);
        }
 
        param.put("backUrl", order.getNotifyUrl());
        param.put("orderExpireDatetime", OrderUtils.getOrderExpireDateTime());
        param.put("goodsName", order.getTitle());
 
        //
        param.put("industryCode", this.industryInfo.getKey());
        param.put("industryName", this.industryInfo.getValue());
        param.put("source", 1L); // 1 Mobile, 2 PC
        param.put("extendInfo", order.getAttach());
 
        HashMap<String, Object> payMethod = null;
 
        if(order instanceof BankCardOrder){
            // 银行卡(快捷支付)订单
            BankCardOrder bankCardOrder = (BankCardOrder)order;
            payMethod = OrderUtils.getBankCardPayMethod(this.openClient.encrypt(bankCardOrder.getBankCardNo()), order.getTotalMoney());
 
        } else if(order instanceof WechatMiniProgramOrder){
            // 微信小程序订单,注意:这里必须放在'WechatJsOrder'前面,否则放下面会因为类型找不到小程序支付
            // 2023-03-13
            WechatMiniProgramOrder wechatJsOrder = (WechatMiniProgramOrder) order;
            payMethod = OrderUtils.getWechatJsPayMethod(wechatJsOrder.getAcct(), wechatJsOrder.getTotalMoney()
                    , wechatJsOrder.getLimitPay(), wechatJsOrder.getIdNo(), wechatJsOrder.getName(), wechatJsOrder.getSubAppid(), true);
 
        } else if(order instanceof WechatJsOrder){
            WechatJsOrder wechatJsOrder = (WechatJsOrder) order;
            payMethod = OrderUtils.getWechatJsPayMethod(wechatJsOrder.getAcct(), wechatJsOrder.getTotalMoney()
                    , wechatJsOrder.getLimitPay(), wechatJsOrder.getIdNo(), wechatJsOrder.getName(), wechatJsOrder.getSubAppid(), false);
 
        } else if(order instanceof AlipayServiceOrder){
            AlipayServiceOrder alipayServiceOrder = (AlipayServiceOrder) order;
            payMethod = OrderUtils.getAlipayJsPayMethod(alipayServiceOrder.getAcct(), alipayServiceOrder.getTotalMoney()
                    , alipayServiceOrder.getLimitPay(), alipayServiceOrder.getIdNo(), alipayServiceOrder.getName());
 
        } else if(order instanceof CouponOrder){
            CouponOrder couponOrder = (CouponOrder) order;
            payMethod = OrderUtils.getCouponPayMethod(couponOrder.getAccountSetNo(), couponOrder.getTotalMoney());
 
        } else if(order instanceof ScanWechatOrder){
            ScanWechatOrder scanWechatOrder = (ScanWechatOrder) order;
            payMethod = OrderUtils.getScanWechatPayMethod(scanWechatOrder);
 
        } else {
            // 默认订单类型
            throw new UnsupportedOperationException("未实现代码!");
        }
 
        param.put("payMethod", payMethod);
        return this.openClient.execute(Constants.METHOD_CONSUME_APPLY, param);
    }
 
    /**
     * 返回提现签约请求URL(包括参数)
     * @param requestSignAcct
     * @return
     * @date 2023-02-27
     */
    public String getSignAcctProtocolParams(RequestSignAcct requestSignAcct){
        final BizParameter param = new BizParameter();
        param.put("bizUserId", requestSignAcct.getBizUserId());
        param.put("signAcctName", requestSignAcct.getSignAcctName());
        param.put("jumpUrl", requestSignAcct.getJumpUrl());
        param.put("backUrl", requestSignAcct.getBackUrl());
        param.put("jumpPageType", requestSignAcct.getJumpPageType());
        param.put("source", requestSignAcct.getSource());
        return this.openClient.concatUrlParams(Constants.METHOD_MEMBER_SIGN_ACCT_PROTOCOL, param);
    }
 
    /**
     * 查询账户余额。
     * @param requestBalance
     * @return
     */
    public ResponseBalance queryBalance(RequestBalance requestBalance){
        final BizParameter param = new BizParameter();
        param.put("bizUserId", requestBalance.getBizUserId());
        param.put("accountSetNo", requestBalance.getAccountSetNo());
        final OpenResponse response = this.openClient.execute(Constants.METHOD_ORDER_QUERY_BALANCE, param);
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("'查询余额'错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'查询余额'错误,msg = {}", error);
            return ResponsePay.error(ResponseBalance.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseBalance.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'查询余额'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 查询订单状态,返回状态结果。
     * @param bizOrderNo
     * @return
     * @date 2023-02-23
     */
    public OrderStatusResponsePay searchOrderStatus(String bizOrderNo){
        final BizParameter param = new BizParameter();
        param.put("bizOrderNo", bizOrderNo);
        final OpenResponse response = this.openClient.execute(Constants.METHOD_ORDER_GET_STATUS, param);
        OrderStatusResponsePay orderStatusResponsePay = new OrderStatusResponsePay();
 
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
            String msg = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("查询订单状态错误,msg = {}", msg);
            orderStatusResponsePay.setStatus(false);
            orderStatusResponsePay.setMessage(msg);
            return orderStatusResponsePay;
        }
        try {
            ObjectNode info = JsonUtils.jsonStringToObjectNode(response.getData());
            return OrderUtils.obtainOrderStatusResponsePay(info, orderStatusResponsePay);
        } catch (Exception e) {
            throw new RuntimeException("转换'查询订单状态'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 提现申请(到银行卡)
     * @param order
     * @return
     * @date 2023-02-23
     */
    public ResponseWithdraw withdrawApply(WithdrawOrder order){
        final BizParameter param = new BizParameter();
        param.put("bizUserId", order.getBuyerId());
//        param.put("bizOrderNo", String.valueOf(order.getId()));
        param.put("bizOrderNo", order.getIdString());
        param.put("accountSetNo", order.getAccountSetNo());
        param.put("amount", order.getTotalMoney());
        param.put("fee", order.getFee());
        param.put("validateType", 0L);
        param.put("backUrl", order.getNotifyUrl());
        param.put("orderExpireDatetime", OrderUtils.getOrderExpireDateTime());
        param.put("bankCardNo", this.openClient.encrypt(order.getBankCardNo()));
        param.put("bankCardPro", order.getBankCardPro());
        param.put("withdrawType", order.getWithdrawType());
        param.put("industryCode", this.industryInfo.getKey());
        param.put("industryName", this.industryInfo.getValue());
        param.put("source", 1L);
//        param.put("summary", "withdraw");
        param.put("extendInfo", order.getAttach());
        OpenResponse response = this.openClient.execute(Constants.METHOD_ORDER_WITHDRAW_APPLY, param);
        if(response == null){
            throw new RuntimeException("调用'通商云'提现申请返回空数据, orderId = " + order.getId());
        }
        if (!Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("'提现申请'调用返回错误: " + response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'提现申请'错误,msg = {}", error);
            return ResponsePay.error(ResponseWithdraw.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseWithdraw.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'提现申请'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 获取carBin信息。
     * @param cardNo 银行卡号
     * @return
     * @date 2023-02-23
     */
    public ResponseCardBinInfo getCardBinInfo(String cardNo){
        final BizParameter param = new BizParameter();
        param.put("cardNo", this.openClient.encrypt(cardNo));
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_GET_CARD_BIN_INFO, param);
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("carBin查询错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'carBin查询'错误,msg = {}", error);
            return ResponsePay.error(ResponseCardBinInfo.class, error);
        }
        try {
            ObjectNode info = JsonUtils.jsonStringToObjectNode(response.getData());
            String cardBinInfo = info.get("cardBinInfo").toString();
            return JsonUtils.jsonStringToObject(cardBinInfo, ResponseCardBinInfo.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'carBin查询'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 获取会员信息。
     * @param bizUserId
     * @return
     */
    public ResponseMemberInfo getMemberInfo(String bizUserId){
        final BizParameter param = new BizParameter();
        param.put("bizUserId", bizUserId);
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_GET_INFO, param);
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("'查询会员'错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'查询会员'错误,msg = {}", error);
            return ResponsePay.error(ResponseMemberInfo.class, error);
        }
        try {
            ObjectNode info = JsonUtils.jsonStringToObjectNode(response.getData());
            ResponseMemberInfo responseMemberInfo = new ResponseMemberInfo();
 
            String memberInfo = info.get("memberInfo").toString();
            System.out.println(memberInfo);
 
            // 判断是个人或企业会员
            if(info.get("memberType").asLong() == 3){
                MemberPerson memberPerson = ResponseMemberInfo.toMemberPerson(memberInfo);
                responseMemberInfo.setMemberPerson(memberPerson);
            } else {
                MemberEnterprise memberEnterprise = ResponseMemberInfo.toMemberEnterprise(memberInfo);
                responseMemberInfo.setMemberEnterprise(memberEnterprise);
            }
//            return JsonUtils.jsonStringToObject(response.getData(), ResponseMemberInfo.class);
            return responseMemberInfo;
 
        } catch (Exception e) {
            throw new RuntimeException("转换'查询会员'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 签约查询。<p></p>
     * @param request
     * @return
     */
//    public ResponseSignContractQuery signContractQuery(RequestSignContractQuery request) throws SdkException{
//        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_SIGN_CONTRACT_QUERY, MemberUtils.acquireSignContractQuery(request));
//        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
//            logger.error("签约查询错误,msg = {}", error);
//            throw new SdkException(error, "签约查询错误", null);
//        }
//        try {
//            return JsonUtils.jsonStringToObject(response.getData(), ResponseSignContractQuery.class);
//        } catch (Exception e) {
//            throw new RuntimeException("转换'签约查询'json错误:" + e.getMessage(), e);
//        }
//    }
    public String signContractQuery(RequestSignContractQuery request) throws SdkException{
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_SIGN_CONTRACT_QUERY, MemberUtils.acquireSignContractQuery(request));
        if (response == null) {
//            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
//            logger.error("签约查询错误,msg = {}", error);
            throw new SdkException("", "签约查询错误", null);
        }
        if(response.getCode().equals(Constants.CODE_OK)){
            return response.getData();
        } else {
            logger.error(response.getMsg());
            return null;
        }
    }
 
    /**
     * 支付确认(短信验证码),该方法在测试使用。<br>
     * 正式环境会申请开通'无验证支付'方式。
     * @param request
     * @return
     * @date 2023-02-22
     */
    public ResponseConfirmPay confirmPay(RequestConfirmPay request){
        final OpenResponse response = this.openClient.execute(Constants.METHOD_ORDER_CONFIRM_PAY, MemberUtils.acquireConfirmPay(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("支付确认(短信验证)错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'支付确认(短信验证)'错误,msg = {}", error);
            return ResponsePay.error(ResponseConfirmPay.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseConfirmPay.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'支付确认(短信验证)'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 上传影音采集信息。<p></p>
     * <pre>
     *     1-营业执照(必传)
     * 2-组织机构代码证(三证时必传)
     * 3-税务登记证(三证时必传)
     * 4-银行开户证明(非必传,上传《银行开户许可证》或《基本存款账户信息》等可证明平台银行账号和户名的文件)
     * 5-机构信用代码(非必传)
     * 6-ICP备案许可(非必传)
     * 7-行业许可证(非必传)
     * 8-身份证正面(人像面)(必传)
     * 9-身份证反面(国徽面)(必传)
     * </pre>
     * @param request
     * @return
     */
    public ResponseUploadGather uploadGather(RequestUploadGather request){
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_IDCARD_COLLECT, MemberUtils.acquireUploadGather(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("影音采集错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'影音采集'错误,msg = {}", error);
            return ResponsePay.error(ResponseUploadGather.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseUploadGather.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'影音采集'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 设置企业信息。
     * @param request
     * @return
     */
    public ResponseSetCompany setCompany(RequestSetCompany request){
        request.setLegalIds(this.openClient.encrypt(request.getLegalIds()));
        request.setAccountNo(this.openClient.encrypt(request.getAccountNo()));
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_SET_COMPANY, MemberUtils.acquireSetCompany(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("设置企业错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'设置企业'错误,msg = {}", error);
            return ResponsePay.error(ResponseSetCompany.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseSetCompany.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'设置企业'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 绑定手机确认
     * @param request
     * @return
     */
    public ResponseBindPhone bindPhone(RequestBindPhone request){
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_BIND_PHONE, MemberUtils.acquireBindPhone(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("绑定手机错误,msg = {}", error);
            return ResponsePay.error(ResponseBindPhone.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseBindPhone.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'绑定手机'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 解绑手机号(确认),之前必须先调用发送验证码。
     * @param request
     * @return
     * @date 2023-02-27
     */
    public ResponseUnBindPhone unbindPhone(RequestBindPhone request){
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_UNBIND_PHONE, MemberUtils.acquireBindPhone(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'解绑手机'错误,msg = {}", error);
            return ResponsePay.error(ResponseUnBindPhone.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseUnBindPhone.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'解绑手机'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 绑定手机(发送验证码)
     * @param request
     * @return
     */
    public ResponseBindPhone sendVerifyCode(RequestSendVerifyCode request){
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_SEND_VERIFY_CODE, MemberUtils.acquireSendVerifyCode(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("绑定手机(发送验证码)错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'绑定手机(发送验证码)'错误,msg = {}", error);
            return ResponsePay.error(ResponseBindPhone.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseBindPhone.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'绑定手机(发送验证码)'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 解除绑定银行卡
     * @param request
     * @return
     */
    public ResponseUnbindBankCard unbindBankCard(RequestUnbindBankCard request){
        request.setCardNo(this.openClient.encrypt(request.getCardNo()));
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_UNBIND_BANKCARD, MemberUtils.acquireUnbindBankCard(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("解除绑定银行卡错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'解除绑定银行卡'错误,msg = {}", error);
            return ResponsePay.error(ResponseUnbindBankCard.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseUnbindBankCard.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'解除绑定银行卡'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 查询个人绑卡列表
     * @param bizUserId 业务用户ID
     * @param cardNo 卡号,如果不提供则返回所有卡集合。
     * @return
     * @date 2023-02-23
     */
    public List<BankCardInfo> getBindCardList(String bizUserId, String cardNo) throws SdkException{
        final BizParameter param = new BizParameter();
        param.put("bizUserId", bizUserId);
        if(StringUtils.isNotEmpty(cardNo)){
            param.put("cardNo", this.openClient.encrypt(cardNo));
        }
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_GET_CARD_BIND, param);
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
            logger.error("'查询绑卡'错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            throw new SdkException(response.getSubMsg(), "查询绑卡调用sdk错误", null);
        }
        try {
            ObjectNode info = JsonUtils.jsonStringToObjectNode(response.getData());
            String cardListInfo = info.get("bindCardList").toString();
            ArrayNode arrayNode = JsonUtils.toJsonArray(cardListInfo);
            if(arrayNode == null || arrayNode.size() <= 0){
                return null;
            }
            List<BankCardInfo> bankCardInfos = new ArrayList<>(4);
            String one = null;
            BankCardInfo bankCardInfo = null;
            for(int i=0; i<arrayNode.size(); i++){
                one = arrayNode.get(i).toString();
                bankCardInfo = JsonUtils.jsonStringToObject(one, BankCardInfo.class);
                bankCardInfo.setBankCardNo(this.openClient.decrypt(bankCardInfo.getBankCardNo()));
                bankCardInfos.add(bankCardInfo);
            }
            return bankCardInfos;
        } catch (Exception e) {
            throw new RuntimeException("转换'查询绑卡'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 确认绑定银行卡
     * @param request
     * @return
     */
    public ResponseBindBankCard bindBankCard(RequestBindBankCard request){
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_BIND_BANKCARD, MemberUtils.acquireBindBankCard(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'确认绑定银行卡'错误,msg = {}", error);
            return ResponsePay.error(ResponseBindBankCard.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseBindBankCard.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'绑定银行卡'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 请求绑定银行卡。
     * @param request
     * @return
     */
    public ResponseApplyBindBankCard applyBindBankCard(RequestApplyBindBankCard request){
        request.setCardNo(this.openClient.encrypt(request.getCardNo()));
        request.setIdentityNo(this.openClient.encrypt(request.getIdentityNo()));
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_APPLY_BIND_BANKCARD, MemberUtils.acquireApplyBindBankCard(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("绑定银行卡错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'绑定银行卡'错误,msg = {}", error);
            return ResponsePay.error(ResponseApplyBindBankCard.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseApplyBindBankCard.class);
        } catch (Exception e) {
            throw new RuntimeException("转换'绑定银行卡'json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 会员绑定支付账户用户标识
     * @param request
     * @return
     */
    public ResponseBindAcct bindAcct(RequestBindAcct request){
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_APPLY_BIND_ACCT, MemberUtils.acquireBindAcct(request));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
//            logger.error("绑定支付标识错误,msg = {}", response == null? StringUtils.EMPTY_STRING : response.getSubMsg());
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("'绑定支付标识'会员实名认证''错误,msg = {}", error);
            return ResponsePay.error(ResponseBindAcct.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseBindAcct.class);
        } catch (Exception e) {
            throw new RuntimeException("转换绑定支付标识json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 实名认证。
     * @param requestRealName
     * @return
     */
    public ResponseRealName setRealName(RequestRealName requestRealName){
        String cardNo = requestRealName.getIdentityNo();
        if(StringUtils.isEmpty(cardNo)){
            throw new IllegalArgumentException("身份证号不能空!");
        }
        requestRealName.setIdentityNo(this.openClient.encrypt(cardNo));
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_SET_REAL_NAME, MemberUtils.acquireRealName(requestRealName));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("会员实名认证错误,msg = {}", error);
            return ResponsePay.error(ResponseRealName.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseRealName.class);
        } catch (Exception e) {
            throw new RuntimeException("转换实名认证json错误:" + e.getMessage(), e);
        }
    }
 
    /**
     * 创建会员
     * @param requestMember
     * @return
     */
    public ResponseMember createMember(RequestMember requestMember){
        if(StringUtils.isEmpty(requestMember.getBizUserId())){
            throw new IllegalArgumentException("bizUserId 必须设置!");
        }
        final OpenResponse response = this.openClient.execute(Constants.METHOD_MEMBER_CREATE, MemberUtils.acquireCreateMember(requestMember));
        if (response == null || !Constants.SUB_CODE_OK.equals(response.getSubCode())) {
            String error = response == null? StringUtils.EMPTY_STRING : response.getSubMsg();
            logger.error("创建会员错误,msg = {}", error);
            return ResponsePay.error(ResponseMember.class, error);
        }
        try {
            return JsonUtils.jsonStringToObject(response.getData(), ResponseMember.class);
        } catch (Exception e) {
            throw new RuntimeException("转换会员json错误:" + e.getMessage(), e);
        }
    }
 
    private void createOpenClient(){
        if(this.openClient != null){
            logger.warn("OpenClient 已经存在,无需重复创建!");
            return;
        }
        try{
            this.openClient = new OpenClient(openConfig);
            logger.debug("创建 'OpenClient' 一次.");
        } catch (Exception ex){
            logger.error("创建 'OpenClient' 错误:" + ex.getMessage(), ex);
        }
    }
 
    /**
     * 设置在'通商云'平台设置的行业类型。
     * @param industryInfo
     */
    public void setIndustryInfo(KeyValue<String, String> industryInfo) {
        this.industryInfo = industryInfo;
    }
 
    private KeyValue<String, String> industryInfo = new KeyValue<>("2422", "其他");
}