|
@@ -16,8 +16,6 @@ import com.zanxiang.sdk.common.util.HttpUtil;
|
|
|
import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
|
|
|
import com.zanxiang.sdk.service.OrderPayService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -27,7 +25,6 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.Enumeration;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -38,9 +35,8 @@ import java.util.regex.Pattern;
|
|
|
*/
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
-@Service("AlipayService")
|
|
|
-public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(AlipayServiceImpl.class);
|
|
|
+@Service("AliPayService")
|
|
|
+public class AliPayServiceImpl extends PayService implements OrderPayService {
|
|
|
|
|
|
@Value("${payConfig.alipay.returnUrl}")
|
|
|
private String returnUrl;
|
|
@@ -48,8 +44,6 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
@Value("${payConfig.alipay.notifyUrl}")
|
|
|
private String notifyUrl;
|
|
|
|
|
|
- private Config config;
|
|
|
-
|
|
|
/**
|
|
|
* 支付调起
|
|
|
*
|
|
@@ -60,10 +54,6 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
public ResultMap create(ProductPayParamBO product) {
|
|
|
this.attach = product.getAttach();
|
|
|
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();
|
|
@@ -104,11 +94,11 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
Boolean flag = Factory.Payment.Common().verifyNotify(params);
|
|
|
if (flag) {
|
|
|
if (paySuccess(orderNo, params.get("total_amount"), params.get("trade_no"), gamePayWayId)) {
|
|
|
- logger.info("支付宝异步回调成功 request:{},orderNo:{},商户订单号为:{}", request, orderNo, params.get("trade_no"));
|
|
|
+ log.info("支付宝异步回调成功 request:{},orderNo:{},商户订单号为:{}", request, orderNo, params.get("trade_no"));
|
|
|
return ResEnum.SUCCESS.getMsg();
|
|
|
}
|
|
|
}
|
|
|
- logger.error("支付宝异步回调-验证签名失败 request:{}", request);
|
|
|
+ log.error("支付宝异步回调-验证签名失败 request:{}", request);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -127,8 +117,7 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
//获取支付宝GET过来反馈信息
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
Map<String, String[]> requestParams = request.getParameterMap();
|
|
|
- for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
|
|
|
- String name = iter.next();
|
|
|
+ for (String name : requestParams.keySet()) {
|
|
|
String[] values = requestParams.get(name);
|
|
|
String valueStr = "";
|
|
|
for (int i = 0; i < values.length; i++) {
|
|
@@ -149,21 +138,19 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
//验证签名
|
|
|
Boolean flag = Factory.Payment.Common().verifyNotify(params);
|
|
|
if (flag) {
|
|
|
- logger.info("订单号" + orderNo + "验证签名结果[成功].");
|
|
|
+ log.info("订单号" + orderNo + "验证签名结果[成功].");
|
|
|
if (paySuccess(orderNo, params.get("total_amount"), params.get("trade_no"), gamePayWayId)) {
|
|
|
- logger.info("支付宝同步回调成功 request:{},orderNo:{},商户订单号为:{}", request, orderNo, params.get("trade_no"));
|
|
|
+ log.info("支付宝同步回调成功 request:{},orderNo:{},商户订单号为:{}", request, orderNo, params.get("trade_no"));
|
|
|
return ResultMap.ok(HttpStatusEnum.SUCCESS.getMsg());
|
|
|
}
|
|
|
}
|
|
|
- logger.error("订单号" + orderNo + "验证签名结果[失败].");
|
|
|
+ log.error("订单号" + orderNo + "验证签名结果[失败].");
|
|
|
return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
//处理异常信息
|
|
|
return ResultMap.error(e.getMessage());
|
|
|
}
|
|
|
- //支付成功、跳转到成功页面
|
|
|
- //return "success.html";
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -174,11 +161,11 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
*/
|
|
|
private ResultMap mobile(ProductPayParamBO product) {
|
|
|
try {
|
|
|
- logger.info("mobile端支付生成,请求参数 bo:{}", product);
|
|
|
+ log.info("mobile端支付生成,请求参数 bo:{}", product);
|
|
|
AlipayTradeWapPayResponse response = Factory.Payment
|
|
|
.Wap().asyncNotify(notifyUrl)
|
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), "", this.returnUrl);
|
|
|
- logger.info("mobile端支付生成,result:{}", response);
|
|
|
+ log.info("mobile端支付生成,result:{}", response);
|
|
|
if (ResponseChecker.success(response)) {
|
|
|
System.out.println("mobile端支付生成================");
|
|
|
System.out.println(response.getBody());
|
|
@@ -193,11 +180,11 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
|
|
|
private ResultMap mobile2(ProductPayParamBO product) {
|
|
|
try {
|
|
|
- logger.info("mobile端支付生成,请求参数 bo:{}", product);
|
|
|
+ log.info("mobile端支付生成,请求参数 bo:{}", product);
|
|
|
AlipayTradeWapPayResponse response = Factory.Payment
|
|
|
.Wap().asyncNotify(notifyUrl)
|
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), "", this.returnUrl);
|
|
|
- logger.info("mobile端支付生成,result:{}", response);
|
|
|
+ log.info("mobile端支付生成,result:{}", response);
|
|
|
if (ResponseChecker.success(response)) {
|
|
|
HashMap<String, String> result = new HashMap<>();
|
|
|
String body = response.getBody();
|
|
@@ -242,7 +229,7 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("获取支付包app支付时发生异常,已通过from表单形式调起支付 fromData:{}, e:{}", body, e);
|
|
|
+ log.error("获取支付包app支付时发生异常,已通过from表单形式调起支付 fromData:{}, e:{}", body, e);
|
|
|
}
|
|
|
return ResultMap.ok(product.getPayDevice(), result);
|
|
|
}
|
|
@@ -261,18 +248,18 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
*/
|
|
|
private ResultMap pc(ProductPayParamBO product) {
|
|
|
try {
|
|
|
- logger.info("pc端支付生成,请求参数 bo:{}", product);
|
|
|
+ log.info("pc端支付生成, product : {}", product);
|
|
|
AlipayTradePagePayResponse response = Factory.Payment
|
|
|
.Page().asyncNotify(notifyUrl)
|
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), this.returnUrl);
|
|
|
- logger.info("pc端支付生成,result:{}", response);
|
|
|
+ log.info("pc端支付生成, response : {}", response);
|
|
|
if (ResponseChecker.success(response)) {
|
|
|
return ResultMap.ok(product.getPayDevice(), response.getBody());
|
|
|
} else {
|
|
|
return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("pc端支付生成异常 e:{}", e);
|
|
|
+ log.error("pc端支付生成异常, e : {}", e.getMessage());
|
|
|
return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
|
}
|
|
|
}
|
|
@@ -294,8 +281,7 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- logger.error("app端支付生成异常 e:{}", e);
|
|
|
+ log.error("app端支付生成异常, e : {}", e.getMessage());
|
|
|
return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
|
}
|
|
|
}
|
|
@@ -305,9 +291,9 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
*
|
|
|
* @param obj config
|
|
|
*/
|
|
|
+ @Override
|
|
|
public void configInit(String obj) {
|
|
|
Config config = JSONObject.parseObject(obj, Config.class);
|
|
|
Factory.setOptions(config);
|
|
|
- this.config = config;
|
|
|
}
|
|
|
}
|