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
package com.stylefeng.guns.modular.account.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.util.GetOpenBodySig;
import com.stylefeng.guns.core.util.NotifyDemo;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.CharteredCar.model.OrderCharteredCar;
import com.stylefeng.guns.modular.CharteredCar.server.IOrderCharteredCarService;
import com.stylefeng.guns.modular.account.model.TEnterpriseWithdrawal;
import com.stylefeng.guns.modular.account.server.ITEnterpriseWithdrawalService;
import com.stylefeng.guns.modular.account.server.UserWithdrawalService;
import com.stylefeng.guns.modular.account.util.Base64Util;
import com.stylefeng.guns.modular.account.util.QrCodeConfiguration;
import com.stylefeng.guns.modular.account.util.Util;
import com.stylefeng.guns.modular.cloudPayment.example.AllocationExample;
import com.stylefeng.guns.modular.cloudPayment.example.DepositExample;
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
import com.stylefeng.guns.modular.cloudPayment.req.DepositReq;
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.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.dao.UserInfoMapper;
import com.stylefeng.guns.modular.system.model.Company;
import com.stylefeng.guns.modular.system.model.Driver;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.model.UserWithdrawal;
import com.stylefeng.guns.modular.system.service.ICompanyService;
import com.stylefeng.guns.modular.system.service.IDriverService;
import com.stylefeng.guns.modular.system.service.ITaxiCardService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.taxi.model.TransactionDetails;
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.resp.AllocationResp;
import com.unionpay.upyzt.resp.DepositResp;
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.apache.shiro.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
/**
 * @program: openPlatform
 * @description: 下单
 */
@Api(tags = "下单")
@Slf4j
@RestController
@RequestMapping("/api/placeOrder")
public class AppOrderController {
 
 
    @Autowired
    private IOrderCharteredCarService orderCharteredCarService;
 
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
 
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
 
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
 
    @Autowired
    private IOrderTaxiService orderTaxiService;
 
    @Autowired
    private IUserInfoService userInfoService;
 
 
    @Autowired
    private ITaxiCardService taxiCardService;
 
    @Autowired
    private ITEnterpriseWithdrawalService enterpriseWithdrawalService;
 
    private final ICompanyService companyService;
    private final QrCodeConfiguration qrCodeConfiguration;
    private final UserWithdrawalService userWithdrawalService;
 
