|
@@ -1,7 +1,8 @@
|
|
|
package com.yonge.cooleshow.biz.dal.sdk;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.yonge.cooleshow.biz.dal.props.WithdrawalProperties;
|
|
|
+import com.alibaba.fastjson.JSONPath;
|
|
|
+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;
|
|
@@ -9,7 +10,7 @@ import com.yonge.toolset.utils.http.HttpUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -25,8 +26,119 @@ import java.util.Map;
|
|
|
public class WithdrawSdk {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(WithdrawSdk.class);
|
|
|
|
|
|
- @Autowired
|
|
|
- private WithdrawalProperties withdrawalProperties;
|
|
|
+ // 商户号
|
|
|
+ @Value("${withdraw.memberNo}")
|
|
|
+ private String memberNo;
|
|
|
+ // 模板协议号
|
|
|
+ @Value("${withdraw.contractNo}")
|
|
|
+ private String contractNo;
|
|
|
+ @Value("${withdraw.md5Key}")
|
|
|
+ private String md5Key;
|
|
|
+ @Value("${withdraw.publicKey}")
|
|
|
+ private String publicKey;
|
|
|
+ //签署协议回调地址
|
|
|
+ @Value("${withdraw.contractNotifyUrl}")
|
|
|
+ private String contractNotifyUrl;
|
|
|
+ //签署协议url
|
|
|
+ @Value("${withdraw.contractApiUrl}")
|
|
|
+ private String contractApiUrl;
|
|
|
+ //提现回调地址
|
|
|
+ @Value("${withdraw.notifyUrl}")
|
|
|
+ private String notifyUrl;
|
|
|
+ //提现第三方url
|
|
|
+ @Value("${withdraw.apiUrl}")
|
|
|
+ private String apiUrl;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签署协议
|
|
|
+ *
|
|
|
+ * @param realName 真实姓名
|
|
|
+ * @param idcard 身份证号
|
|
|
+ * @param mobileNo 手机号
|
|
|
+ * @param serialNo 唯一标识
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean signContract(String realName, String idcard, String mobileNo, String serialNo) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("signType", "RSA");
|
|
|
+ jsonObject.put("service", "bpotop.zx.contract");
|
|
|
+ jsonObject.put("charset", "UTF-8");
|
|
|
+ jsonObject.put("version", "1.0");
|
|
|
+ jsonObject.put("createTime", DateUtil.format(new Date(), DateUtil.DEFAULT_PATTERN));
|
|
|
+
|
|
|
+ jsonObject.put("outMemberNo", memberNo);// 公司商户号
|
|
|
+ jsonObject.put("serialNo", serialNo);// 流水号(商户唯一标识)
|
|
|
+ jsonObject.put("contractNo", contractNo);// 合同模板号
|
|
|
+ jsonObject.put("notifyUrl", contractNotifyUrl);// 返回结果异步通知地址
|
|
|
+
|
|
|
+ JSONObject jsonObject2 = new JSONObject();
|
|
|
+ jsonObject2.put("name", realName);
|
|
|
+ jsonObject2.put("phone", mobileNo);
|
|
|
+ jsonObject2.put("identityId", idcard);
|
|
|
+ jsonObject2.put("citizenship", "0");
|
|
|
+ jsonObject2.put("signTime", DateUtil.format(new Date(), DateUtil.DEFAULT_PATTERN));
|
|
|
+ jsonObject.put("contractSignInfo", jsonObject2);
|
|
|
+ String jsonStr = JSONObject.toJSONString(jsonObject);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String encryptStr = RSA.encryptPub(jsonStr, publicKey);
|
|
|
+ jsonObject.put("sign", encryptStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("加密失败", e);
|
|
|
+ throw new ThirdpartyException("加密失败:{}", e.getMessage());
|
|
|
+ }
|
|
|
+ logger.info("[合同签署]请求参数:{}", jsonObject.toJSONString());
|
|
|
+ try {
|
|
|
+ String s = HttpUtil.postForHttp(contractApiUrl + "/api/signContract", jsonObject.toJSONString(), null);
|
|
|
+ logger.info("请求[合同签署]响应参数:{}", s);
|
|
|
+
|
|
|
+ jsonObject = JSONObject.parseObject(s);
|
|
|
+ if (StringUtils.equals(jsonObject.getString("return_code"), "T")) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ throw new ThirdpartyException("合同签署失败:{}", jsonObject.getString("content"));
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("请求[合同签署]接口报错", e);
|
|
|
+ throw new ThirdpartyException("请求[合同签署]接口报错:{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询协议
|
|
|
+ *
|
|
|
+ * @param serialNo 唯一标识
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String querySignContractResult(String serialNo) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("outMemberNo", memberNo);
|
|
|
+ jsonObject.put("serialNo", serialNo);
|
|
|
+ jsonObject.put("contractNo", contractNo);
|
|
|
+ try {
|
|
|
+ String encryptStr = RSA.encryptPub(JSONObject.toJSONString(jsonObject), publicKey);
|
|
|
+ jsonObject.put("sign", encryptStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("加密失败", e);
|
|
|
+ throw new ThirdpartyException("加密失败:{}", e.getMessage());
|
|
|
+ }
|
|
|
+ jsonObject.put("signType", "RSA");
|
|
|
+ jsonObject.put("service", "bpotop.zx.contract");
|
|
|
+ jsonObject.put("charset", "UTF-8");
|
|
|
+ jsonObject.put("version", "1.0");
|
|
|
+ jsonObject.put("createTime", DateUtil.format(new Date(), DateUtil.DEFAULT_PATTERN));
|
|
|
+ try {
|
|
|
+ String s = HttpUtil.postForHttp(contractApiUrl + "/api/queryContractInfo", jsonObject.toJSONString(), null);
|
|
|
+ logger.info("[合同查询]响应参数:{}", s);
|
|
|
+
|
|
|
+ jsonObject = JSONObject.parseObject(s);
|
|
|
+ if (StringUtils.equals(jsonObject.getString("return_code"), "T")) {
|
|
|
+ return (String) JSONPath.eval(jsonObject, "$.content.contractUrl");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("请求[合同查询]接口报错", e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 单笔提现
|
|
@@ -43,40 +155,33 @@ public class WithdrawSdk {
|
|
|
public String withdraw(String outerOrderNo, String name, String mobile, String certificateNo, Integer predictAmount,
|
|
|
String payAccount, String remark) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("outMemberNo", withdrawalProperties.getMemberNo());
|
|
|
+ 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, withdrawalProperties.getMd5Key());
|
|
|
+ String signs = Md5EncryptUtils.sign(map, md5Key);
|
|
|
|
|
|
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", withdrawalProperties.getNotifyUrl());
|
|
|
- //卡类型 DC 借记卡
|
|
|
+ map.put("notifyUrl", notifyUrl);
|
|
|
map.put("cardType", "DC");
|
|
|
- //输入发放类型(0:工资,1:奖金,2:绩效,3:劳务,4:个人经营所得,5:其他)
|
|
|
- map.put("salaryType", 4);
|
|
|
- map.put("projectName", name + DateUtil.format(new Date(), DateUtil.DEFAULT_PATTERN) + "提现");
|
|
|
- //支付类型(1:银行卡,2:支付宝,4:微信) 以实际业务为准
|
|
|
- map.put("payType", 1);
|
|
|
- //卡属性:(C:对私)
|
|
|
+ map.put("salaryType", "4");
|
|
|
+ map.put("projectName", name + "-" + DateUtil.getStrDate());
|
|
|
+ map.put("payType", "1");
|
|
|
map.put("cardAttribute", "C");
|
|
|
map.put("payAccount", payAccount);
|
|
|
- if (StringUtils.isNotBlank(remark)) {
|
|
|
- map.put("remark", remark);
|
|
|
- }
|
|
|
String jsonStr = JSONObject.toJSONString(map);
|
|
|
|
|
|
//签名
|
|
|
JSONObject mapParam = new JSONObject();
|
|
|
try {
|
|
|
//使用公钥加密
|
|
|
- String encryptStr = RSA.encryptPub(jsonStr, withdrawalProperties.getPublicKey());
|
|
|
- mapParam.put("outMemberNo", withdrawalProperties.getMemberNo());
|
|
|
+ String encryptStr = RSA.encryptPub(jsonStr, publicKey);
|
|
|
+ mapParam.put("outMemberNo", memberNo);
|
|
|
mapParam.put("signType", "RSA");
|
|
|
mapParam.put("sign", encryptStr);
|
|
|
logger.info("单笔请求请求参数:{}", JSONObject.toJSONString(mapParam));
|
|
@@ -86,7 +191,7 @@ public class WithdrawSdk {
|
|
|
|
|
|
//发送
|
|
|
try {
|
|
|
- String resultJsonStr = HttpUtil.postForHttp(withdrawalProperties.getApiUrl() + "/bpotop_trade/single", JSONObject.toJSONString(mapParam), null);
|
|
|
+ String resultJsonStr = HttpUtil.postForHttp(apiUrl + "/bpotop_trade/single", JSONObject.toJSONString(mapParam), null);
|
|
|
logger.info("单笔请求返回参数:{}", resultJsonStr);
|
|
|
return resultJsonStr;
|
|
|
} catch (IOException e) {
|
|
@@ -101,23 +206,35 @@ public class WithdrawSdk {
|
|
|
* @param outerOrderNo 商户唯一订单号
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public void query(String outerOrderNo) throws Exception {
|
|
|
+ public String query(String outerOrderNo) {
|
|
|
Map<String, Object> requestMap = new HashMap<>();
|
|
|
- requestMap.put("outMemberNo", withdrawalProperties.getMemberNo());
|
|
|
+ requestMap.put("outMemberNo", memberNo);
|
|
|
requestMap.put("outerOrderNo", outerOrderNo);
|
|
|
requestMap.put("service", "bpotop.zx.pay.order");
|
|
|
requestMap.put("version", "1.0");
|
|
|
requestMap.put("signType", "RSA");
|
|
|
requestMap.put("charset", "UTF-8");
|
|
|
String jsonStr = JSONObject.toJSONString(requestMap);
|
|
|
- String encryptStr = RSA.encryptPub(jsonStr, withdrawalProperties.getPublicKey());
|
|
|
+ String encryptStr = null;
|
|
|
+ try {
|
|
|
+ encryptStr = RSA.encryptPub(jsonStr, publicKey);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ThirdpartyException("加密失败:{}", e.getMessage());
|
|
|
+ }
|
|
|
|
|
|
Map<String, Object> requestMap2 = new HashMap<>();
|
|
|
- requestMap2.put("outMemberNo", withdrawalProperties.getMemberNo());
|
|
|
+ requestMap2.put("outMemberNo", memberNo);
|
|
|
requestMap2.put("sign", encryptStr);
|
|
|
logger.info("单笔查询请求参数:{}", JSONObject.toJSONString(requestMap2));
|
|
|
- String resultJsonStr = HttpUtil.postForHttp(withdrawalProperties.getApiUrl() + "/bpotop_trade/order_query", JSONObject.toJSONString(requestMap2), null);
|
|
|
- logger.info("单笔查询响应参数:{}", resultJsonStr);
|
|
|
+ String resultJsonStr = null;
|
|
|
+ try {
|
|
|
+ resultJsonStr = HttpUtil.postForHttp(apiUrl + "/bpotop_trade/order_query", JSONObject.toJSONString(requestMap2), null);
|
|
|
+ logger.info("单笔查询响应参数:{}", resultJsonStr);
|
|
|
+ return resultJsonStr;
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
}
|