xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
package com.stylefeng.guns.modular.account.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.account.service.ITEnterpriseWithdrawalService;
import com.stylefeng.guns.modular.account.service.UserWithdrawalService;
import com.stylefeng.guns.modular.account.unionpay.*;
import com.stylefeng.guns.modular.cloudPayment.example.*;
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
import com.stylefeng.guns.modular.cloudPayment.req.BalanceAcctReq;
import com.stylefeng.guns.modular.cloudPayment.req.DepositReq;
import com.stylefeng.guns.modular.cloudPayment.req.WithdrawalReq;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.enums.PaymentTypeEnum;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.resp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * @program: openPlatform
 * @description: 下单
 */
@Api(tags = "下单")
@Slf4j
@RestController
@RequestMapping("")
public class AppOrderController {
    static String appId = "10037e6f66f2d0f901672aa27d690006"; // 10037e6f6823b20801682b6a5e5a0006
    static String appKey = "47ace12ae3b348fe93ab46cee97c6fde";
 
 
    private final UserWithdrawalService userWithdrawalService;
    private final ICompanyService companyService;
    private final QrCodeConfiguration qrCodeConfiguration;
    private final IOrderCrossCityService orderCrossCityService;
    private final IDriverService driverService;
    private final ITEnterpriseWithdrawalService enterpriseWithdrawalService;
    private final ITransactionDetailsService transactionDetailsService;
    private final IReassignService reassignService;
    private final IPaymentRecordService paymentRecordService;
 
    @Autowired
    public AppOrderController(UserWithdrawalService userWithdrawalService, ICompanyService companyService, QrCodeConfiguration qrCodeConfiguration, IOrderCrossCityService orderCrossCityService, IDriverService driverService, ITEnterpriseWithdrawalService enterpriseWithdrawalService, ITransactionDetailsService transactionDetailsService, IReassignService reassignService, IPaymentRecordService paymentRecordService) {
        this.userWithdrawalService = userWithdrawalService;
        this.companyService = companyService;
        this.qrCodeConfiguration = qrCodeConfiguration;
        this.orderCrossCityService = orderCrossCityService;
        this.driverService = driverService;
        this.enterpriseWithdrawalService = enterpriseWithdrawalService;
        this.transactionDetailsService = transactionDetailsService;
        this.reassignService = reassignService;
        this.paymentRecordService = paymentRecordService;
    }
 
    public static void main(String[] args) throws Exception {
 
    }
 
