xiaoyong931011
2021-11-10 fc1773400e95b39a7acd97074dd41a3fe9c302d4
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
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
package com.xzx.gc.pay.service;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayOpenOperationOpenbizmockBizQueryModel;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayOpenOperationOpenbizmockBizQueryRequest;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayOpenOperationOpenbizmockBizQueryResponse;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.constant.*;
import com.xzx.gc.common.dto.CommonDto;
import com.xzx.gc.common.dto.SimplePage;
import com.xzx.gc.common.dto.log.PayInfoLog;
import com.xzx.gc.common.exception.BusinessException;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.common.exception.wx.WxPayNotifyResponseException;
import com.xzx.gc.common.utils.*;
import com.xzx.gc.entity.*;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.model.admin.*;
import com.xzx.gc.model.pay.*;
import com.xzx.gc.model.user.AccountVo;
import com.xzx.gc.pay.mapper.*;
import com.xzx.gc.util.DoubleUtil;
import com.xzx.gc.util.SessionUtil;
import com.xzx.gc.util.pay.util.WechatpayUtil;
import com.xzx.gc.util.pay.util.entity.ResultEntity;
import com.xzx.gc.util.pay.util.entity.TransfersDtoAdmin;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
 
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
 
 
@Service
@Transactional
@Slf4j
public class PayService {
 
    @Autowired
    private PayInfoMapper payInfoMapper;
 
    @Autowired
    private AccountLogMapper accountLogMapper;
 
    @Autowired
    private SysMessageMapper sysMessageMapper;
 
    @Autowired
    private IdUtils idUtils;
 
    @Autowired
    private HttpServletRequest request;
 
    @Autowired
    private OtherUserMapper otherUserMapper;
 
    @Autowired
    private UserMapper userMapper;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private PayRequestMapper payRequestMapper;
 
    @Autowired
    private PlatformAccountInfoMapper platformAccountInfoMapper;
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Autowired
    private BusinessUtil businessUtil;
 
    @Autowired
    private AccountMapper accountMapper;
 
    @Autowired
    private PayInfoLogService payInfoLogService;
 
    @Autowired
    private AccountService accountService;
 
    @Autowired
    private OtherUserService otherUserService;
 
    @Autowired
    private PlatformAccountLogService platformAccountLogService;
 
    @Autowired
    private PlatformAccountInfoService platformAccountInfoService;
 
    @Autowired
    private ConfigService configService;
 
    @Autowired
    private ConfigMapper configMapper;
 
    @Autowired
    private AccountBindService accountBindService;
 
    @Autowired
    private SessionUtil sessionUtil;
    @Autowired
    private UserRoleMapper userRoleMapper;
 
    @Autowired
    private PlatformAccountLogMapper platformAccountLogMapper;
 
    @Autowired
    private AccountScoreLogMapper accountScoreLogMapper;
 
    @Autowired
    private CityPartnerService cityPartnerService;
 
 
    @Value("${anroidAppId}")
    private String anroidAppId;
    @Value("${wx.app.url}")
    String TRANS_URL;
    @Value("${wx.app.key}")
    String APP_KEY;
    @Value("${wx.path}")
    String CERT_PATH;
    @Value("${wx.pay.appid}")
    String APP_ID;
    @Value("${wx.mchid}")
    String MCH_ID;
    @Value("${wx.name}")
    String MCH_NAME;
    @Value("${wx.create.ip}")
    String CREATE_IP;
 
    @Autowired
    private PartnerAccountLogService partnerAccountLogService;
    @Autowired
    private PartnerAccountService partnerAccountService;
 
