| | |
| | | package com.stylefeng.guns.modular.system.util.Tingg; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | 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.TokenResponse; |
| | | import org.apache.http.protocol.HTTP; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.net.HttpURLConnection; |
| | | import java.util.Calendar; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.TimeZone; |
| | | |
| | | /** |
| | | * Tingg支付工具类 |
| | | */ |
| | | @Component |
| | | public class TinggPayUtil { |
| | | |
| | | @Autowired |
| | | private HttpClientUtil httpClientUtil; |
| | | |
| | | /** |
| | | * 获取token |
| | | * @return |
| | | */ |
| | | public TokenResponse getToken(){ |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("grant_type", "client_credentials"); |
| | | params.put("client_id", TinggConfigEnum.CLIENT_ID.getValue()); |
| | | params.put("client_secret", TinggConfigEnum.CLIENT_SECRET.getValue()); |
| | | |
| | | String s = httpClientUtil.pushHttpRequset("POST", TinggConfigEnum.TOKEN_URL.getValue(), params, null, "json"); |
| | | if(ToolUtil.isNotEmpty(s)){ |
| | | TokenResponse tokenResponse = JSON.parseObject(s, TokenResponse.class); |
| | | return tokenResponse; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | public ResultUtil checkoutRequest(String phone, String email, Double amount){ |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("merchantTransactionID", "");//商家的唯一交易标识符 |
| | | params.put("currencyCode", "");//通过的金额所使用的货币 |
| | | params.put("requestAmount", amount);//客户将要支付的总金额 |
| | | params.put("countryCode", "");//商家的默认国家代码 |
| | | params.put("accountNumber", "");//交易的帐号/参考编号 |
| | | params.put("serviceCode", "");//商户的服务代码 |
| | | Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| | | params.put("dueDate", "");//事务到期日期的格式为YYYY-MM-DD HH:mm:ss。这应该是UTC时间 |
| | | params.put("requestDescription", "");//事务的叙述 |
| | | params.put("customerFirstName", "");//顾客名称 |
| | | params.put("customerLastName", "");//客户的姓氏 |
| | | params.put("MSISDN", phone);//客户的手机号码 |
| | | params.put("customerEmail", email);//客户的邮件 |
| | | params.put("paymentWebhookUrl", "");//这是结帐将使用的URL,用相关的支付细节调用商家,以便商家确认支付 |
| | | |
| | | Map<String, String> header = new HashMap<>(); |
| | | TokenResponse token = getToken(); |
| | | if(null == token || ToolUtil.isNotEmpty(token.getError())){ |
| | | System.err.println("调用支付异常,获取token凭证失败!【" + token.getError() + "-----" + token.getMessage() + "】"); |
| | | return ResultUtil.error("调用支付异常"); |
| | | } |
| | | header.put("Authorization", "Bearer " + token.getAccess_token()); |
| | | header.put("Content-Type", "application/json"); |
| | | |
| | | String s = httpClientUtil.pushHttpRequset("POST", TinggConfigEnum.CHECKOUT_URL.getValue(), params, header, "json"); |
| | | if(ToolUtil.isNotEmpty(s)){ |
| | | |
| | | } |
| | | } |
| | | } |