    /**
     * app下单
     *
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/api/placeOrder/appPay", method = RequestMethod.POST)
    @ApiOperation(value = "司机下单", tags = {"司机端-司机下单"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "支付方式 1=微信,2=支付宝,4=云闪付", name = "type", required = true, dataType = "Integer"),
    })
    public ResultUtil placeAnOrder(BigDecimal amount, Integer type,Integer orderType) throws Exception {
        JSONObject json = new JSONObject();
        json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));    // 报文请求时间
        json.put("merOrderId", Util.getMerOrderId(qrCodeConfiguration.getMsgSrcId())); // 商户订单号
        json.put("mid", qrCodeConfiguration.getMid()); // 商户号
        json.put("tid", qrCodeConfiguration.getTid());    // 终端号
        json.put("instMid", qrCodeConfiguration.getInstMid()); // 业务类型
        json.put("totalAmount", amount.multiply(new BigDecimal("100")).intValue());      // 支付总金额
        json.put("orderDesc", "APP下单"); // 订单描述
        json.put("srcReserve", type); // 预留字段
        json.put("subAppId", "wxasdasdasdasdads");
        json.put("notifyUrl", "http://123.56.89.63:8080/driver/api/placeOrder/notifyUrl");
        json.put("tradeType", "APP");  // 交易类型,微信必传
      //  json.put("divisionFlag", true); // 分账标记
      //  json.put("platformAmount", 0); // 平台商户分账金额
//        ArrayList<JSONObject> subOrders = new ArrayList<>();
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("mid", "988460101800201");
//        jsonObject.put("totalAmount", 1);
//        subOrders.add(jsonObject);
     //    json.put("subOrders", subOrders);
 
        System.err.println("请求报文json:\n" + json);
        String url;
        if(1 == type){
//            url = "https://test-api-open.chinaums.com/v1/netpay/wx/app-pre-order";// 测试
            url = "https://api-mop.chinaums.com/v1/netpay/wx/app-pre-order";
        }else if (2 == type){
//            url = "https://test-api-open.chinaums.com/v1/netpay/trade/precreate";// 测试
            url = "https://api-mop.chinaums.com/v1/netpay/trade/precreate";
        }else {
//            url = "https://test-api-open.chinaums.com/v1/netpay/uac/app-order";// 测试
            url = "https://api-mop.chinaums.com/v1/netpay/uac/app-order";
        }
        //OPEN-BODY-SIG 方式
        String result = GetOpenBodySig.sendOpenBodySig(qrCodeConfiguration.getAppId(),qrCodeConfiguration.getAppKey(),url, json.toString());
        System.err.println("响应报文json:\n" + result);
        JSONObject jsonObject = JSONObject.parseObject(result);
        Object appPayRequest = jsonObject.get("appPayRequest");
        System.out.println(appPayRequest);
        return ResultUtil.success(appPayRequest);
    }
 
    /**
     *
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/api/placeOrder/qrCode", method = RequestMethod.POST)
    @ApiOperation(value = "二维码支付", tags = {"司机端-二维码支付"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil getQrcode(Integer id) throws Exception {
 
        // 跨城出行订单查询
        OrderCrossCity orderCrossCity = orderCrossCityService.selectById(id);
        if(Objects.isNull(orderCrossCity)){
            return ResultUtil.error("该订单不存在!");
        }
        // 云闪付订单号
        String merOrderId = Util.getMerOrderId(qrCodeConfiguration.getMsgSrcId());
        orderCrossCity.setBillNo(merOrderId+"0");
        orderCrossCityService.updateById(orderCrossCity);
 
        paymentRecordService.saveData(1, orderCrossCity.getDriverId(), 2, orderCrossCity.getId(), 3, 5, orderCrossCity.getOrderMoney(), "", 1);//添加预支付数据
 
        JSONObject json = new JSONObject();
        json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));    // 报文请求时间
        json.put("srcReserve", id+"-"+3); // 请求系统预留字段,订单类型
        json.put("mid", qrCodeConfiguration.getMid()); // 商户号
        json.put("tid", qrCodeConfiguration.getTid());    // 终端号
        json.put("instMid", qrCodeConfiguration.getInstMid()); // 业务类型
        json.put("billNo", merOrderId); // 商户订单号
        //json.put("preauthTransaction", true);
        //json.put("expireTime", "2120-10-30 10:00:00");
        //json.put("billDate", DateFormatUtils.format(new Date(), "yyyy-MM-dd")); // 账单日期
        json.put("returnUrl", "https://zhentonggongsi.com:443/driver/api/placeOrder/notifyUrlOne"); // 回调地址
        json.put("notifyUrl", "https://zhentonggongsi.com:443/driver/api/placeOrder/notifyUrlOne"); // 回调地址
//        json.put("returnUrl", "http://vwpmxwbhv59i.guyubao.com/api/placeOrder/notifyUrlOne"); // 回调地址
//        json.put("notifyUrl", "http://vwpmxwbhv59i.guyubao.com/api/placeOrder/notifyUrlOne"); // 回调地址
        json.put("billDesc", "跨城出行");  // 账单描述
        BigDecimal bigDecimal = BigDecimal.valueOf(orderCrossCity.getOrderMoney());
//        BigDecimal bigDecimal = BigDecimal.ONE;
        json.put("totalAmount", new BigDecimal(100).multiply(bigDecimal));      // 支付总金额
//        json.put("totalAmount", bigDecimal);      // 支付总金额
//        json.put("totalAmount", 3);      // 支付总金额
        //json.put("limitCreditCard", true);
//        json.put("certNo", "NDIwMTExMTk3ODEyMTE1Njkz");
//                json.put("name", "6ZmI5L+K5beN");
//                json.put("fixBuyer", "T");
//        json.put("certType", "IDENTITY_CARD");
//        json.put("msgId", "字段返回测试msgId");
//        json.put("memberId", "字段返回测试memberId");
//        json.put("counterNo", "字段返回测试counterNo");
 
        /* 分账部分 */
//        json.put("divisionFlag", true); // 分账标记
//        json.put("platformAmount", 30000); // 平台商户分账金额
//        ArrayList subOrders = new ArrayList<>();
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("mid", "988460101800201");
//        jsonObject.put("totalAmount", 7000);
//        subOrders.add(jsonObject);
//        json.put("subOrders", subOrders);
        System.out.println("请求报文json:\n" + json.toString());
//        String url = "https://test-api-open.chinaums.com/v1/netpay/bills/get-qrcode";
          String url = "https://api-mop.chinaums.com/v1/netpay/bills/get-qrcode";
        //OPEN-BODY-SIG 方式
        String result = GetOpenBodySig.sendOpenBodySig(qrCodeConfiguration.getAppId(),qrCodeConfiguration.getAppKey(),url, json.toString());
        System.out.println("响应报文json:\n" + result);
        return ResultUtil.success(JSONObject.parseObject(result));
    }
 
    /**
     * 支付回调
     *
     * @throws Exception
     */
    @PostMapping(value = "/api/placeOrder/notifyUrl")
    @Transactional(isolation = Isolation.READ_UNCOMMITTED,rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public void notifyUrl(HttpServletRequest request,HttpServletResponse response) throws Exception {
        // 接收参数
        Map<String, String> params = NotifyDemo.getRequestParams(request);
        System.err.println("params:" + params);
        String sign = params.get("sign");// 签名
        System.err.println("============================"+sign);
        String billStatus = params.get("status");// 状态
//        String billPayment = params.get("billPayment");// 账单支付信息
//        String merOrderId = params.get("merOrderId"); // 商户订单号
        String targetOrderId = params.get("targetOrderId"); // 流水号
        Integer totalAmount = Integer.valueOf(params.get("totalAmount")); // 总金额
        Integer buyerPayAmount = Integer.valueOf(params.get("buyerPayAmount")); // 支付金额
        Integer couponAmount = Integer.valueOf(params.get("couponAmount"));// 优惠金额
        String srcReserve = params.get("srcReverse");// 预留字段
        System.out.println("预留字段"+srcReserve);
        // 验签
        //对通知内容生成sign
        String strSign = NotifyDemo.makeSign256Hex(qrCodeConfiguration.getMd5key(), params);
        System.err.println("==============================="+strSign);
 
        //判断签名是否相等
        if (sign.equals(strSign)) {
            System.out.println("签名相等");
            if("TRADE_SUCCESS".equals(billStatus)){
                System.out.println("回调状态成功");
                String[] split = srcReserve.split("-");
                Integer orderType = Integer.valueOf(split[1]);
                Integer type = Integer.valueOf(split[2]);
 
//                orderCrossCity.setState(8);// 待评价
//                orderCrossCity.setPayMoney(buyerPayAmount.doubleValue());
//                orderCrossCity.setPayType(3);// 二维码支付
//                orderCrossCity.setPayTime(new Date());// 支付时间
//                orderCrossCityService.updateById(orderCrossCity);
//
//                BigDecimal b1 = new BigDecimal(Double.toString(driver.getBalance()));
//                BigDecimal b2 = new BigDecimal(Double.toString(buyerPayAmount));
//                driver.setBalance(b1.add(b2).doubleValue());
//                driverService.updateById(driver);
//                Driver driver = null;
                if(orderType == 1){
                    System.out.println("改派订单");
                    String orderId = split[0];
                    System.out.println("=========================="+orderId);
                    String[] s = orderId.split("_");
                    if(Integer.parseInt(s[1]) == 3) {//跨城订单
                        System.out.println("跨城订单");
                        String[] split1 = s[0].split(",");
                        List<Reassign> reassigns = reassignService.selectBatchIds(Arrays.asList(split1));
                        if(Objects.nonNull(reassigns.get(0).getState()) && 2 == reassigns.get(0).getState() ){
                            System.out.println("该订单已支付");
                            return;
                        }
                        reassigns.get(0).setBillNo(targetOrderId);
                        reassignService.updateById(reassigns.get(0));
//                        driver = driverService.selectById(reassigns.get(0).getOriginalDriverId());
                    }else {
                        System.out.println("其他订单");
                        Reassign reassign = reassignService.selectById(s[0]);
                        if(Objects.nonNull(reassign.getState()) && 2 == reassign.getState() ){
                            System.out.println("该订单已支付");
                            return;
                        }
                        reassign.setBillNo(targetOrderId);
                        reassignService.updateById(reassign);
//                        driver = driverService.selectById(reassign.getOriginalDriverId());
                    }
 
                    reassignService.payReassign(orderId,targetOrderId,4);
                    System.out.println("改派订单结束");
                }
 
                if(orderType == 3){
                    System.out.println("跨城订单");
                    Integer orderId = Integer.valueOf(split[0]);
                    // 更新商户系统的订单
                    OrderCrossCity orderCrossCity = orderCrossCityService.selectOne(new EntityWrapper<OrderCrossCity>()
                            .eq("id", orderId));
 
                    if(Objects.isNull(orderCrossCity)){
                        System.out.println("该订单不存在!");
                        return;
                    }
                    orderCrossCity.setBillNo(targetOrderId);
                    orderCrossCityService.updateById(orderCrossCity);
                    if(orderCrossCity.getState() != 7){
                        System.out.println("该订单状态不为待支付状态!");
                        return;
                    }
 
//                    driver = driverService.selectById(orderCrossCity.getDriverId());
 
                    orderCrossCityService.payOrderCrossCityCallback(orderCrossCity.getId(), targetOrderId, 4);
                    System.out.println("跨城订单结束");
                }
 
//                if(Objects.isNull(driver)){
//                    throw new RuntimeException("该订单司机查询失败");
//                }
 
                // 调用支付充值接口,将金额充值到平台账户
                // 查询平台账户
//                Company company = companyService.selectOne(new EntityWrapper<Company>()
//                        .eq("type", 1)
//                        .last("LIMIT 1"));
//                System.out.println("查询平台账户==============="+company);
                // 查询平台开户信息
//                TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
//                        .eq("companyId", company.getId())); //  替换为公司id
//                System.out.println("查询平台开户信息==============="+enterpriseWithdrawal);
                // 司机开户信息
                // TODO 司机进件信息
//                UserWithdrawal driverWith = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
//                        .eq("phone",driver.getPhone())
//                        .last("LIMIT 1"));
//                System.out.println("司机进件信息==============="+driverWith);
                // 查询司机该订单的收入,进行分账
//                TransactionDetails transactionDetails = transactionDetailsService.selectOne(new EntityWrapper<TransactionDetails>()
//                        .eq("state", 1)
//                        .eq("type", 1)
//                        .eq("userType", 2)
//                        .eq("userId", driver.getId())
//                        .eq("orderId", orderCrossCity.getId())
//                        .last("LIMIT 1"));
//                if(Objects.isNull(transactionDetails) || Objects.isNull(transactionDetails.getMoney())){
//                    throw new RuntimeException("司机订单收入为空!");
//                }
 
//                DepositReq depositReq = new DepositReq();
//                depositReq.setOutOrderNo(ToolUtil.getRandomString(32));
//                depositReq.setTotalAmount(totalAmount); // 总金额
//                depositReq.setAmount(buyerPayAmount); // 支付金额
//                depositReq.setDiscountAmount(couponAmount); // 优惠金额
//                depositReq.setBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId());
//                depositReq.setDepositType("1");
//                depositReq.setPaymentType(PaymentTypeEnum.CUP_APP.getCode());
//                depositReq.setPaymentTradeNo(targetOrderId); // 系统交易流水号
//                depositReq.setPaymentSucceededAt(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()));
//                System.out.println("创建支付充值对象==============="+depositReq);
                try {
//                    DepositResp depositResp = DepositExample.create(depositReq);
//                    System.out.println("支付充值成功============="+depositResp);
//                    log.info("支付充值成功:{}",depositResp);
                    // 对司机进行分账
//                    AllocationReq allocationReq = new AllocationReq();
//                    allocationReq.setOutOrderNo(targetOrderId);
//                    allocationReq.setPayBalanceAcctId(driverWith.getBalanceAcctId()); // 发送方
//                    allocationReq.setRecvBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId()); // 接收方
////                    BigDecimal multiply = new BigDecimal(100).multiply(BigDecimal.valueOf(buyerPayAmount));
//                    allocationReq.setAmount(buyerPayAmount); // 金额
//                    allocationReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode())); // 密码
//                    allocationReq.setOrderNo(targetOrderId);
//                    allocationReq.setOrderAmount(Long.valueOf(totalAmount));
//                    if(orderType == 1){
//                        allocationReq.setProductName("订单改派");
//                    }
//                    if(orderType == 3){
//                        allocationReq.setProductName("跨城出行");
//                    }
//                    allocationReq.setProductCount(1);
//                    AllocationResp allocationResp = AllocationExample.create(allocationReq);
//                    System.err.println("司机分账信息:"+allocationResp);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("支付充值失败:{}",e.getMessage());
                    PrintWriter writer = response.getWriter();
                    response.setStatus(200);
                    writer.write("FAILED");
                }
            }
            // 收到通知后记得返回SUCCESS
            System.out.println("验签通过");
            PrintWriter writer = response.getWriter();
            response.setStatus(200);
            writer.write("SUCCESS");
        } else {
            log.error("验签未通过!");
            PrintWriter writer = response.getWriter();
            response.setStatus(200);
            writer.write("FAILED");
        }
        //跳转支付完成页面
//        return "/WEB-INF/views/jsp/payResult.jsp";
    }
 
 
    @PostMapping(value = "/api/placeOrder/notifyUrlOne")
    @Transactional(isolation = Isolation.READ_UNCOMMITTED,rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public void notifyUrlOne(HttpServletRequest request, HttpServletResponse response) throws Exception{
        System.out.println("二维码支付回调");
        // 接收参数
        Map<String, String> params = NotifyDemo.getRequestParams(request);
        System.err.println("params:" + params);
        String sign = params.get("sign");// 签名
        System.err.println("============"+sign);
        String billStatus = params.get("billStatus");// 状态
        String billPayment = params.get("billPayment");// 账单支付信息
        String merOrderId = params.get("merOrderId"); // 商户订单号
        String targetOrderId = params.get("targetOrderId"); // 流水号
        String srcReserve = params.get("srcReserve");// 预留字段
        JSONObject jsonObject = JSONObject.parseObject(billPayment);
        Integer totalAmount = jsonObject.getInteger("totalAmount"); // 总金额
        Integer buyerCashPayAmt = jsonObject.getInteger("buyerCashPayAmt"); // 支付金额
        Integer couponAmount = jsonObject.getInteger("couponAmount");// 优惠金额
        // 验签
        //对通知内容生成sign
        String strSign = NotifyDemo.makeSign256Hex(qrCodeConfiguration.getMd5key(), params);
        System.err.println("==========="+strSign);
 
        //判断签名是否相等
//        if (sign.equals(strSign)) {
            if("PAID".equals(billStatus)){
                System.out.println("预留字段"+srcReserve);
                String[] split = srcReserve.split("-");
                Integer orderId = Integer.valueOf(split[0]);
                // 更新商户系统的订单
                OrderCrossCity orderCrossCity = orderCrossCityService.selectOne(new EntityWrapper<OrderCrossCity>()
                        .eq("id", orderId));
                if(Objects.isNull(orderCrossCity)){
                    System.out.println("该订单不存在!");
                    return;
                }
                orderCrossCity.setBillNo(targetOrderId);
                orderCrossCityService.updateById(orderCrossCity);
                if(orderCrossCity.getState() != 7){
                    System.out.println("该订单状态不为待支付状态!");
                    return;
                }
 
//                orderCrossCity.setState(8);// 待评价
//                orderCrossCity.setPayMoney(buyerPayAmount.doubleValue());
//                orderCrossCity.setPayType(3);// 二维码支付
//                orderCrossCity.setPayTime(new Date());// 支付时间
//                orderCrossCityService.updateById(orderCrossCity);
//                // 修改司机余额
//                Driver driver = driverService.selectById(orderCrossCity.getDriverId());
//                BigDecimal b1 = new BigDecimal(Double.toString(driver.getBalance()));
//                BigDecimal b2 = new BigDecimal(Double.toString(buyerPayAmount));
//                driver.setBalance(b1.add(b2).doubleValue());
//                driverService.updateById(driver);
                try {
                    System.out.println("跨城二维码支付回调开始");
                    orderCrossCityService.payOrderCrossCityCallback(orderCrossCity.getId(), targetOrderId, 5);
                    System.out.println("跨城二维码支付回调结束");
                } catch (Exception e) {
                    throw new RuntimeException(e.getMessage());
                }
                // 调用支付充值接口,将金额充值到平台账户
                // 查询平台账户
//                Company company = companyService.selectOne(new EntityWrapper<Company>()
//                        .eq("type", 1)
//                        .last("LIMIT 1"));
//                System.out.println("公司信息"+company);
//                // 查询平台开户信息
//                TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
//                        .eq("companyId", company.getId())); //  替换为公司id
//                // 司机开户信息
//                // TODO 司机进件信息
//                UserWithdrawal driverWith = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
//                        .eq("phone",driver.getPhone())
//                        .last("LIMIT 1"));
 
//                DepositReq depositReq = new DepositReq();
//                depositReq.setOutOrderNo(ToolUtil.getRandomString(32));
//                depositReq.setTotalAmount(totalAmount); // 总金额
//                depositReq.setAmount(buyerPayAmount); // 支付金额
//                depositReq.setDiscountAmount(couponAmount); // 优惠金额
//                depositReq.setBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId());
//                depositReq.setDepositType("1");
//                depositReq.setPaymentType(PaymentTypeEnum.CUP_APP.getCode());
//                depositReq.setPaymentTradeNo(targetOrderId); // 系统交易流水号
//                depositReq.setPaymentSucceededAt(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()));
                try {
//                    DepositResp depositResp = DepositExample.create(depositReq);
//                    System.err.println(depositResp);
//                    log.info("支付充值成功:{}",depositResp);
                    // 对司机进行分账
//                    AllocationReq allocationReq = new AllocationReq();
//                    allocationReq.setPayBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId()); // 发送方
//                    allocationReq.setRecvBalanceAcctId(driverWith.getBalanceAcctId()); // 接收方
//                    BigDecimal multiply = new BigDecimal(100).multiply(BigDecimal.valueOf(transactionDetails.getMoney()));
//                    allocationReq.setAmount(multiply.intValue()); // 金额
//                    allocationReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode())); // 密码
//                    allocationReq.setOrderNo(merOrderId);
//                    allocationReq.setOrderAmount(Long.valueOf(totalAmount));
//                    allocationReq.setProductName("跨城出行");
//                    allocationReq.setProductCount(1);
//                    AllocationResp allocationResp = AllocationExample.create(allocationReq);
//                    System.err.println("司机分账信息:"+allocationResp);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("支付充值失败:{}",e.getMessage());
                    PrintWriter writer = response.getWriter();
                    response.setStatus(200);
                    writer.write("FAILED");
                }
//            }
            // 收到通知后记得返回SUCCESS
            System.out.println("验签通过");
            PrintWriter writer = response.getWriter();
            response.setStatus(200);
            writer.write("SUCCESS");
        } else {
            log.error("二维码回调失败!");
            PrintWriter writer = response.getWriter();
            response.setStatus(200);
            writer.write("FAILED");
        }
        //跳转支付完成页面
//        return "/WEB-INF/views/jsp/payResult.jsp";
    }
 
//    @ResponseBody
//    @RequestMapping(value = "/api/placeOrder/appPayRecharge", method = RequestMethod.POST)
//    @ApiOperation(value = "支付充值", tags = {"支付充值"}, notes = "")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
//    })
    public static void app(){
        DepositReq depositReq = new DepositReq();
        depositReq.setOutOrderNo(ToolUtil.getRandomString(32));
        //-
        depositReq.setAmount(60000); // 支付金额
        depositReq.setBalanceAcctId("2008429872055963229");
        depositReq.setDepositType("1");
        depositReq.setPaymentType(PaymentTypeEnum.CUP_APP.getCode());
        //-
        depositReq.setPaymentTradeNo("88890525-135");
        depositReq.setPaymentSucceededAt(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()));
        //-
        depositReq.setOrderNo("88890525-135");
        depositReq.setOrderAmount(1L);
        depositReq.setProductName("充值金额");
        depositReq.setProductCount(1);
        depositReq.setNotifyUrl("http://zhentonggongsi.com:8010/api/placeOrder/notifyUrlOne");
        DepositResp depositResp = null;
        try {
            depositResp = DepositExample.create(depositReq);
        } catch (UpyztException e) {
            log.error(e.getMessage());
            e.printStackTrace();
        }
        System.err.println(depositResp);
        log.info("支付充值成功:{}",depositResp);
    }
 
//    @ResponseBody
//    @RequestMapping(value = "/api/placeOrder/queryApp", method = RequestMethod.POST)
//    @ApiOperation(value = "支付充值查询", tags = {"支付充值查询"}, notes = "")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
//    })
    public void queryApp(){
        DepositResp balanceAcctResp = null;
        try {
            balanceAcctResp = DepositExample.retrieveById("2008429872055963229");
            System.err.println(balanceAcctResp);
        } catch (UpyztException e) {
            log.error("电子账簿查询失败:{}",e.getMessage());
            e.printStackTrace();
        }
        log.info("电子账簿查询完成=========:{}",balanceAcctResp);
    }
 
 
//    @ResponseBody
//    @RequestMapping(value = "/api/placeOrder/fenZhang", method = RequestMethod.POST)
//    @ApiOperation(value = "分账", tags = {"分账"}, notes = "")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
//    })
    public void fenZhang(){
        log.info("平台分账到司机电子账簿=========");
        AllocationReq allocationReq = userWithdrawalService.createAllocationReq("2007942595542621717", "2007942320163036794", 1,"123456");
        allocationReq.setOrderNo("202304041039329889826910");
        allocationReq.setPassword("123456");
        allocationReq.setOrderAmount(1L);
        allocationReq.setProductName("测试退货5(1111)");
        allocationReq.setProductCount(1);
        AllocationResp allocationResp = null;
        try {
            allocationResp = AllocationExample.create(allocationReq);
        } catch (UpyztException e) {
            log.error("平台分账到司机电子账簿失败:{}",e.getMessage());
            e.printStackTrace();
        }
        log.info("平台分账到司机电子账簿完成=========:{}",allocationResp);
    }
//    @ResponseBody
//    @RequestMapping(value = "/api/placeOrder/dianZi", method = RequestMethod.POST)
//    @ApiOperation(value = "电子账簿查询", tags = {"电子账簿查询"}, notes = "")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
//    })
    public void dianZi(){
        BalanceAcctListResp balanceAcctListResp = null;
        try {
            BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
            balanceAcctReq.setMchId("1008427961477222943");
            balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
            System.err.println(balanceAcctListResp);
        } catch (UpyztException e) {
            log.error("电子账簿查询失败:{}",e.getMessage());
            e.printStackTrace();
        }
        log.info("电子账簿查询完成=========:{}",balanceAcctListResp);
    }
 
//    @ResponseBody
//    @RequestMapping(value = "/api/placeOrder/tiXian", method = RequestMethod.POST)
//    @ApiOperation(value = "提现", tags = {"提现"}, notes = "")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
//    })
    public void tiXian(){
        WithdrawalResp balanceAcctResp = null;
        try {
 
            /*params.put("out_order_no", withdrawalReq.getOutOrderNo());
        params.put("amount", withdrawalReq.getAmount());
        params.put("balance_acct_id", withdrawalReq.getBalanceAcctId());
        params.put("bank_acct_no", Upyzt.encryptField(withdrawalReq.getBankAcctNo()));
        params.put("password", Upyzt.encryptField(withdrawalReq.getPassword()));*/
            WithdrawalReq withdrawalReq = new WithdrawalReq();
            withdrawalReq.setOutOrderNo(ToolUtil.getRandomString(32));
            withdrawalReq.setAmount(1);
            withdrawalReq.setBalanceAcctId("2007942320163036794");
            withdrawalReq.setBankAcctNo("149245719387");
            withdrawalReq.setPassword("123456");
            balanceAcctResp = WithdrawalExample.create(withdrawalReq);
            System.err.println(balanceAcctResp);
        } catch (UpyztException e) {
            System.err.println("提现失败:{}"+e.getMessage());
            e.printStackTrace();
        }
        log.info("提现完成=========:{}",balanceAcctResp);
    }
 
//    @ResponseBody
//    @RequestMapping(value = "/api/placeOrder/tiXianQuery", method = RequestMethod.POST)
//    @ApiOperation(value = "提现查询", tags = {"提现查询"}, notes = "")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
//    })
    public void tiXianQuery(){
        WithdrawalResp balanceAcctResp = null;
        try {
            balanceAcctResp = WithdrawalExample.retrieveById("3708203534784717899");
            System.err.println(balanceAcctResp);
        } catch (UpyztException e) {
            System.err.println("提现失败:{}"+e.getMessage());
            e.printStackTrace();
        }
        log.info("提现完成=========:{}",balanceAcctResp);
    }
 
}