|
@@ -1,8 +1,6 @@
|
|
package com.zanxiang.sdk.service.Impl.pay;
|
|
package com.zanxiang.sdk.service.Impl.pay;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
|
import com.alipay.easysdk.factory.Factory;
|
|
import com.alipay.easysdk.factory.Factory;
|
|
import com.alipay.easysdk.kernel.Config;
|
|
import com.alipay.easysdk.kernel.Config;
|
|
import com.alipay.easysdk.kernel.util.ResponseChecker;
|
|
import com.alipay.easysdk.kernel.util.ResponseChecker;
|
|
@@ -10,22 +8,23 @@ import com.alipay.easysdk.payment.app.models.AlipayTradeAppPayResponse;
|
|
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
|
|
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
|
|
import com.alipay.easysdk.payment.wap.models.AlipayTradeWapPayResponse;
|
|
import com.alipay.easysdk.payment.wap.models.AlipayTradeWapPayResponse;
|
|
import com.zanxiang.common.domain.ResultMap;
|
|
import com.zanxiang.common.domain.ResultMap;
|
|
-import com.zanxiang.common.enums.OrderStateEnum;
|
|
|
|
|
|
+import com.zanxiang.common.enums.HttpStatusEnum;
|
|
import com.zanxiang.common.enums.ResEnum;
|
|
import com.zanxiang.common.enums.ResEnum;
|
|
-import com.zanxiang.common.utils.URIUtil;
|
|
|
|
-import com.zanxiang.sdk.domain.bo.PlatformOrderBO;
|
|
|
|
import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
|
|
import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
|
|
import com.zanxiang.sdk.service.OrderPayService;
|
|
import com.zanxiang.sdk.service.OrderPayService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
-import java.math.BigDecimal;
|
|
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.Enumeration;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author xufeng
|
|
* @author xufeng
|
|
@@ -33,11 +32,15 @@ import java.util.*;
|
|
*/
|
|
*/
|
|
@Component
|
|
@Component
|
|
@Slf4j
|
|
@Slf4j
|
|
-@Service
|
|
|
|
|
|
+@Service("AlipayService")
|
|
public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
private static final Logger logger = LoggerFactory.getLogger(AlipayServiceImpl.class);
|
|
private static final Logger logger = LoggerFactory.getLogger(AlipayServiceImpl.class);
|
|
|
|
|
|
- private String returnUrl = "http://localhost/pay/notify";
|
|
|
|
|
|
+ @Value("payConfig.alipay.returnUrl")
|
|
|
|
+ private String returnUrl;
|
|
|
|
+
|
|
|
|
+ @Value("payConfig.alipay.notifyUrl")
|
|
|
|
+ private String notifyUrl;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 支付调起
|
|
* 支付调起
|
|
@@ -46,12 +49,17 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
|
|
+
|
|
public ResultMap create(ProductPayParamBO product) {
|
|
public ResultMap create(ProductPayParamBO product) {
|
|
this.attach = product.getAttach();
|
|
this.attach = product.getAttach();
|
|
- configInit(product.getConfig());
|
|
|
|
- Map<String, String> attachMap = JSON.parseObject(JSON.toJSONString(this.attach), new TypeReference<Map<String, String>>() {
|
|
|
|
- });
|
|
|
|
- this.returnUrl = URIUtil.fillUrlParams(this.returnUrl, attachMap, true);
|
|
|
|
|
|
+ configInit(getPayConfig(product.getGameId(), product.getPayWay(), product.getPayWay()));
|
|
|
|
+// Map<String, String> attachMap = JSON.parseObject(JSON.toJSONString(this.attach), new TypeReference<Map<String, String>>() {
|
|
|
|
+// });
|
|
|
|
+// this.returnUrl = URIUtil.fillUrlParams(this.returnUrl, attachMap, true);
|
|
|
|
+
|
|
|
|
+ //回调地址中拼接游戏具体支付方式
|
|
|
|
+ returnUrl += "?" + "gamePayWayId=" + attach.getGamePayWayId();
|
|
|
|
+ notifyUrl += "?" + "gamePayWayId=" + attach.getGamePayWayId();
|
|
switch (product.getPayDevice()) {
|
|
switch (product.getPayDevice()) {
|
|
case 1:
|
|
case 1:
|
|
return this.pc(product);
|
|
return this.pc(product);
|
|
@@ -80,20 +88,16 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
String parameterName = parameterNames.nextElement();
|
|
String parameterName = parameterNames.nextElement();
|
|
params.put(parameterName, request.getParameter(parameterName));
|
|
params.put(parameterName, request.getParameter(parameterName));
|
|
}
|
|
}
|
|
- String outTradeNo = request.getParameter("out_trade_no");
|
|
|
|
|
|
+ String orderNo = request.getParameter("out_trade_no");
|
|
|
|
+ String gamePayWayId = params.get("gamePayWayId");
|
|
|
|
+ //回调地址拼接参数不参加sign验证
|
|
|
|
+ params.remove("gamePayWayId");
|
|
|
|
+ //初始化配置
|
|
|
|
+ configInit(getPayConfig(gamePayWayId));
|
|
Boolean flag = Factory.Payment.Common().verifyNotify(params);
|
|
Boolean flag = Factory.Payment.Common().verifyNotify(params);
|
|
if (flag) {
|
|
if (flag) {
|
|
- PlatformOrderBO bo = new PlatformOrderBO();
|
|
|
|
- bo.setId(outTradeNo);
|
|
|
|
- bo.setUserId(request.getParameter("user_id"));
|
|
|
|
- bo.setRealAmount(new BigDecimal(request.getParameter("totalFee")));
|
|
|
|
- bo.setMerchantOrderNo(request.getParameter("trade_no"));
|
|
|
|
- bo.setStatus(OrderStateEnum.SUCCESS.getCode());
|
|
|
|
- bo.setGamePaywayId(request.getParameter("gamePayWayId"));
|
|
|
|
- bo.setPayTime(new Date());
|
|
|
|
- Boolean result = platformOrderService.pay(bo);
|
|
|
|
- if (result) {
|
|
|
|
- logger.info("支付宝异步回调成功 request:{},商户订单号为:{}", request, outTradeNo);
|
|
|
|
|
|
+ if (paySuccess(orderNo, params.get("total_amount"), params.get("trade_no"), gamePayWayId)) {
|
|
|
|
+ logger.info("支付宝异步回调成功 request:{},orderNo:{},商户订单号为:{}", request, orderNo, params.get("trade_no"));
|
|
return ResEnum.SUCCESS.getMsg();
|
|
return ResEnum.SUCCESS.getMsg();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -130,15 +134,22 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
}
|
|
}
|
|
//商户订单号
|
|
//商户订单号
|
|
String orderNo = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");
|
|
String orderNo = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");
|
|
- //前台回调验证签名 v1 or v2
|
|
|
|
|
|
+ String gamePayWayId = params.get("gamePayWayId");
|
|
|
|
+ //回调地址拼接参数不参加sign验证
|
|
|
|
+ params.remove("gamePayWayId");
|
|
|
|
+ //初始化配置
|
|
|
|
+ configInit(getPayConfig(gamePayWayId));
|
|
|
|
+ //验证签名
|
|
Boolean flag = Factory.Payment.Common().verifyNotify(params);
|
|
Boolean flag = Factory.Payment.Common().verifyNotify(params);
|
|
if (flag) {
|
|
if (flag) {
|
|
logger.info("订单号" + orderNo + "验证签名结果[成功].");
|
|
logger.info("订单号" + orderNo + "验证签名结果[成功].");
|
|
- //处理业务逻辑
|
|
|
|
- } else {
|
|
|
|
- logger.info("订单号" + orderNo + "验证签名结果[失败].");
|
|
|
|
|
|
+ if (paySuccess(orderNo, params.get("total_amount"), params.get("trade_no"), gamePayWayId)) {
|
|
|
|
+ logger.info("支付宝同步回调成功 request:{},orderNo:{},商户订单号为:{}", request, orderNo, params.get("trade_no"));
|
|
|
|
+ return ResultMap.ok(HttpStatusEnum.SUCCESS.getMsg());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return ResultMap.ok("success");
|
|
|
|
|
|
+ logger.error("订单号" + orderNo + "验证签名结果[失败].");
|
|
|
|
+ return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
//处理异常信息
|
|
//处理异常信息
|
|
@@ -158,11 +169,11 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
try {
|
|
try {
|
|
logger.info("mobile端支付生成,请求参数 bo:{}", product);
|
|
logger.info("mobile端支付生成,请求参数 bo:{}", product);
|
|
AlipayTradeWapPayResponse response = Factory.Payment
|
|
AlipayTradeWapPayResponse response = Factory.Payment
|
|
- .Wap()
|
|
|
|
- .pay(JSONObject.toJSONString(this.attach), product.getOutTradeNo(), product.getTotalFee(), "", this.returnUrl);
|
|
|
|
|
|
+ .Wap().asyncNotify(notifyUrl)
|
|
|
|
+ .pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), "", this.returnUrl);
|
|
logger.info("mobile端支付生成,result:{}", response);
|
|
logger.info("mobile端支付生成,result:{}", response);
|
|
if (ResponseChecker.success(response)) {
|
|
if (ResponseChecker.success(response)) {
|
|
- return ResultMap.ok(response.getBody());
|
|
|
|
|
|
+ return ResultMap.ok(product.getPayDevice(), response.getBody());
|
|
} else {
|
|
} else {
|
|
return ResultMap.ok(ResEnum.FAIL.getMsg());
|
|
return ResultMap.ok(ResEnum.FAIL.getMsg());
|
|
}
|
|
}
|
|
@@ -182,7 +193,7 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
try {
|
|
try {
|
|
logger.info("pc端支付生成,请求参数 bo:{}", product);
|
|
logger.info("pc端支付生成,请求参数 bo:{}", product);
|
|
AlipayTradePagePayResponse response = Factory.Payment
|
|
AlipayTradePagePayResponse response = Factory.Payment
|
|
- .Page()
|
|
|
|
|
|
+ .Page().asyncNotify(notifyUrl)
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), this.returnUrl);
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), this.returnUrl);
|
|
logger.info("pc端支付生成,result:{}", response);
|
|
logger.info("pc端支付生成,result:{}", response);
|
|
if (ResponseChecker.success(response)) {
|
|
if (ResponseChecker.success(response)) {
|
|
@@ -206,10 +217,10 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
private ResultMap app(ProductPayParamBO product) {
|
|
private ResultMap app(ProductPayParamBO product) {
|
|
try {
|
|
try {
|
|
AlipayTradeAppPayResponse response = Factory.Payment
|
|
AlipayTradeAppPayResponse response = Factory.Payment
|
|
- .App()
|
|
|
|
|
|
+ .App().asyncNotify(notifyUrl)
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee());
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee());
|
|
if (ResponseChecker.success(response)) {
|
|
if (ResponseChecker.success(response)) {
|
|
- return ResultMap.ok(response.getBody());
|
|
|
|
|
|
+ return ResultMap.ok(product.getPayDevice(), response.getBody());
|
|
} else {
|
|
} else {
|
|
return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
}
|
|
}
|
|
@@ -222,10 +233,11 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 配置初始化
|
|
* 配置初始化
|
|
|
|
+ *
|
|
|
|
+ * @param obj config
|
|
*/
|
|
*/
|
|
- public void configInit(Object obj) {
|
|
|
|
- Config config = JSONObject.parseObject(obj.toString(), Config.class);
|
|
|
|
|
|
+ public void configInit(String obj) {
|
|
|
|
+ Config config = JSONObject.parseObject(obj, Config.class);
|
|
Factory.setOptions(config);
|
|
Factory.setOptions(config);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|