    private static CertAlipayRequest getClientParams() {
        CertAlipayRequest certParams = new CertAlipayRequest();
        //https://blog.csdn.net/sinat_32575213/article/details/79651110
        certParams.setServerUrl("https://openapi.alipaydev.com/gateway.do");
        //请更换为您的AppId
        certParams.setAppId("2021000119674887");
        //请更换为您的PKCS8格式的应用私钥
        certParams.setPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCDXABjX661uzuAbwEOa2YV9S3Xm409k27LRkJsBHRyhHuq4+MK5OnFMpNmYl+e2rIvQ9y+1YI65NovPV4XTAt6tr2wIE2uD8dLJELHxwZyUpLSgdLW4Ds6qoea8qoZk3563baO2i0EnuSk9evBpzzJtO0+QDiNGASrE+7mPL9ygCv8V4i185h/LpinKTymnIhyTtEmjEAXITPM/e2PvWTE+RCz07kkXIEquVtcj/5geRPqXaogsbaMgwy3oKiZLRw8Axo8OhO9zDTnfFeO7pwPvWTAMFYKZu7jbOTMa4vT0DQYqDIDmNzCbTCfkfE3VQrmI4KTacprTz46fNC5UXq9AgMBAAECggEAdtaS21RC4NJkgErsb7kmABNxx69IVj69a1VC3iohl0DYCMBmNQLnoqmgxG2XCEXeEfiZCmRqjxFfeoFQUE9Ry1Drxx1SaXiI2igR6l7aLC8b+SnOLutpaifAyqNi1ASl1k4izJYBSD7fp4V8JhRAYFM4lqrO/oaOIp/D77NhmBmfV5XIzZOzeLkHaLN8pTqUdvTF917MkmUsY1iysol+EmU/pZePkcwIcHoQcJ9yWam8bRErXAqoKSvMcXetpsaIN6Fgn/sMkk/coJW2rSWNxUQVn+RTvKwT9UGehah/jwqzNwg/FhiKu28PDLccQzbK/VkZ2sTla3w/AlKnmn91QQKBgQDcHdwyjI25tRMayjneZc5VOKA65Du1RubiXdJU+14288qDNHmR4CMxIe49gHPknWwkiLNa0VnhnINJSsEXtvpcPY1ICL9TnHGBCYFpA+4Wc6gYa6CqUeg41O5ki0b+Ar3xp3hVOqeBnHdyKwv1/UvHWeFYPXwqg5MFu3iA1mLnNQKBgQCYxgeecZshL6iwww8kHaCxNf92l4s89YIpiTFsv70SAt+h7OxN9wzJcF2dQbUIEB0Q26KWeomzd4rZRr0CqcpMj/HRQzk0W8fGGEKGAZwjf33aa1VSehY8ZMYBCgJcVk7CRl/XQ+51ppqr80HwGBgSqV5P3b6T1vmiZlRP1GTOaQKBgQCiAwRo3FUQY/u80y3GyK4WwcgFsKlV4urboGzIif+teMEM01nLieq9JhlBgUNL+KZ5OXixlreOPHHRR0laWB5sOA2+AFo6g0Jz1HhAwFjEg7osx0MJOaIv+mHA9VZ6bbA6pqYGLVbPKkgsawyxsQ7OmxQmq5KxhAh5xqOKSMGhJQKBgGFpg9onnj7e4LU06yagLaJRR/8aShIoiUJq1DT/XVNquaXKKDLeYCzhlQ98oi3t+FqTcWx53eutQb+hN0vHb9K5xfsk3gjgrNVHCsPfquuHk3v+DH12k08XApoPA8pUzgtaTCo6ioZCIUWa6mRpOJBNpnFOdwJVhP9kOEZeq5hhAoGAMKztAVJCzjiJr7Htd8pUc/hjLXUznUfbNfigNtNXAKL7QWHmrz5NIDuFKY2gn08ahAoZG/P34N2DrrhEOrBlT249FEFEo7HH1EvFbEN1QosCZFhXTWkcgSxcmj9TRu4uLVppW+6hMxVbR2ZY4MGmCQPJEu91JnQzYqyZAt6SGYw=");
        //请更换为您使用的字符集编码,推荐采用utf-8
        certParams.setCharset("utf-8");
        certParams.setFormat("json");
        certParams.setSignType("RSA2");
        //请更换为您的应用公钥证书文件路径
        certParams.setCertPath("E:/card/appCertPublicKey_2021000119674887.crt");
        //请更换您的支付宝公钥证书文件路径
        certParams.setAlipayPublicCertPath("E:/card/alipayCertPublicKey_RSA2.crt");
        //更换为支付宝根证书文件路径
        certParams.setRootCertPath("E:/card/alipayRootCert.crt");
        return certParams;
    }
 
 
    private AlipayClient alipayClient;
 
    @PostConstruct
    public void init() throws AlipayApiException {
        // 1. 创建AlipayClient实例
        if (SpringUtil.isDev()) {
            alipayClient = new DefaultAlipayClient(getClientParams());
        }
 
    }
 
    public int addPayInfo(PayInfoModel model) {
        CoreUser user = sessionUtil.getCurrentUser();
        model.setAccountId("");
        model.setStatus("1");
        model.setPayType("1");
        model.setCreateUserId(user.getId() + "");
        model.setCreateTime(DateUtil.now());
        return payInfoMapper.addPayInfo(model);
    }
 
