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
package com.stylefeng.guns.modular.cloudPayment.example;
 
import com.stylefeng.guns.modular.cloudPayment.mock.MockData;
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
import com.unionpay.upyzt.Upyzt;
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.model.Allocation;
import com.unionpay.upyzt.resp.AllocationResp;
import com.unionpay.upyzt.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
 
import java.io.Serializable;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Slf4j
public class AllocationExample implements Serializable {
 
 
    /**
     * 分账
     *
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static AllocationResp create(AllocationReq allocationReq) throws UpyztException {
        Map<String, Object> params = new HashMap<>();
        params.put("out_order_no", allocationReq.getOutOrderNo());
        params.put("sent_at", OffsetDateTime.now().toString());
        params.put("pay_balance_acct_id", allocationReq.getPayBalanceAcctId());
 
        List<Map<String, Object>> transferParams = new ArrayList<>();
        Map<String, Object> transferParam = new HashMap<>();
        transferParam.put("recv_balance_acct_id", allocationReq.getRecvBalanceAcctId());
        transferParam.put("amount", allocationReq.getAmount());
//        transferParam.put("metadata", MockData.metadata());
        transferParam.put("extra", MockData.allocationExtra(allocationReq));
        transferParams.add(transferParam);
        params.put("transfer_params", transferParams);
        if(!StringUtils.isBlank(allocationReq.getPassword())){
            params.put("password", Upyzt.encryptField(allocationReq.getPassword()));
        }
//        params.put("remark", "用于 SDK 示例测试 ");
 
        return Allocation.create(params);
    }
 
 
    /**
     * 分账订单查询(系统订单号)
     *
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static AllocationResp retrieveById(String allocationId) throws UpyztException {
        return Allocation.retrieveById(allocationId);
    }
 
    /**
     * 分账订单查询(平台订单号)
     *
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public AllocationResp retrieveByOutOrderNo(String outOrderNo) throws UpyztException {
        return Allocation.retrieveByOutOrderNo(outOrderNo);
    }
 
}