puzhibing
2023-07-05 7a14e1592dd0c2cfd6cd4e8b11f95c9f46f2ffe7
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
package com.stylefeng.guns.modular.system.util.Tingg;
 
import com.alibaba.fastjson.JSON;
import com.stylefeng.guns.modular.system.util.HttpClientUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.util.Tingg.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 转账
 * @author zhibing.pu
 * @date 2023/3/17 9:48
 */
@Component
public class TinggPayoutUtil {
 
    @Autowired
    private RestTemplate restTemplate;
 
 
    /**
     * 转账接口
     * @param phone                 电话号码,带国家代码+233
     * @param payerTransactionID    支付单号
     * @param amount                支付金额
     * @param callbackUrl           回调地址
     * @param narration             备注
     * @return
     */
    public PayoutResponse sendPayout(String serviceCode, String phone, String payerTransactionID, Double amount, String callbackUrl, String narration) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Credentials credentials = new Credentials("igo_api_user", "mXo%kJM.p;_i)SSZ&^b?6XSH)D+OCPh8");
        List<Packet> packets = new ArrayList<>();
        Packet packet = new Packet();
        packet.setServiceCode(serviceCode);//手机网络运营商 GH-MTN-B2C、GH-TIGO-B2C、GH-VODAFONE-B2C、GH-AIRTEL-B2C
        packet.setMSISDN(phone);
        packet.setAccountNumber(phone);
        packet.setPayerTransactionID(payerTransactionID);
        packet.setAmount(amount);
        packet.setNarration(narration);
        packet.setDatePaymentReceived(sdf.format(new Date()));
        packet.setExtraData(new ExtraData(callbackUrl));
        packet.setCurrencyCode("GHS");
        packets.add(packet);
        Payload payload = new Payload(credentials, packets);
        Payout payout = new Payout("GH", "BEEP.postPayment", payload);
        String string = JSON.toJSONString(payout);
        string = string.replace("mSISDN", "MSISDN");
        System.err.println(string);
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("text/plain");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        HttpEntity<String> formEntity = new HttpEntity<>(string, headers);
 
        String url = "https://apps.cellulant.co.ke:9801/globalApi/v2/JSON/";
        String s = restTemplate.postForObject(url, formEntity, String.class);
        PayoutResponse payoutResponse = JSON.parseObject(s, PayoutResponse.class);
        System.err.println(s);
        return payoutResponse;
    }
 
 
 
}