    public CommonDto PayInfoAdd(PayInfoReq payInfoReq) {
 
        String lockId = "";
        if (StrUtil.isNotBlank(payInfoReq.getCreateUserId())) {
            lockId = payInfoReq.getCreateUserId();
        } else if (StrUtil.isNotBlank(payInfoReq.getUserId())) {
            lockId = payInfoReq.getUserId();
        }
        CommonDto commonDto = new CommonDto();
        if (StrUtil.isNotBlank(lockId) && redisUtil.setnx(Constants.REDIS_PAY_KEY + "add:" + lockId, lockId)) {
            try {
                String payOrderId = idUtils.generate("ZF", 0);
                payInfoReq.setPayOrderId(payOrderId);
                String now = DateUtil.now();
                payInfoReq.setCreateTime(now);
                //充值或者支入则不需要写入支付申请表
                if (PayEnum.提现.getValue().equals(payInfoReq.getPayType())) {
 
 
                    String configValue = configService.findByCode("WITHDRAW_MAX_MONEY").getConfigValue();
 
                    if (Convert.toBigDecimal(payInfoReq.getMoney()).compareTo(Convert.toBigDecimal(configValue)) > 0) {
                        throw new RestException(-1, "单笔提现金额不能超过" + configValue);
                    }
 
                    //查询账号是否被冻结
                    AccountInfo byUserIdWithStatus = accountService.findByUserId(payInfoReq.getCreateUserId());
                    if (byUserIdWithStatus == null) {
                        throw new RestException(-1, "账户已被禁用");
                    }
 
 
                    List<PayInfoVo> withdrawList = payInfoMapper.queryWithdrawInfo(payInfoReq);
                    if (withdrawList.size() >= 1) {
 
                        throw new RestException(-1, "一天只能提现一次");
                    }
                    List<AccountVo> accountList = payInfoMapper.queryMyMoney(payInfoReq);
                    AccountVo accountVo = accountList.get(0);
 
                    //提现金额
                    BigDecimal bigDecimal = NumberUtil.toBigDecimal(payInfoReq.getMoney());
                    //余额
                    BigDecimal bigDecimal1 = NumberUtil.toBigDecimal(accountVo.getMoney());
 
                    //判断账户余额是否足够,返回-1表示余额不够
 
                    if (NumberUtil.isGreater(bigDecimal, bigDecimal1)) {
                        throw new RestException(-1, "用户余额不足");
                    }
 
                    //查询账户信息  安卓回收员提现转成普通用户
                    if (1 == Convert.toInt(payInfoReq.getChangeUserFlag(), 0)) {
                        String createUserId = payInfoReq.getCreateUserId();
                        OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(createUserId);
                        String mobilePhone = otherUserInfo.getMobilePhone();
 
 
                        UserInfo userInfo1 = userService.findByMobile(mobilePhone);
 
                        if (userInfo1 != null) {
                            payInfoReq.setOpenId(userInfo1.getOpenId());
                        }
                    }
 
                    payInfoReq.setStatus(PayEnum.待审核.getValue());
                    payInfoReq.setAccountId(accountVo.getAccountId());
                    payInfoMapper.payRequestInfoAdd(payInfoReq);
 
 
                    PayInfoLog payInfoLog = new PayInfoLog();
                    BeanUtil.copyProperties(payInfoReq, payInfoLog);
                    payInfoLog.setAccount(accountVo.getAccountName());
                    payInfoLog.setAccountClass(PayEnum.微信.getValue());
                    payInfoLog.setPayType(PayEnum.提现交易.getValue());
                    payInfoLogService.add(payInfoLog);
 
 
                    commonDto.setId(payOrderId);
 
                    if (PayEnum.银行卡.getValue().equals(Convert.toStr(payInfoReq.getAccountType(), ""))) {
                        commonDto.setExtra(PayEnum.手动审核.getValue());
                    } else {
                        ConfigInfo configInfo = new ConfigInfo();
                        configInfo.setConfigTypeCode("APPROVAL_TYPE");
                        ConfigInfo configInfo1 = configMapper.selectOne(configInfo);
                        if (PayEnum.自动审核.getValue().equals(configInfo1.getConfigValue())) {
 
                            log.debug("调用后台的提现方法");
                            TransfersDtoAdmin transfersDtoAdmin = new TransfersDtoAdmin();
                            transfersDtoAdmin.setPayOrderId(payOrderId);
                            if (businessUtil.isApp(request.getHeader("clientType"))) {
                                transfersDtoAdmin.setOtherUserId(payInfoReq.getCreateUserId());
                            } else {
                                transfersDtoAdmin.setUserId(payInfoReq.getCreateUserId());
                                transfersDtoAdmin.setOtherUserId("");
                            }
                            wxPay(transfersDtoAdmin);
                            //防止前端在调用自动审核接口
                            commonDto.setExtra(PayEnum.自动审核.getValue());
                        } else {
                            //防止前端在调用自动审核接口
                            commonDto.setExtra(PayEnum.手动审核.getValue());
                        }
                    }
                }
            } catch (RestException e) {
                ExceptionUtils.err(e.getMsg(), e);
            } catch (Exception e) {
                ExceptionUtils.err("提现失败", e);
            } finally {
                redisUtil.del(Constants.REDIS_PAY_KEY + "add:" + lockId);
            }
        }
        return commonDto;
    }
 
    public List<PayInfoVo> queryPayInfo(PayInfoReq payInfoReq) {
        List<PayInfoVo> payInfoList = payInfoMapper.queryPayInfo(payInfoReq);
        return payInfoList;
    }
 