    public AppOrderController(ICompanyService companyService, QrCodeConfiguration qrCodeConfiguration, UserWithdrawalService userWithdrawalService) {
        this.companyService = companyService;
        this.qrCodeConfiguration = qrCodeConfiguration;
        this.userWithdrawalService = userWithdrawalService;
    }
 
 
 
 
    /**
     * app下单
     *
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/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 = "支付金额", name = "amount", required = true, dataType = "BigDecimal"),
            @ApiImplicitParam(value = "支付方式 1=微信,2=支付宝,4=云闪付", name = "type", required = true, dataType = "Integer"),
            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "Integer"),
            @ApiImplicitParam(value = "0感谢费 不用管 1专车OrderPrivateCar取消 2跨城感谢费  3跨成订单OrderCrossCity  4跨城取消订单 orderCrossCity  5小件物流OrderLogistics 6专车OrderPrivateCar 7用户余额充值 8出租车取消 OrderTaxi 9出租车订单OrderTaxi" +
                    "10 小件物流感谢费  11专车感谢费 12出租车感谢费" +
                    "", name = "types", required = true, dataType = "Integer"),
    })
    public ResultUtil placeAnOrder(BigDecimal amount, Integer type,Integer orderId,Integer types,Integer paymentId) 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", "898150841210108"); // 商户号
        json.put("tid", qrCodeConfiguration.getTid());    // 终端号
        json.put("instMid", qrCodeConfiguration.getInstMid()); // 业务类型
        BigDecimal multiply = amount.multiply(new BigDecimal(100));
        int money = multiply.intValue();
        json.put("totalAmount",money);      // 支付总金额
        json.put("orderDesc", ""); // 订单描述
        json.put("subAppId", "wxasdasdasdasdads");
        json.put("notifyUrl", "https://zhentonggongsi.com:443/user/api/placeOrder/notifyUrl");
        json.put("tradeType", "APP");  // 交易类型,微信必传
        json.put("srcReserve", orderId+"_"+types+"_"+paymentId);  // 交易类型,微信必传
 
        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(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);
    }
 
 
    public ResultUtil cancleMoney(BigDecimal amount) 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", "898150841210108"); // 商户号
        json.put("tid", qrCodeConfiguration.getTid());    // 终端号
        json.put("instMid", qrCodeConfiguration.getInstMid()); // 业务类型
        BigDecimal multiply = amount.multiply(new BigDecimal(100));
        int money = multiply.intValue();
        json.put("refundAmount",money);      // 支付总金额
        System.err.println("请求报文json:\n" + json);
        String  url = "https://test-api-open.chinaums.com/v1/netpay/refund";
//        String  url = "https://api-mop.chinaums.com/v1/netpay/refund";
        //OPEN-BODY-SIG 方式
        String result = GetOpenBodySig.sendOpenBodySig(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);
    }
 
    public static void main(String[] args) throws Exception {
        JSONObject json = new JSONObject();
        json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));    // 报文请求时间
        json.put("merOrderId", "34U02023062418175413584261700"); // 商户订单号
        json.put("mid", "898150841210108"); // 商户号
        json.put("tid", "W4U185RJ");    // 终端号
        json.put("instMid", "QRPAYDEFAULT"); // 业务类型
        BigDecimal multiply = new BigDecimal(1);
        int money = multiply.intValue();
        json.put("refundAmount",money);      // 支付总金额
        System.err.println("请求报文json:\n" + json);
//        String  url = "https://test-api-open.chinaums.com/v1/netpay/refund";
        String  url = "https://api-mop.chinaums.com/v1/netpay/refund";
        //OPEN-BODY-SIG 方式
        String result = GetOpenBodySig.sendOpenBodySig(url, json.toString());
        System.err.println("响应报文json:\n" + result);
        JSONObject jsonObject = JSONObject.parseObject(result);
        Object appPayRequest = jsonObject.get("appPayRequest");
        System.out.println(appPayRequest);
    }
 
 
    @PostMapping(value = "/notifyUrl")
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.SUPPORTS)
    public void notifyUrl(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("status");// 状态
        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");// 预留字段
        // 验签
        //对通知内容生成sign
        String strSign = NotifyDemo.makeSign(qrCodeConfiguration.getMd5key(),params);
        System.out.println(billStatus);
        //判断签名是否相等
        if (sign.equals(strSign)) {
            if("TRADE_SUCCESS".equals(billStatus)){
 
                String[] split = srcReserve.split("_");
                /*
                1专车取消订单 2组老模式OrderCall  3跨成订单OrderCrossCity
                4跨城取消订单 orderCrossCity  5小件物流OrderLogistics 6专车OrderPrivateCar
                 7用户余额充值 8出租车取消 OrderTaxi 9出租车订单OrderTaxi
                 */
                Integer integer = Integer.valueOf(split[1]);
                Integer orderId = Integer.valueOf(split[0]);
                Integer paymentId = Integer.valueOf(split[2]);
                System.out.println("订单类型:"+integer);
                System.out.println("预留:"+srcReserve);
 
                if(integer==3){
                    orderCrossCityService.payOrderCrossCityCallback(orderId,"",4,targetOrderId);
                }
                if(integer==4){
                    orderCrossCityService.payCancelOrderCrossCity(orderId,"",4);
                }
                if(integer==5){
                    orderLogisticsService.payOrderLogisticsCallback(orderId,",",4);
                }
                if(integer==6){
                    orderPrivateCarService.payOrderPrivateCarCallback(orderId,",",4);
                }
                if(integer==9){
                    orderTaxiService.payOrderTaxiCallback(orderId,"",4,paymentId);
                }
                if(integer==1){
                    orderPrivateCarService.payCancelOrderPrivateCar(orderId,",",4);
                }
                if(integer==8){
                    orderTaxiService.payCancelOrderTaxi(orderId,"",4);
                }
                if(integer==2){
                    orderCrossCityService.payThankYouFeeCallback(orderId,targetOrderId,4);
                }
 
