|
@@ -1,6 +1,7 @@
|
|
package com.zanxiang.sdk.service.Impl.pay;
|
|
package com.zanxiang.sdk.service.Impl.pay;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.zanxiang.common.constant.Constants;
|
|
import com.zanxiang.common.domain.ResultMap;
|
|
import com.zanxiang.common.domain.ResultMap;
|
|
import com.zanxiang.common.enums.ResEnum;
|
|
import com.zanxiang.common.enums.ResEnum;
|
|
import com.zanxiang.common.utils.RandomStringUtil;
|
|
import com.zanxiang.common.utils.RandomStringUtil;
|
|
@@ -21,10 +22,7 @@ import weixin.popular.api.SnsAPI;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
-import java.util.Iterator;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.SortedMap;
|
|
|
|
-import java.util.TreeMap;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author xufeng
|
|
* @author xufeng
|
|
@@ -76,8 +74,8 @@ public class WxpayServiceImpl extends PayService implements OrderPayService {
|
|
return this.mobile(product, "NATIVE");
|
|
return this.mobile(product, "NATIVE");
|
|
case 2:
|
|
case 2:
|
|
case 3:
|
|
case 3:
|
|
-// return this.mobile(product, "MWEB");
|
|
|
|
- return this.pc(product);
|
|
|
|
|
|
+ return this.mobile(product, "MWEB");
|
|
|
|
+// return this.pc(product);
|
|
case 4:
|
|
case 4:
|
|
return this.mp(product);
|
|
return this.mp(product);
|
|
default:
|
|
default:
|
|
@@ -131,7 +129,7 @@ public class WxpayServiceImpl extends PayService implements OrderPayService {
|
|
// 处理业务开始
|
|
// 处理业务开始
|
|
// ------------------------------
|
|
// ------------------------------
|
|
String resXml;
|
|
String resXml;
|
|
- if ("SUCCESS".equals(packageParams.get("result_code"))) {
|
|
|
|
|
|
+ if (Constants.SUCCESS.equalsIgnoreCase(packageParams.get("result_code").toString())) {
|
|
// 这里是支付成功
|
|
// 这里是支付成功
|
|
String orderNo = (String) packageParams.get("out_trade_no");
|
|
String orderNo = (String) packageParams.get("out_trade_no");
|
|
logger.info("微信订单号{}付款成功", orderNo);
|
|
logger.info("微信订单号{}付款成功", orderNo);
|
|
@@ -240,7 +238,7 @@ public class WxpayServiceImpl extends PayService implements OrderPayService {
|
|
totalFee = wxPayUtil.subZeroAndDot(this.totalFee);
|
|
totalFee = wxPayUtil.subZeroAndDot(this.totalFee);
|
|
packageParams.put("total_fee", totalFee);// 总金额
|
|
packageParams.put("total_fee", totalFee);// 总金额
|
|
packageParams.put("spbill_create_ip", product.getSpbillCreateIp());// 发起人IP地址
|
|
packageParams.put("spbill_create_ip", product.getSpbillCreateIp());// 发起人IP地址
|
|
- packageParams.put("notify_url", notifyUrl);// 回调地址
|
|
|
|
|
|
+ packageParams.put("notify_url", "https://localhost");// 回调地址 notifyUrl
|
|
packageParams.put("trade_type", trade_type);// 交易类型
|
|
packageParams.put("trade_type", trade_type);// 交易类型
|
|
packageParams.put("attach", JSONObject.toJSONString(this.attach));
|
|
packageParams.put("attach", JSONObject.toJSONString(this.attach));
|
|
|
|
|
|
@@ -262,16 +260,26 @@ public class WxpayServiceImpl extends PayService implements OrderPayService {
|
|
Map map = XMLUtil.doXMLParse(resXml);
|
|
Map map = XMLUtil.doXMLParse(resXml);
|
|
logger.info("订单号:{} 微信响应 map:{}", product.getOutTradeNo(), map);
|
|
logger.info("订单号:{} 微信响应 map:{}", product.getOutTradeNo(), map);
|
|
String returnCode = (String) map.get("return_code");
|
|
String returnCode = (String) map.get("return_code");
|
|
- if ("SUCCESS".equals(returnCode)) {
|
|
|
|
|
|
+ if (Constants.SUCCESS.equalsIgnoreCase(returnCode)) {
|
|
String resultCode = (String) map.get("result_code");
|
|
String resultCode = (String) map.get("result_code");
|
|
- if ("SUCCESS".equals(resultCode)) {
|
|
|
|
|
|
+ if (Constants.SUCCESS.equalsIgnoreCase(resultCode)) {
|
|
logger.info("订单号:{}生成微信支付码成功", product.getOutTradeNo());
|
|
logger.info("订单号:{}生成微信支付码成功", product.getOutTradeNo());
|
|
String urlCode = trade_type.equals("MWEB") ? (String) map.get("mweb_url") : (String) map.get("code_url");
|
|
String urlCode = trade_type.equals("MWEB") ? (String) map.get("mweb_url") : (String) map.get("code_url");
|
|
String imgName = this.outTradeNo + ".png";
|
|
String imgName = this.outTradeNo + ".png";
|
|
String imgPath = filePath + imgName;
|
|
String imgPath = filePath + imgName;
|
|
- ZxingUtil.createQRCodeImage(urlCode, imgPath);
|
|
|
|
- System.out.println(imgPath);
|
|
|
|
- return ResultMap.ok(product.getPayDevice(), urlCode);
|
|
|
|
|
|
+ HashMap<String, String> result = new HashMap<>();
|
|
|
|
+ if (trade_type.equals("MWEB")) {
|
|
|
|
+ try {
|
|
|
|
+ String shortUrl = wxPayUtil.shortUrl(urlCode);
|
|
|
|
+ if (!Constants.FAIL.equalsIgnoreCase(shortUrl)) {
|
|
|
|
+ result.put("AppLink", shortUrl);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logger.error("订单号:{} 生成微信app支付链接失败:{}", product.getOutTradeNo(), e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ result.put("fromData", urlCode);
|
|
|
|
+ return ResultMap.ok(product.getPayDevice(), result);
|
|
} else {
|
|
} else {
|
|
String errCodeDes = (String) map.get("err_code_des");
|
|
String errCodeDes = (String) map.get("err_code_des");
|
|
logger.error("订单号:{}生成微信支付码(系统)失败:{}", product.getOutTradeNo(), errCodeDes);
|
|
logger.error("订单号:{}生成微信支付码(系统)失败:{}", product.getOutTradeNo(), errCodeDes);
|