    public List<PayInfoVo> queryPayRequestInfo(PayInfoReq payInfoReq) {
        List<PayInfoVo> payInfoList = payInfoMapper.queryPayRequestInfo(payInfoReq);
        return payInfoList;
    }
 
 
    public void addPay(PayInfo payInfo) {
        payInfo.setCreateTime(DateUtil.now());
        payInfoMapper.insertSelective(payInfo);
    }
 
 
    public int webChatRechargeCallback(Map map) {
        String userId = (String) map.get("userId");
        String money = (String) map.get("money");
        String fee = (String) map.get("fee");
        String payOrderId = (String) map.get("payOrderId");
 
 
        //更改状态
        int returnvalue = payInfoMapper.updatePayInfoStatus(map);
 
 
        AccountInfo accountInfo1 = accountService.findByUserId(userId);
        if (accountInfo1 == null) {
            throw new WxPayNotifyResponseException("账户不存在:" + userId);
        }
 
 
        OtherUserInfo otherUserInfo = otherUserService.findByIdByNotDel(userId);
 
        boolean flag = otherUserInfo != null && (CommonEnum.回收员.getValue().equals(otherUserInfo.getUserType()) || CommonEnum.入库员.getValue().equals(otherUserInfo.getUserType()) || CommonEnum.打包站运营员.getValue().equals(otherUserInfo.getUserType()) || CommonEnum.打包员.getValue().equals(otherUserInfo.getUserType())) && StrUtil.isNotBlank(accountInfo1.getFixedLimit()) && Convert.toBigDecimal(accountInfo1.getFixedLimit(), Constants.MONEY_INIT).compareTo(BigDecimal.ZERO) > 0;
        if (flag) {
            //回收员充值 和额度相关
            AccountVo accountVo = new AccountVo();
            BeanUtil.copyProperties(accountInfo1, accountVo);
            accountService.addAccount(accountVo, CommonEnum.充值操作.getValue(), payOrderId, money);
        } else {
            String now = DateUtil.now();
            AccountLog accountLog = new AccountLog();
            accountLog.setCreateTime(now);
            accountLog.setAccountId(accountInfo1.getAccountId());
            accountLog.setOldMoney(accountInfo1.getMoney());
            accountLog.setNewMoney(Convert.toStr(NumberUtil.add(Convert.toBigDecimal(accountInfo1.getMoney()), Convert.toBigDecimal(money))));
            accountLog.setCreateUserId(userId);
            accountLog.setChannelType(Convert.toShort(CommonEnum.充值操作.getValue()));
            accountLog.setOrderId(payOrderId);
            accountLogMapper.insertSelective(accountLog);
 
            map.put("money", Convert.toBigDecimal(money));
            payInfoMapper.updateMyMoneyByOrder(map);
 
        }
 
        //添加平台日志
        String oldMoney = Constants.MONEY_INIT.toString();
        String oldHbb = Constants.MONEY_INIT.toString();
 
        PlatformAccountInfo moneyKey = platformAccountInfoService.findByKey(Constants.PLAT_MONEY_KEY);
        if (moneyKey != null) {
            oldMoney = moneyKey.getFieldValue();
        }
        PlatformAccountInfo hbbKey = platformAccountInfoService.findByKey(Constants.PLAT_HBB_KEY);
        if (hbbKey != null) {
            oldHbb = hbbKey.getFieldValue();
        }
 
        //算上服务费的金额
        String MoneyAndFee = money;
//            if(StrUtil.isNotBlank(fee)){
//                MoneyAndFee=NumberUtil.add(Convert.toBigDecimal(money),Convert.toBigDecimal(fee)).toString();
//            }
 
        PlatformAccountLog platformAccountLog = new PlatformAccountLog();
        platformAccountLog.setCreateUserId(userId);
        platformAccountLog.setType(Convert.toInt(CommonEnum.平台充值.getValue()));
        platformAccountLog.setOldMoney(Convert.toBigDecimal(oldMoney));
        platformAccountLog.setMoney(Convert.toBigDecimal(MoneyAndFee));
        platformAccountLog.setNewMoney(NumberUtil.add(platformAccountLog.getOldMoney(), platformAccountLog.getMoney()));
        platformAccountLog.setOldHbb(Convert.toBigDecimal(oldHbb));
        platformAccountLog.setHbb(Convert.toBigDecimal("-" + money));
        platformAccountLog.setNewHbb(NumberUtil.add(platformAccountLog.getOldHbb(), platformAccountLog.getHbb()));
        platformAccountLog.setFlowNo(payOrderId);
        platformAccountLogService.add(platformAccountLog);
 
        //更新平台账户
        platformAccountInfoService.updateMoney(MoneyAndFee);
        platformAccountInfoService.updateHbb("-" + money);
 
        //充值消息录入
        SysMessage sysMessage = new SysMessage();
        sysMessage.setCreateTime(DateUtils.getCurDateTime());
        sysMessage.setCreateUserId(userId);
        sysMessage.setFlag("2");
        sysMessage.setMessage("您已经充值" + money + "元");
        sysMessage.setMessageSubTypeName("充值");
        sysMessage.setMessageType("2");
        sysMessage.setUserId(userId);
        sysMessageMapper.insert(sysMessage);
 
        return returnvalue;
    }
 
//    public int audit(CommonDto commonDto) {
//        String payOrderId = commonDto.getId();
//        boolean lock = false;
//        try {
//            if (redisUtil.setnx(Constants.REDIS_PAY_KEY + "audit:" + payOrderId, payOrderId)) {
//                lock = true;
//                PayRequestInfo payInfo = payRequestMapper.selectByPrimaryKey(payOrderId);
//                if (payInfo != null) {
//                    //调用提现自动审核接口
//                    log.info("调用提现自动审核接口");
//                    Map<String, Object> map = new HashMap<>();
//                    map.put("payOrderId", commonDto.getId());
//                    if (businessUtil.isApp(request.getHeader("clientType"))) {
//                        map.put("otherUserId", request.getHeader("userId"));
//                    } else {
//                        map.put("userId", payInfo.getCreateUserId());
//                        map.put("otherUserId", "");
//                    }
//
//                    String post = null;
//                    boolean error = false;
//                    log.info("提现审核请求参数:{}", JSONUtil.toJsonPrettyStr(map));
//                    try {
//                        post = HttpUtil.post(adminUrl + "gc-pay/admin/front/wx/pay/wxPay.do", JSONUtil.toJsonStr(map));
//                    } catch (Exception e) {
//                        error = true;
//                        log.error("远程调用提现审核接口失败", e);
//                    }
//
//                    if (error) {
//                        //修改状态
//                        PayRequestInfo payRequestInfo = new PayRequestInfo();
//                        payRequestInfo.setPayOrderId(payOrderId);
//                        payRequestInfo.setPayFlag(Convert.toInt(PayEnum.支付失败.getValue()));
//                        payRequestInfo.setStatus(PayEnum.已审核完成.getValue());
//                        payRequestInfo.setUnpassReason("提现审核接口超时");
//                        payRequestMapper.updateByPrimaryKeySelective(payRequestInfo);
//                        return -1;
//                    } else {
//                        log.info("提现审核返回结果:{}", post);
//                        JSONObject jsonObject = JSONUtil.parseObj(post);
//                        Integer code = jsonObject.getInt("code");
//                        String data = jsonObject.getStr("data", "");
//                        if (code != 0) {
//                            throw new RestException(-1, data);
//                        }
//                    }
//                } else {
//                    throw new RestException(-1, "提现订单不存在");
//                }
//            }
//        } catch (RestException e) {
//            throw new BusinessException(-1, e.getMsg(), ExceptionUtil.getMessage(e));
//        } catch (Exception e) {
//            ExceptionUtils.err("提现审核失败", e);
//        } finally {
//            if (lock == true) {
//                redisUtil.del(Constants.REDIS_PAY_KEY + "audit:" + payOrderId);
//            }
//        }
//        return 0;
//    }
 
 
    /**
     * 提现
     * @param money
     */
//    public void withdraw(String money,String userId,String clientType,Long accountBindId) {
//        boolean lock=false;
//        try {
//            if(redisUtil.setnx(Constants.REDIS_PAY_KEY + "withdraw:" +userId, userId)) {
//                lock=true;
//                PayInfoReq payInfoReq = new PayInfoReq();
//                payInfoReq.setMoney(money);
//                payInfoReq.setCreateUserId(userId);
//                List<PayInfoVo> withdrawList = payMapper.queryWithdrawInfo(payInfoReq);
//                if (withdrawList.size() >= 1) {
//                    throw new RestException(-1, "一天只能提现一次");
//                }
//                String payOrderId = idUtils.generate("ZF", 0);
//                payInfoReq.setPayOrderId(payOrderId);
//                String now = DateUtil.now();
//                payInfoReq.setCreateTime(now);
//                List<AccountVo> accountList = payMapper.queryMyMoney(payInfoReq);
//                AccountVo accountVo = accountList.get(0);
//                payInfoReq.setAccountId(accountVo.getAccountId());
//                payInfoReq.setPayType(PayEnum.提现.getValue());
//                //提现金额
//                BigDecimal bigDecimal = NumberUtil.toBigDecimal(payInfoReq.getMoney());
//                //余额
//                BigDecimal bigDecimal1 = NumberUtil.toBigDecimal(accountVo.getMoney());
//
//                //判断账户余额是否足够,返回-1表示余额不够
//
//                if (NumberUtil.isGreater(bigDecimal, bigDecimal1)) {
//                    throw new RestException(-1, "用户余额不足");
//                }
//
//                //查询用户openId
//                if (CommonEnum.WEB.getValue().equals(clientType)) {
//                    UserInfo userInfo = userMapper.selectByPrimaryKey(userId);
//                    payInfoReq.setOpenId(userInfo.getOpenId());
//                } else {
//                    OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(userId);
//                    payInfoReq.setOpenId(otherUserInfo.getOpenId());
//                }
//
//                payInfoReq.setStatus(PayEnum.已审核.getValue());
//                payInfoReq.setAccountBindId(accountBindId);
//                payMapper.payRequestInfoAdd(payInfoReq);
//
//
//                PayInfoLog payInfoLog = new PayInfoLog();
//                BeanUtil.copyProperties(payInfoReq, payInfoLog);
//                payInfoLog.setAccount(accountVo.getAccountName());
//                payInfoLog.setAccountClass(PayEnum.微信.getValue());
//                payInfoLog.setPayType(PayEnum.提现交易.getValue());
//                payInfoLogService.add(payInfoLog);
//
//                //是否自动审核  银行卡等肯定是手动审核
//                ConfigInfo configInfo = new ConfigInfo();
//                configInfo.setConfigTypeCode("APPROVAL_TYPE");
//                ConfigInfo configInfo1 = configMapper.selectOne(configInfo);
//                if (configInfo1 != null) {
//                    String configValue = configInfo1.getConfigValue();
//                    if(PayEnum.自动审核.getValue().equals(configValue)){
//                        log.info("调用提现自动审核接口");
//                        Map<String, Object> map = new HashMap<>();
//                        map.put("payOrderId", commonDto.getId());
//                    }
//                }
//
//
//
//            }
//        }catch (RestException e){
//            throw new RestException(-1,e.getMsg());
//        }catch (Exception e){
//            ExceptionUtils.err("提现审核失败",e);
//        }finally {
//            if(lock){
//                redisUtil.del(Constants.REDIS_PAY_KEY +"withdraw:" +userId);
//            }
//        }
//
//    }
 
 
    /**
     * 查询当前用户一周内是否有充值成功的记录
     */
//    public List<PayInfo> findForWeekByUserIdAndType(String userId, String payType) {
//        return payInfoMapper.findForWeekByUserIdAndType(userId, payType);
//    }
    public void updateStatus(String payOrderId, String status) {
        Example example = new Example(PayInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("payOrderId", payOrderId);
        criteria.andNotEqualTo("status", "2");
        PayInfo payInfo = new PayInfo();
        payInfo.setStatus(status);
        payInfoMapper.updateByExampleSelective(payInfo, example);
    }
 
    public AccountBindInfo findPayMethod(String userId) {
        AccountBindInfo payMethod = payInfoMapper.findPayMethod(userId);
        if (payMethod == null) {
            List<AccountBindInfo> byUserId = accountBindService.findByUserId(userId);
            if (CollUtil.isNotEmpty(byUserId)) {
                return byUserId.get(0);
            } else {
                return null;
            }
        } else {
            return payMethod;
        }
    }
 
 
    public void sendWxPay(String url, String path, TransfersDtoAdmin dto, UserAccountModel userAccount, String mobilePhone, String oldMoney) {
        String param = WechatpayUtil.getStringBuild(dto);
        PayLog payLog = insertLog(dto, userAccount, param);
        ResultEntity iResult = WechatpayUtil.doTransfers(url, path, dto, userAccount, param);
        payLog.setResponseData(iResult.getMsg());
        if (!iResult.isSuccess()) {
            throw new RestException(iResult.getMsg());
        } else {
            updateAccount(payLog, dto.getPayOrderId(), mobilePhone, oldMoney);
        }
    }
 
 
    /**
     * 企业提现零钱接口
     *
     * @param dto
     * @param userAccount
     */
    private PayLog insertLog(TransfersDtoAdmin dto, UserAccountModel userAccount, String param) {
        // 添加账户log请求前信息
        PayLog payLog = new PayLog();
        payLog.setId(IdUtil.getSnowflake(1, 3).nextId());
        payLog.setAccountBeforeMoney(userAccount.getMoney());
        payLog.setUserId(dto.getUserId());
        payLog.setAccountId(userAccount.getAccountId());
        payLog.setWxOpenid(dto.getOpenid());
        payLog.setCreateTime(DateUtil.now());
        payLog.setPayStatus("0");
        //因为接口使用的是以分为单位,所以需要转为元
        String a = new BigDecimal(dto.getAmount()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).toString();
        payLog.setMoney(Double.valueOf(a));
        payLog.setWithdrawBeforeMoney(Double.parseDouble("0"));
        payLog.setMchBillno(dto.getPayOrderId());
 
        payLog.setRequestParams(param);
        return payLog;
 
    }
 
    private void updateAccount(PayLog payLog, String payOrderId, String mobilePhone, String oldMoney) {
        UserAccountModel userAccountModel1 = accountMapper.queryAccountInfo(payLog.getUserId(), mobilePhone);
        double mm = MathUtils.subDouble(userAccountModel1.getMoney(), payLog.getMoney());
        PayLog newPl = new PayLog();
        newPl.setAccountId(payLog.getAccountId());
        newPl.setMoney(mm);
        // 更新账号余额
        accountMapper.updateAccountMoneyDouble(newPl);
        //写入消息列表中
        String message = "您的提现已经到了:" + payLog.getMoney() + "元,提现单号:" + payOrderId + ",请注意查收.";
        sysMessageMapper.insertMessage(message, payLog.getUserId(), "", "1", "提现", DateUtil.now());
 
        UserAccountModel userAccountModel = accountMapper.queryAccountInfo(payLog.getUserId(), mobilePhone);
        AccountLogModel model = new AccountLogModel();
        model.setAccountId(userAccountModel.getAccountId());
        model.setChannelType("2");
        model.setCreateTime(DateUtil.now());
        model.setCreateUserId(userAccountModel.getUserId());
        model.setNewFixedLimit(userAccountModel.getFixedLimit());
        model.setNewLimit(userAccountModel.getOverdraftLimit());
        model.setNewMoney(String.valueOf(userAccountModel.getMoney()));
        model.setOldFixedLimit(userAccountModel.getFixedLimit());
        model.setOldLimit(userAccountModel.getOverdraftLimit());
        model.setOldMoney(oldMoney);
        model.setOrderId(payOrderId);
        accountLogMapper.insertAccountLog(model);
        //写入平台日志表,扣除平台金额添加环保币
        insertPlatLog(payLog.getMoney() + "", payOrderId);
    }
 
    public Map<String, Object> queryPayInfoDetail(String payOrderId) {
        Map<String, Object> map = payRequestMapper.queryPayInfoDetail(payOrderId);
        if (!"1".equals(map.get("usertype"))) {
            String roleName = userRoleMapper.queryPayInfoUserRole(map.get("usertype").toString());
            map.put("roleName", roleName);
        } else {
            map.put("roleName", "普通用户");
        }
 
        if (map.get("status").equals("2")) {
            map.put("statusName", "已审核");
        } else if (map.get("status").equals("3")) {
            map.put("statusName", "审核未通过");
        } else {
            map.put("statusName", "待审核");
        }
        return map;
    }
 
    private void insertPlatLog(String amount, String payOrderId) {
        String acc = platformAccountInfoMapper.queryAccountByAdminId();
        String[] accArr = acc.split(",");
        String adminMoney = accArr[1];
        String adminhbb = accArr[2];
        //平台
        BigDecimal oldAdminMoney = new BigDecimal(adminMoney);
        BigDecimal oldAdminhbb = new BigDecimal(adminhbb);
        //平台账户处理红包
        BigDecimal newAdminMoney = oldAdminMoney.subtract(new BigDecimal(amount));
        BigDecimal newAdminhbb = oldAdminhbb.add(new BigDecimal(amount));
 
        platformAccountInfoMapper.updatePlatformHbb(DoubleUtil.roundTwo(newAdminhbb.toString()));
        platformAccountInfoMapper.updatePlatformMoney(DoubleUtil.roundTwo(newAdminMoney.toString()));
        PlatformAccountLogModel platformAccountLogModel = new PlatformAccountLogModel();
        platformAccountLogModel.setCreateTime(DateUtil.now());
        platformAccountLogModel.setCreateUserId("1");
        platformAccountLogModel.setMoney(DoubleUtil.roundTwo("0"));
        platformAccountLogModel.setHbb("-" + DoubleUtil.roundTwo(amount));
        platformAccountLogModel.setOldHbb(DoubleUtil.roundTwo(adminhbb));
        platformAccountLogModel.setOldMoney(DoubleUtil.roundTwo(adminMoney));
        platformAccountLogModel.setNewHbb(DoubleUtil.roundTwo(newAdminhbb.toString()));
        platformAccountLogModel.setNewMoney(DoubleUtil.roundTwo(adminMoney));
        platformAccountLogModel.setCreateUserName("平台管理员");
        platformAccountLogModel.setCreateUserType("2");
        platformAccountLogModel.setCreateUserMobile("--");
        platformAccountLogModel.setFlowNo(payOrderId);
        platformAccountLogMapper.insertPlatFormLog(platformAccountLogModel);
    }
 
 
    public void wxPay(TransfersDtoAdmin dto) {
        MoneyModel moneyModel;
        String payOrderId = dto.getPayOrderId();
        String otherUserId = dto.getOtherUserId();
        String key=RedisKeyConstant.WITHDRAW_KEY+payOrderId;
        try {
            if(redisUtil.setnx(key,"0")){
                if (StringUtils.isEmpty(dto.getPayOrderId())) {
                    throw new RestException("payOrderId不能为空");
                } else {
                    moneyModel = getMoneyModel(dto.getPayOrderId());
                    String desc;
                    //监测金额和用户是否一致
                    if (null != otherUserId && !"".equals(otherUserId)) {
                        desc = checkMoneyModel(moneyModel, otherUserId);
                    } else {
                        desc = checkMoneyModel(moneyModel, dto.getUserId());
                    }
                    if (!"success".equals(desc)) {
                        throw new RestException(desc);
                    }
                }
 
                //查询用户openId
                String openId;
                UserModel userModel = null;
                CityPartner cityPartner = null;
                if (StrUtil.isNotBlank(otherUserId)) {
                    //根据用户ID判断是否是合伙人 是则代表是合伙人的运营员在操作
                    cityPartner = cityPartnerService.findByUserId(otherUserId, OrderEnum.合伙人.getValue());
                    if (cityPartner == null) {
                        //回收员之类的在提现
                        dto.setMch_appid(anroidAppId);
                        userModel = otherUserMapper.queryUserOtherInfoById(otherUserId);
                    }
                } else {
                    dto.setMch_appid(APP_ID);
                    userModel = userMapper.queryUserById(dto.getUserId());
                }
 
                //不是合伙人提现
                if (cityPartner == null && userModel == null) {
                    throw new RestException("用户不存在");
                }
                //查询用户账户是否能提现
                if (cityPartner == null) {
                    //检测金额是否足够
                    UserAccountModel userAccount=checkUserAccount(moneyModel, userModel);
                    String oldMoney = String.valueOf(userAccount.getMoney());
 
                    openId = userModel.getOpenId();
                    String mobilePhone = userModel.getMobilePhone();
                    if (StrUtil.isNotBlank(openId)) {
                        dto.setOpenid(openId);
                        dto.setMchid(MCH_ID);
                        dto.setAppkey(APP_KEY);
                        dto.setSpbill_create_ip(CREATE_IP);
                        dto.setMch_name("湖南小棕熊环保科技有限责任公司");
                        dto.setDesc("企业付款到零钱");
                        if (null != otherUserId && !"".equals(otherUserId)) {
                            dto.setUserId(otherUserId);
 
                        }
                        //自动转为以分为单位
                        dto.setAmount(Double.parseDouble(moneyModel.getMoney()));
                        dto.setPayOrderId(payOrderId);
                        sendWxPay(TRANS_URL, CERT_PATH, dto, userAccount, mobilePhone, oldMoney);
                    }else {
                        throw new RestException("用户OPENID为空");
                    }
                }else {
                    //线下打款  减去其环保币
                    PartnerAccountLog partnerAccountLog=new PartnerAccountLog();
                    partnerAccountLog.setPartnerId(cityPartner.getId()+"");
                    partnerAccountLog.setFlowNo(payOrderId);
                    //提现
                    partnerAccountLog.setType("2");
                    partnerAccountLog.setMoney("-"+moneyModel.getMoney());
                    partnerAccountLogService.add(partnerAccountLog);
                    partnerAccountService.updateReduceMoneyByPartnerId(cityPartner.getId()+"",Convert.toBigDecimal(moneyModel.getMoney()));
                }
 
                // 更新支付状态
                PayRequestInfo payRequestInfo=new PayRequestInfo();
                payRequestInfo.setPayOrderId(payOrderId);
                payRequestInfo.setStatus("2");
                payRequestInfo.setPayFlag(2);
                payRequestInfo.setExamineTime(DateUtil.now());
                payRequestMapper.updateByPrimaryKeySelective(payRequestInfo);
            }
        }catch (RestException e){
            ExceptionUtils.err(e.getMsg(), e);
        }catch (Exception e){
                ExceptionUtils.err("提现失败", e);
        }finally {
                redisUtil.del(key);
        }
 
    }
 
    private MoneyModel getMoneyModel(String payOrderId) {
        MoneyModel moneyModel = new MoneyModel();
        moneyModel.setPayOrderId(payOrderId);
        moneyModel = payRequestMapper.queryMoney(moneyModel);
        moneyModel.setStatus("3");
        moneyModel.setPayFlag("3");
        moneyModel.setExamineTime(DateUtil.now());
        return moneyModel;
    }
 
    private UserAccountModel checkUserAccount(MoneyModel moneyModel, UserModel userModel) {
 
        // 查询用户账号表
        UserAccountModel userAccountModel = accountMapper.queryAccountInfo(userModel.getUserId(), userModel.getMobilePhone());
        if (userAccountModel == null) {
            throw new RestException("此用户未查询到账户信息");
        }
        if (userAccountModel.getDelFlag().equals("1")) {
            throw new RestException("账户信息已删除");
        }
        if (userAccountModel.getMoney() < Double.parseDouble(moneyModel.getMoney())) {
            throw new RestException("账户金额不足");
        }
        if (!userModel.getOpenId().equals(moneyModel.getOpenId())) {
            throw new RestException("用户和支付的openId不一致");
        }
        return userAccountModel;
    }
 
    /**
     * @param model
     * @return
     */
    private String checkMoneyModel(MoneyModel model, String userId) {
        if (!model.getCreateUserId().equals(userId)) {
            model.setUnpassReason("userId和支付订单里面的userId不一致");
            payRequestMapper.updateMoney(model);
            return "userId和支付订单里面的userId不一致";
        }
        if (StringUtils.isEmpty(model.getCreateUserId())) {
            model.setUnpassReason("用户ID不能为空");
            payRequestMapper.updateMoney(model);
            return "用户ID不能为空";
        }
        if (StringUtils.isEmpty(model.getMoney())) {
            model.setUnpassReason("金钱不能为空");
            payRequestMapper.updateMoney(model);
            return "金钱不能为空";
        }
        if (Double.parseDouble(model.getMoney()) <= 0.3) {
            model.setUnpassReason("金额不能等于或小于0.3");
            payRequestMapper.updateMoney(model);
            return "金额不能等于或小于1";
        }
        return "success";
    }
 
 
    /**
     * 根据用户id和支付类型和支付第二类型分页查询
     *
     * @param userId     用户id
     * @param payType    支付类型
     * @param secondType 第二类型
     * @return
     */
    public PageInfo<PayInfo> findPageByUserIdAndSecondType(SimplePage simplePage, String userId, String payType, String secondType) {
        Example example = new Example(PayInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("createUserId", userId);
        if (StrUtil.isNotBlank(payType))
            criteria.andEqualTo("payType", payType);
        if (StrUtil.isNotBlank(secondType))
            criteria.andEqualTo("paySecondType", secondType);
        example.setOrderByClause("create_time desc");
        PageHelper.startPage(simplePage.getPageNo(), simplePage.getPageSize());
        List<PayInfo> payInfos = payInfoMapper.selectByExample(example);
        PageInfo<PayInfo> payInfoPageInfo = new PageInfo<>(payInfos);
        return payInfoPageInfo;
    }
 
 
    /**
     * 积分列表
     *
     * @param payScoreParamDTO
     * @return
     */
    public PayScoreResDTO scoreList(PayScoreParamDTO payScoreParamDTO) {
        PayScoreResDTO resDTO = new PayScoreResDTO();
        List<PayScoreResPerDTO> list = payInfoMapper.scoreList(payScoreParamDTO);
        PageInfo<PayScoreResPerDTO> pageInfo = new PageInfo<>(list);
        resDTO.setPageInfo(pageInfo);
        //平台总积分
        String collectScore = platformAccountInfoService.findByKey("collectScore").getFieldValue();
        resDTO.setAllPlatScore(businessUtil.changeMoney(collectScore));
        //获取总积分
        BigDecimal allRechargeScore = Constants.MONEY_INIT;
        //消耗总积分
        BigDecimal allConsumeScore = Constants.MONEY_INIT;
 
        List<AccountScoreLog> accountScoreLogs = accountScoreLogMapper.selectAll();
 
        for (AccountScoreLog accountScoreLog : accountScoreLogs) {
            Short channelType = accountScoreLog.getChannelType();
            String manageScore = accountScoreLog.getManageScore();
            if (Convert.toShort(1).equals(channelType)) {
                //获取
                allRechargeScore = NumberUtil.add(allRechargeScore, businessUtil.changeMul(manageScore));
            } else if (Convert.toShort(2).equals(channelType)) {
                //消耗
                allConsumeScore = NumberUtil.add(allConsumeScore, businessUtil.changeMul(manageScore));
            }
        }
        resDTO.setAllRechargeScore(businessUtil.changeMoney(allRechargeScore));
        resDTO.setAllConsumeScore(businessUtil.changeMoney(allConsumeScore));
 
        return resDTO;
    }
 
    private AlipayTradeAppPayRequest getRequest() {
        // 初始化Request,并填充Model属性。实际调用时请替换为您想要使用的API对应的Request对象。
        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//        AlipayOpenOperationOpenbizmockBizQueryModel model = new AlipayOpenOperationOpenbizmockBizQueryModel();
//        model.setBizNo("test");
        //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setBody("我是测试数据");
        model.setSubject("App支付测试Java");
        model.setOutTradeNo(idUtils.generate("ZF", 1));
        model.setTimeoutExpress("30m");
        model.setTotalAmount("0.01");
        model.setProductCode("QUICK_MSECURITY_PAY");
        request.setBizModel(model);
        request.setNotifyUrl("http://zan7755.ngrok2.xiaomiqiu.cn/gc-pay/pay/ali/notify");
        return request;
    }
 
    public String aliPay(AliPayDTO aliPayDTO) throws AlipayApiException {
        // 2. 创建使用的Open API对应的Request请求对象
        AlipayTradeAppPayRequest request = getRequest();
        // 3. 发起请求并处理响应
        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
        if (response.isSuccess()) {
            log.debug("阿里支付调用成功。");
        } else {
            log.debug("阿里支付调用失败,原因:" + response.getMsg() + "," + response.getSubMsg());
        }
        return response.getBody();
    }
 
    public String aliPayNotify(Map<String, String> params) throws AlipayApiException {
        log.debug("阿里回调返回:{}", JSONUtil.toJsonStr(params));
        //切记alipaypublickey是支付宝的公钥,请去open.alipay.com对应应用下查看。
        //boolean AlipaySignature.rsaCertCheckV1(Map<String, String> params, String publicKeyCertPath, String charset,String signType)
        boolean flag = AlipaySignature.rsaCertCheckV1(params, "E:/card/alipayCertPublicKey_RSA2.crt", "UTF-8", "RSA2");
        return Convert.toStr(flag);
    }
}