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;
|
}
|
|
|
|
}
|