                if(integer==10){
                    orderLogisticsService.payThankYouFeeCallback(orderId,targetOrderId,4);
                }
                if(integer==11){
                    orderPrivateCarService.payThankYouFeeCallback(orderId,targetOrderId,4);
                }
                if(integer==12){
                    orderTaxiService.payThankYouFeeCallback(orderId,targetOrderId,4);
                }
                if(integer==13){  //补差价
                    orderLogisticsService.payOrderLogisticsSpreadCallback(orderId,targetOrderId,4);
                }
                if(integer==14){
                    taxiCardService.payTaxiCardPaymentSpread(orderId,targetOrderId);
                }
 
                // 调用支付充值接口,将金额充值到平台账户
                // 查询平台账户
                Company company = companyService.selectOne(new EntityWrapper<Company>()
                        .eq("type", 1)
                        .last("LIMIT 1"));
                // 查询平台开户信息
                TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
                        .eq("companyId", company.getId())); // TODO 替换为公司id
 
                DepositReq depositReq = new DepositReq();
 
 
                if(integer==7){  // 充值回调
                    userInfoService.payCancelUserBalance(orderId,"",paymentId,4);
                    UserInfo userInfo = userInfoService.selectById(orderId);
                    UserWithdrawal driverWith = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
                            .eq("phone", userInfo.getPhone())
                            .last("LIMIT 1"));
                    createAllocationReqUser(1,orderId,1,new BigDecimal(totalAmount).divide(new BigDecimal(100)).doubleValue());
//                    depositReq.setOutOrderNo(ToolUtil.getRandomString(32));
//                    depositReq.setTotalAmount(totalAmount); // 总金额
//                    depositReq.setAmount(buyerPayAmount); // 支付金额
//                    depositReq.setDiscountAmount(couponAmount); // 优惠金额
//                    depositReq.setBalanceAcctId(driverWith.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()));
//                    depositReq.setOrderNo(targetOrderId);
//                    depositReq.setOrderAmount(Long.valueOf(totalAmount));
//                    depositReq.setProductName("用户支付充值");
//                    depositReq.setProductCount(1);
                }
                    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()));
                    depositReq.setOrderNo(targetOrderId);
                    depositReq.setOrderAmount(Long.valueOf(totalAmount));
                    depositReq.setProductName("用户支付充值");
                    depositReq.setProductCount(1);
 
                try {
//                    DepositResp depositResp = DepositExample.create(depositReq);
//                    System.err.println(depositResp);
//                    log.info("支付充值成功:{}",depositResp);
                } 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("验签未通过!");
            System.out.println("验签未通过!");
            PrintWriter writer = response.getWriter();
            response.setStatus(200);
            writer.write("FAILED");
        }
        //跳转支付完成页面
//        return "/WEB-INF/views/jsp/payResult.jsp";
    }
 
 
    @RequestMapping(value = "/notifyUrlOne", method = RequestMethod.POST)
    public void notifyUrl(String event_id,String event_type, Map event_data, String created_at,HttpServletResponse response){
        System.out.println("支付充值回调+++++++++");
        System.out.println(event_id);
        System.out.println(event_type);
        System.out.println(event_data);
        System.out.println(created_at);
        try {
            PrintWriter writer = response.getWriter();
            writer.print(200);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
 
    public  ResultUtil moneyPay(Integer id,Integer userId,Double money){
 
        Company company = companyService.selectOne(new EntityWrapper<Company>()
                .eq("type", 1)
                .last("LIMIT 1"));
        // 查询平台开户信息
        TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
                .eq("companyId", company.getId()));
        UserInfo userInfo = userInfoService.selectById(userId);
        System.out.println("用户信息:"+userInfo);
        UserWithdrawal driverWith = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
                .eq("phone", userInfo.getPhone())
                .last("LIMIT 1"));
        System.out.println("用户进件信息:"+driverWith);
        if(driverWith==null){
            return ResultUtil.error("领取失败,请先设置进件信息");
        }
        AllocationReq allocationReq = new AllocationReq();
        allocationReq.setOutOrderNo(ToolUtil.getRandomString(32));
        allocationReq.setProductCount(1);
        allocationReq.setPayBalanceAcctId(driverWith.getBalanceAcctId());
//        allocationReq.setPayBalanceAcctId("2008322294132024868");
        allocationReq.setOrderAmount((long) (money*100));
        allocationReq.setAmount((int) (money*100));
        allocationReq.setProductName("余额支付");
        allocationReq.setRecvBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId());
