|
@@ -1,6 +1,5 @@
|
|
|
package com.zanxiang.sdk.service.Impl.pay;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.zanxiang.common.constant.Constants;
|
|
|
import com.zanxiang.common.domain.ResultMap;
|
|
|
import com.zanxiang.common.enums.ResEnum;
|
|
@@ -8,7 +7,10 @@ import com.zanxiang.common.exception.BaseException;
|
|
|
import com.zanxiang.common.utils.JsonUtil;
|
|
|
import com.zanxiang.common.utils.RandomStringUtil;
|
|
|
import com.zanxiang.common.utils.URIUtil;
|
|
|
-import com.zanxiang.sdk.common.util.*;
|
|
|
+import com.zanxiang.sdk.common.constant.WxPayConstants;
|
|
|
+import com.zanxiang.sdk.common.util.PayCommonUtil;
|
|
|
+import com.zanxiang.sdk.common.util.WxPayUtil;
|
|
|
+import com.zanxiang.sdk.common.util.XmlUtil;
|
|
|
import com.zanxiang.sdk.domain.bo.ProductPayAttachParamBO;
|
|
|
import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
|
|
|
import com.zanxiang.sdk.domain.bo.WxPayConfigBO;
|
|
@@ -72,8 +74,6 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
*/
|
|
|
private WxPayConfigBO config;
|
|
|
|
|
|
- private WxPayUtil wxPayUtil;
|
|
|
-
|
|
|
private String body;
|
|
|
|
|
|
private String totalFee;
|
|
@@ -83,13 +83,6 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 支付调起
|
|
|
- *
|
|
|
- * @param product
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
public ResultMap create(ProductPayParamBO product) {
|
|
|
this.body = product.getSubject();
|
|
@@ -128,7 +121,7 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
inputStream.close();
|
|
|
log.info("微信支付回调 body:{}", sb);
|
|
|
// 解析xml成map
|
|
|
- Map m = XMLUtil.xmlToMap(sb.toString());
|
|
|
+ Map m = XmlUtil.xmlToMap(sb.toString());
|
|
|
// 过滤空 设置 TreeMap
|
|
|
SortedMap<Object, Object> packageParams = new TreeMap<>();
|
|
|
for (Object parameter : m.keySet()) {
|
|
@@ -205,7 +198,7 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
//转换deepLink
|
|
|
String deepLink;
|
|
|
try {
|
|
|
- deepLink = wxPayUtil.readUrl(urlCode, serverUrl);
|
|
|
+ deepLink = WxPayUtil.readUrl(urlCode, serverUrl);
|
|
|
} catch (Exception e) {
|
|
|
log.error("微信h5支付urlCode转deepLink异常, urlCode:{}", urlCode);
|
|
|
throw new BaseException("微信h5支付urlCode转deepLink异常");
|
|
@@ -261,72 +254,6 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * H5手机支付(jspapi)
|
|
|
- *
|
|
|
- * @param product
|
|
|
- * @return
|
|
|
- */
|
|
|
- private ResultMap mobile(ProductPayParamBO product, String tradeType) {
|
|
|
- //商户支付回调URL设置指引:进入公众平台-->微信支付-->开发配置-->扫码支付-->修改 加入回调URL
|
|
|
- log.info("订单号:{}生成微信支付码", product.getOutTradeNo());
|
|
|
- try {
|
|
|
- // 账号信息
|
|
|
- String key = config.getApiKey();
|
|
|
- SortedMap<Object, Object> packageParams = new TreeMap<>();
|
|
|
- wxPayUtil.commonParams(packageParams);
|
|
|
- // 商品描述
|
|
|
- packageParams.put("body", this.body);
|
|
|
- // 商户订单号
|
|
|
- packageParams.put("out_trade_no", this.outTradeNo);
|
|
|
- totalFee = WxPayUtil.subZeroAndDot(this.totalFee);
|
|
|
- // 总金额
|
|
|
- packageParams.put("total_fee", totalFee);
|
|
|
- // 发起人IP地址
|
|
|
- packageParams.put("spbill_create_ip", product.getSpbillCreateIp());
|
|
|
- // 回调地址 notifyUrl
|
|
|
- packageParams.put("notify_url", notifyUrl);
|
|
|
- // 交易类型
|
|
|
- packageParams.put("trade_type", tradeType);
|
|
|
- packageParams.put("attach", JSONObject.toJSONString(this.attach));
|
|
|
- String sign = PayCommonUtil.createSign(Constants.UTF8, packageParams, key);
|
|
|
- packageParams.put("sign", sign);
|
|
|
- String requestXml = PayCommonUtil.getRequestXml(packageParams);
|
|
|
- String resXml = HttpUtil.postData(WxPayUrl.UNIFIED_ORDER_URL, requestXml);
|
|
|
- Map map = XMLUtil.xmlToMap(resXml);
|
|
|
- if (map == null) {
|
|
|
- log.error("微信支付通信异常, 订单号:{}", product.getOutTradeNo());
|
|
|
- return ResultMap.error();
|
|
|
- }
|
|
|
- String returnCode = (String) map.get("return_code");
|
|
|
- //返回失败
|
|
|
- if (!Constants.SUCCESS.equalsIgnoreCase(returnCode)) {
|
|
|
- String returnMsg = (String) map.get("return_msg");
|
|
|
- log.error("微信支付通信失败, 订单号:{}, msg :{}", product.getOutTradeNo(), returnMsg);
|
|
|
- return ResultMap.error(returnMsg);
|
|
|
- }
|
|
|
- //结果失败
|
|
|
- String resultCode = (String) map.get("result_code");
|
|
|
- if (!Constants.SUCCESS.equalsIgnoreCase(resultCode)) {
|
|
|
- String errCodeDes = (String) map.get("err_code_des");
|
|
|
- log.error("微信支付通信失败, 订单号:{}, errCodeDes :{}", product.getOutTradeNo(), errCodeDes);
|
|
|
- return ResultMap.error(errCodeDes);
|
|
|
- }
|
|
|
- if (tradeType.equals(WX_PAY_MWEB)) {
|
|
|
- String urlCode = wxPayUtil.readUrl((String) map.get("mweb_url"), serverUrl);
|
|
|
- return ResultMap.ok(product.getPayDevice(), urlCode);
|
|
|
- }
|
|
|
- if (tradeType.equals(WX_PAY_NATIVE)) {
|
|
|
- String urlCode = (String) map.get("code_url");
|
|
|
- return ResultMap.ok(product.getPayDevice(), urlCode);
|
|
|
- }
|
|
|
- return ResultMap.ok(product.getPayDevice(), null);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("微信支付通信异常, 订单号:{}, e : {}", product.getOutTradeNo(), e.getMessage());
|
|
|
- return ResultMap.error();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private Map<String, String> unifiedOrder(ProductPayParamBO product, String tradeType, String openId) {
|
|
|
try {
|
|
|
Map<String, String> paramData = new HashMap<>(13);
|
|
@@ -350,8 +277,8 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
String sign = WxPayUtil.generateSignature(paramData, config.getApiKey());
|
|
|
paramData.put("sign", sign);
|
|
|
// 下单, 获取结果
|
|
|
- String result = restTemplate.postForObject(WxPayUrl.UNIFIED_ORDER_URL, XMLUtil.mapToXml(paramData), String.class);
|
|
|
- Map<String, String> successMap = XMLUtil.xmlToMap(result);
|
|
|
+ String result = restTemplate.postForObject(WxPayConstants.UNIFIED_ORDER_URL, XmlUtil.mapToXml(paramData), String.class);
|
|
|
+ Map<String, String> successMap = XmlUtil.xmlToMap(result);
|
|
|
// 返回状态码
|
|
|
String returnCode = successMap.get("return_code");
|
|
|
// 结果状态码
|
|
@@ -374,7 +301,6 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void configInit(String obj) {
|
|
|
- this.config = JSONObject.parseObject(obj, WxPayConfigBO.class);
|
|
|
- this.wxPayUtil = new WxPayUtil(this.config);
|
|
|
+ this.config = JsonUtil.toObj(obj, WxPayConfigBO.class);
|
|
|
}
|
|
|
}
|