puzhibing
2023-05-18 53562814add61acfdc02d6b25dae6324f6fd5f92
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
package com.stylefeng.guns.modular.system.util.Tingg;
 
/**
 * @author chenza
 * @date 2023/3/14 9:15
 */
 
import com.alibaba.fastjson.JSON;
import com.stylefeng.guns.modular.system.util.Tingg.model.TinggPayload;
import com.stylefeng.guns.modular.system.util.Tingg.model.TinggRequest;
import com.stylefeng.guns.modular.system.util.Tingg.model.TinggResponse;
 
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
 
/**
 * Tingg退款工具类
 */
public class TinggRefundUtil {
 
    private static String urlPath = "https://beep2.cellulant.africa:9001/paymentRouter/JSONV2/";
 
    public static void main(String[] args) {
        TinggRequest tinggRequest = new TinggRequest();
        //设置国家代码
        tinggRequest.setCountryCode("NG");
        //设置功能
        tinggRequest.setFunction("BEEP.postPayment");
        //设置用户名称
        tinggRequest.setUsername("sandboxUser");
        //设置用户密码
        tinggRequest.setPassword("sandboxPassword!");
        //设置服务代码
        tinggRequest.setServiceCode("NG-BANK-PAYOUT");
        //设置MSISDN
        tinggRequest.setMsisdn("256700000000");
        //设置账号
        tinggRequest.setAccountNumber("00072186");
        //设置付款人交易编号
        tinggRequest.setPayerTransactionID("yourUniqueID");
        //设置金额
        tinggRequest.setAmount(50000L);
        //设置备注
        tinggRequest.setNarration("Bank Payout");
        //设置收到付款的日期
        tinggRequest.setDatePaymentReceived(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        //设置回调网址
        tinggRequest.setCallbackUrl("https://yourCallBackUrl.com/receivePaymentStatus");
        //设置目的地银行代码
        tinggRequest.setDestinationBankCode("000012");
        //设置目标账户名称
        tinggRequest.setDestinationAccountName("Shem B. Mwangi");
        //设置目标账户号码
        tinggRequest.setDestinationAccountNo("00072186");
        //设置目的地银行
        tinggRequest.setDestinationBank("StanbicIBTC Bank");
        //设置支付方式
        tinggRequest.setPaymentMode("BANK");
        //设置货币代码
        tinggRequest.setCurrencyCode("NGN");
        //设置客户名称
        tinggRequest.setCustomerNames("Shem B. Mwangi");
        TinggResponse tinggResponse = getTinggResponse(tinggRequest);
        String s = JSON.toJSONString(tinggResponse);
        System.out.println(s);
        System.out.println("-------------");
        try {
            String post = new HttpsUtil().post(urlPath,s,"UTF-8");
            System.out.println(post);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    public static TinggResponse getTinggResponse(TinggRequest tinggRequest) {
        TinggResponse transferResponse = new TinggResponse();
        //设置国家代码
        transferResponse.setCountryCode(tinggRequest.getCountryCode());
        //设置功能
        transferResponse.setFunction(tinggRequest.getFunction());
        //获得有效载荷
        TinggPayload transferPayload = getTinggPayload(tinggRequest);
        //设置有效载荷
        transferResponse.setPayload(transferPayload);
        return transferResponse;
    }
 
    private static TinggPayload getTinggPayload(TinggRequest tinggRequest) {
        //有效载荷
        TinggPayload tinggPayload = new TinggPayload();
        //凭据
        HashMap<String, String> credentials = new LinkedHashMap<>();
        //设置用户名
        credentials.put("username", tinggRequest.getUsername());
        //设置支付密码
        credentials.put("password", tinggRequest.getPassword());
        //设置凭据
        tinggPayload.setCredentials(credentials);
 
        //有效负载的数据包
        ArrayList<Object> packet = new ArrayList<>();
        LinkedHashMap<String, Object> hs = getStringObjectHashMap(tinggRequest);
        packet.add(hs);
        //设置包
        tinggPayload.setPacket(packet);
        return tinggPayload;
    }
 
    private static LinkedHashMap<String, Object> getStringObjectHashMap(TinggRequest tinggRequest) {
        LinkedHashMap<String, Object> hs = new LinkedHashMap<>();
        //设置服务代码
        hs.put("serviceCode", tinggRequest.getServiceCode());
        hs.put("MSISDN", tinggRequest.getMsisdn());
        //设置账号
        hs.put("accountNumber", tinggRequest.getAccountNumber());
        //设置付款交易人编号
        hs.put("payerTransactionID", tinggRequest.getPayerTransactionID());
        //设置金额
        hs.put("amount", tinggRequest.getAmount());
        hs.put("narration", tinggRequest.getNarration());
        //设置付款时间
        hs.put("datePaymentReceived", tinggRequest.getDatePaymentReceived());
        //额外数据
        HashMap<String, String> tempHs = new LinkedHashMap<>();
        //回调网址
        tempHs.put("callbackUrl", tinggRequest.getCallbackUrl());
        //目的地银行代码
        tempHs.put("destinationBankCode", tinggRequest.getDestinationBankCode());
        //目标账户名称
        tempHs.put("destinationAccountName", tinggRequest.getDestinationAccountName());
        //目的地账户号码
        tempHs.put("destinationAccountNo", tinggRequest.getDestinationAccountNo());
        //目的地银行
        tempHs.put("destinationBank", tinggRequest.getDestinationBank());
        //设置额外数据
        hs.put("extraData", tempHs);
        //设置支付方式
        hs.put("paymentMode", tinggRequest.getPaymentMode());
        //设置货币代码
        hs.put("currencyCode", tinggRequest.getCurrencyCode());
        //设置客户名称
        hs.put("customerNames", tinggRequest.getCustomerNames());
        return hs;
    }
}