|
@@ -1,13 +1,23 @@
|
|
|
package com.yonge.cooleshow.biz.dal.sdk;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.JSONPath;
|
|
|
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import com.yonge.toolset.base.exception.ThirdpartyException;
|
|
|
import com.yonge.toolset.thirdparty.lingxinpay.Md5EncryptUtils;
|
|
|
import com.yonge.toolset.thirdparty.lingxinpay.RSA;
|
|
|
import com.yonge.toolset.utils.date.DateUtil;
|
|
|
import com.yonge.toolset.utils.http.HttpUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.HttpStatus;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -17,6 +27,7 @@ import java.io.IOException;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* @author: cy
|
|
@@ -152,8 +163,8 @@ public class WithdrawSdk {
|
|
|
* @param remark 备注(扩展字段) 只针对测试环境:只要参数合规都会返回交易成功,如果想要模拟交易失败,该字段值中含有“失败”二字即会失败。
|
|
|
* @return
|
|
|
*/
|
|
|
- public String withdraw(String outerOrderNo, String name, String mobile, String certificateNo, Integer predictAmount,
|
|
|
- String payAccount, String remark) {
|
|
|
+ public HttpResponseResult<Boolean> withdraw(String outerOrderNo, String name, String mobile, String certificateNo, Integer predictAmount,
|
|
|
+ String payAccount, String remark) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("outMemberNo", memberNo);
|
|
|
map.put("outerOrderNo", outerOrderNo);
|
|
@@ -193,11 +204,12 @@ public class WithdrawSdk {
|
|
|
try {
|
|
|
String resultJsonStr = HttpUtil.postForHttp(apiUrl + "/bpotop_trade/single", JSONObject.toJSONString(mapParam), null);
|
|
|
logger.info("单笔请求返回参数:{}", resultJsonStr);
|
|
|
- return resultJsonStr;
|
|
|
+ Map<String,Object> mapTypes = JSON.parseObject(resultJsonStr);
|
|
|
+ return HttpResponseResult.succeed(true);
|
|
|
} catch (IOException e) {
|
|
|
logger.info("发送失败:{}", e);
|
|
|
}
|
|
|
- return null;
|
|
|
+ return HttpResponseResult.failed("提现失败");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -237,4 +249,100 @@ public class WithdrawSdk {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public void test(){
|
|
|
+ //输入商户订单号
|
|
|
+ String outerOrderNo = UUID.randomUUID().toString().substring(0,12);
|
|
|
+ System.out.println(outerOrderNo);
|
|
|
+ //输入收款人手机号
|
|
|
+ String name = "何亮";
|
|
|
+ //输入收款人姓名
|
|
|
+ String mobile = "17600220933";
|
|
|
+ //输入收款人身份证号
|
|
|
+ String certificateNo = "130423199206192818";
|
|
|
+ //输入转账金额(单位分)
|
|
|
+ String predictAmount = "1";
|
|
|
+ //输入收款人账号
|
|
|
+ String payAccount = "6228480018864836772";
|
|
|
+ //输入卡类型:DC借记卡,CC信用卡(暂不支持)
|
|
|
+ String cardType = "DC";
|
|
|
+ //输入发放类型(0:工资,1:奖金,2:绩效,3:劳务,4:个人经营所得,5:其他)
|
|
|
+ String salaryType = "4";
|
|
|
+ //输入项目名称
|
|
|
+ String projectName = "测试";
|
|
|
+ //输入支付类型(1:银行卡)
|
|
|
+ String payType = "1";
|
|
|
+ //输入卡属性:(C:对私 ,B:对公)暂时不支持对公
|
|
|
+ String cardAttribute = "C";
|
|
|
+ String requestParam = doSign(outerOrderNo, name, mobile, certificateNo, predictAmount, payAccount, cardType,
|
|
|
+ salaryType, projectName, payType, cardAttribute);
|
|
|
+ String resultJsonStr = doPost("http://39.107.15.64:8090/bpotop_trade/single", requestParam);
|
|
|
+ System.out.println("单笔请求返回参数:{}"+resultJsonStr);
|
|
|
+ Map<String,Object> mapTypes = JSON.parseObject(resultJsonStr);
|
|
|
+ System.out.println(mapTypes);
|
|
|
+ }
|
|
|
+ private static String pk="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCYT5eCY6r8sGWgbiId/VqSZmS6XkBNGMkzUqTIkpkecOzsFBxFXTQmgDeR991YfgqmyOaHsJ/ons/H+e8l+RmHsOm4eErFU+9qXFq+k195YFV1vAR9O7MIG+FR5vmLDuhgimPsgqscWhUrGinc8RUpi5KwClgx7d+d8ZJ4GmkR0QIDAQAB";
|
|
|
+ private static String md5="0fd42370bad6485e46718b97f3dd1536";
|
|
|
+
|
|
|
+ public static String doSign(String outerOrderNo, String name, String mobile, String certificateNo, String predictAmount,
|
|
|
+ String payAccount, String cardType, String salaryType, String projectName, String payType, String cardAttribute){
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ //输入商户号
|
|
|
+ String memberNo = "1491663782974988288";
|
|
|
+
|
|
|
+ map.put("outMemberNo", memberNo);
|
|
|
+ map.put("outerOrderNo", outerOrderNo);
|
|
|
+ map.put("name", name);
|
|
|
+ map.put("certificateNo", certificateNo);
|
|
|
+ map.put("predictAmount", predictAmount);
|
|
|
+ String signs = Md5EncryptUtils.sign(map, md5);
|
|
|
+ map.put("charset", "UTF-8");
|
|
|
+ map.put("mobile", mobile);
|
|
|
+ map.put("version", "1.1");
|
|
|
+ map.put("service", "bpotop.zx.pay.order");
|
|
|
+ map.put("Md5Key", signs);
|
|
|
+ map.put("notifyUrl", "http://apis.bpotop.com/bpotop_trade/test");
|
|
|
+ map.put("cardType", cardType);
|
|
|
+ map.put("salaryType", salaryType);
|
|
|
+ map.put("projectName", projectName);
|
|
|
+ map.put("payType", payType);
|
|
|
+ map.put("cardAttribute", cardAttribute);
|
|
|
+ map.put("payAccount", payAccount);
|
|
|
+ String jsonStr = JSONObject.toJSONString(map);
|
|
|
+ try {
|
|
|
+ //使用公钥加密
|
|
|
+ String encryptStr = RSA.encryptPub(jsonStr,pk);
|
|
|
+ JSONObject mapParam = new JSONObject();
|
|
|
+ mapParam.put("outMemberNo",memberNo);
|
|
|
+ mapParam.put("signType","RSA");
|
|
|
+ mapParam.put("sign",encryptStr);
|
|
|
+ logger.info("单笔请求请求参数:{}",JSONObject.toJSONString(mapParam));
|
|
|
+ return JSONObject.toJSONString(mapParam);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("加密/发送失败:{}",e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String doPost(String url, String json) {
|
|
|
+ CloseableHttpClient httpclient = HttpClientBuilder.create().build();
|
|
|
+ HttpPost post = new HttpPost(url);
|
|
|
+ HttpGet get = new HttpGet(url);
|
|
|
+
|
|
|
+ String response = null;
|
|
|
+ try {
|
|
|
+ StringEntity s = new StringEntity(json,"UTF-8");
|
|
|
+// s.setContentEncoding("UTF-8");
|
|
|
+ // 发送json数据需要设置contentType
|
|
|
+ s.setContentType("application/json");
|
|
|
+ post.setEntity(s);
|
|
|
+ HttpResponse res = httpclient.execute(post);
|
|
|
+ if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
|
+ response = EntityUtils.toString(res.getEntity());// 返回json格式:
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
}
|