//        allocationReq.setRecvBalanceAcctId("2007982285722883157");
        allocationReq.setOrderNo(id.toString());
        allocationReq.setPassword(Base64Util.decode(driverWith.getTransactionAuthorizationCode()));
//        allocationReq.setPassword("MTIzNDU2");
        System.out.println("余额支付请求信息:"+allocationReq);
        try {
 
            AllocationResp allocationResp = AllocationExample.create(allocationReq);
            System.out.println("余额支付操作:"+allocationResp);
            return ResultUtil.success();
        } catch (UpyztException e) {
            e.printStackTrace();
            System.out.println("余额支付操作error:"+e);
            System.out.println(e.getIssue());
            return ResultUtil.error(e.getMessage());
        }
    }
 
 
    public String createAllocationReqUser(Integer companyId,Integer userId,int type,double money){
        List<TEnterpriseWithdrawal> tEnterpriseWithdrawals = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", companyId));
        UserInfo tUser = userInfoService.selectById(userId);
        List<UserWithdrawal> userWithdrawals = userWithdrawalService.selectList(new EntityWrapper<UserWithdrawal>().eq("phone", tUser.getPhone()));
        if(userWithdrawals.size()==0){
            return "error";
        }
 
        AllocationReq allocationReq= new AllocationReq();
        allocationReq.setOutOrderNo(ToolUtil.getRandomString(32));
        if(type==1){
            allocationReq.setPayBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setRecvBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
 
            allocationReq.setPassword(Base64Util.decode(tEnterpriseWithdrawals.get(0).getTransactionAuthorizationCode()));
        }else {
            allocationReq.setRecvBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setPayBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setPassword(Base64Util.decode(userWithdrawals.get(0).getTransactionAuthorizationCode()));
        }
        money=money*100;
        allocationReq.setAmount((int)money);
        allocationReq.setProductName("分账");
        allocationReq.setProductCount(1);
        allocationReq.setOrderNo(ToolUtil.getRandomString(32));
        allocationReq.setOrderAmount(1l);
        try {
            AllocationResp allocationResp = AllocationExample.create(allocationReq);
            System.out.println(allocationResp);
            return "ok";
        } catch (UpyztException e) {
            e.printStackTrace();
            return e.getMessage();
        }
 
    }
 
    @Autowired
    private IDriverService driverService;
    public String createAllocationReqDriver(Integer companyId,Integer userId,int type,double money){
        List<TEnterpriseWithdrawal> tEnterpriseWithdrawals = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", companyId));
        Driver tUser = driverService.selectById(userId);
        List<UserWithdrawal> userWithdrawals = userWithdrawalService.selectList(new EntityWrapper<UserWithdrawal>().eq("phone", tUser.getPhone()));
        if(userWithdrawals.size()==0){
            return "error";
        }
 
        AllocationReq allocationReq= new AllocationReq();
        allocationReq.setOutOrderNo(ToolUtil.getRandomString(32));
        if(type==1){
            allocationReq.setPayBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setRecvBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
 
            allocationReq.setPassword(Base64Util.decode(tEnterpriseWithdrawals.get(0).getTransactionAuthorizationCode()));
        }else {
            allocationReq.setRecvBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setPayBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setPassword(Base64Util.decode(userWithdrawals.get(0).getTransactionAuthorizationCode()));
        }
        money=money*100;
        allocationReq.setAmount((int)money);
        allocationReq.setProductName("分账");
        allocationReq.setProductCount(1);
        allocationReq.setOrderNo(ToolUtil.getRandomString(32));
        allocationReq.setOrderAmount(1l);
        try {
            AllocationResp allocationResp = AllocationExample.create(allocationReq);
            System.out.println(allocationResp);
            return "ok";
        } catch (UpyztException e) {
            e.printStackTrace();
            return e.getMessage();
        }
 
    }
}