|
@@ -8,10 +8,11 @@ import com.alipay.easysdk.payment.app.models.AlipayTradeAppPayResponse;
|
|
|
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
|
|
|
import com.alipay.easysdk.payment.wap.models.AlipayTradeWapPayResponse;
|
|
|
import com.zanxiang.common.constant.Constants;
|
|
|
-import com.zanxiang.common.domain.ResultMap;
|
|
|
import com.zanxiang.common.enums.HttpStatusEnum;
|
|
|
import com.zanxiang.common.enums.OsEnum;
|
|
|
+import com.zanxiang.common.exception.BaseException;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
+import com.zanxiang.module.util.pojo.ResultVO;
|
|
|
import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
|
|
|
import com.zanxiang.sdk.domain.dto.GamePayWayDTO;
|
|
|
import com.zanxiang.sdk.domain.dto.PayApplicationDTO;
|
|
@@ -83,7 +84,7 @@ public class AliPayService extends PayBaseService {
|
|
|
private IPayApplicationService payApplicationService;
|
|
|
|
|
|
@Override
|
|
|
- public ResultMap create(ProductPayParamBO product) {
|
|
|
+ public Map<String, Object> create(ProductPayParamBO product) {
|
|
|
this.attach = product.getAttach();
|
|
|
this.configInit(getPayConfig(product.getGameId(), product.getPayWay(), product.getPayDevice()));
|
|
|
//回调地址中拼接游戏具体支付方式
|
|
@@ -134,7 +135,7 @@ public class AliPayService extends PayBaseService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResultMap synNotify(HttpServletRequest request) {
|
|
|
+ public ResultVO synNotify(HttpServletRequest request) {
|
|
|
try {
|
|
|
//获取支付宝GET过来反馈信息
|
|
|
Map<String, String> params = new HashMap<>();
|
|
@@ -163,48 +164,51 @@ public class AliPayService extends PayBaseService {
|
|
|
log.info("订单号" + orderNo + "验证签名结果[成功].");
|
|
|
if (paySuccess(orderNo, params.get("total_amount"), params.get("trade_no"), gamePayWayId)) {
|
|
|
log.info("支付宝同步回调成功 request:{},orderNo:{},商户订单号为:{}", request, orderNo, params.get("trade_no"));
|
|
|
- return ResultMap.ok();
|
|
|
+ return ResultVO.ok();
|
|
|
}
|
|
|
}
|
|
|
log.error("订单号" + orderNo + "验证签名结果[失败].");
|
|
|
- return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
|
+ return ResultVO.fail(HttpStatusEnum.FAIL.getMsg());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
//处理异常信息
|
|
|
- return ResultMap.error(e.getMessage());
|
|
|
+ return ResultVO.fail(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private ResultMap h5Pay(ProductPayParamBO product) {
|
|
|
+ private Map<String, Object> h5Pay(ProductPayParamBO product) {
|
|
|
+ AlipayTradeWapPayResponse response;
|
|
|
try {
|
|
|
- AlipayTradeWapPayResponse response = Factory.Payment
|
|
|
- .Wap().asyncNotify(notifyUrl)
|
|
|
+ response = Factory.Payment.Wap().asyncNotify(notifyUrl)
|
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), "", this.returnUrl);
|
|
|
- //请求失败
|
|
|
- if (!ResponseChecker.success(response)) {
|
|
|
- log.error("支付宝h5支付失败,product : {}, response : {}", JsonUtil.toString(product), JsonUtil.toString(response));
|
|
|
- return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
|
- }
|
|
|
- HashMap<String, String> result = new HashMap<>();
|
|
|
- String body = response.getBody();
|
|
|
- result.put("fromData", body);
|
|
|
- //安卓与ios系统时才单独获取app支付地址
|
|
|
- if (!product.getDeviceSystem().contains(OsEnum.SYSTEM_ANDROID.getOs())
|
|
|
- && !product.getDeviceSystem().contains(OsEnum.SYSTEM_IOS.getOs())) {
|
|
|
- return ResultMap.ok(product.getPayDevice(), result, product.getOutTradeNo());
|
|
|
- }
|
|
|
- Matcher matcher = pattern.matcher(body);
|
|
|
- //解析短链
|
|
|
- String deepLink = this.getDeepLink(matcher, body, product.getDeviceSystem());
|
|
|
- //返回结果
|
|
|
- return ResultMap.ok(product.getPayDevice(), deepLink, product.getOutTradeNo());
|
|
|
} catch (Exception e) {
|
|
|
- log.error("支付宝h5支付失败,meg : {}", e.getMessage());
|
|
|
- return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
|
+ log.error("支付宝H5支付异常, product : {}, e:{}", JsonUtil.toString(product), e.getMessage());
|
|
|
+ throw new BaseException("支付宝H5支付异常");
|
|
|
+ }
|
|
|
+ //请求失败
|
|
|
+ if (!ResponseChecker.success(response)) {
|
|
|
+ log.error("支付宝H5支付失败, product : {}, response : {}", JsonUtil.toString(product), JsonUtil.toString(response));
|
|
|
+ throw new BaseException("支付宝H5支付失败");
|
|
|
}
|
|
|
+ //结果数据
|
|
|
+ String body = response.getBody();
|
|
|
+ Map<String, Object> payParamMap = new HashMap<>(3);
|
|
|
+ payParamMap.put("deviceType", product.getPayDevice());
|
|
|
+ payParamMap.put("orderId", product.getOutTradeNo());
|
|
|
+ //非手机系统, 不走deepLink
|
|
|
+ if (!product.getDeviceSystem().contains(OsEnum.SYSTEM_ANDROID.getOs())
|
|
|
+ && !product.getDeviceSystem().contains(OsEnum.SYSTEM_IOS.getOs())) {
|
|
|
+ payParamMap.put("data", body);
|
|
|
+ return payParamMap;
|
|
|
+ }
|
|
|
+ //解析短链deepLink
|
|
|
+ String deepLink = this.getH5DeepLink(body, product.getDeviceSystem());
|
|
|
+ payParamMap.put("data", deepLink);
|
|
|
+ return payParamMap;
|
|
|
}
|
|
|
|
|
|
- private String getDeepLink(Matcher matcher, String body, String deviceSystem) throws Exception {
|
|
|
+ private String getH5DeepLink(String body, String deviceSystem) {
|
|
|
+ Matcher matcher = pattern.matcher(body);
|
|
|
if (!matcher.find()) {
|
|
|
return null;
|
|
|
}
|
|
@@ -229,44 +233,54 @@ public class AliPayService extends PayBaseService {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(pageData);
|
|
|
Object invokeAliPayData = jsonObject.get("invokeAlipayData");
|
|
|
String dataString = JSONObject.parseObject(invokeAliPayData.toString()).get("dataString").toString();
|
|
|
- deepLinkAndroid += URLEncoder.encode(dataString, Constants.UTF8);
|
|
|
- deepLinkIos += URLEncoder.encode(pageData, Constants.UTF8);
|
|
|
+ try {
|
|
|
+ deepLinkAndroid += URLEncoder.encode(dataString, Constants.UTF8);
|
|
|
+ deepLinkIos += URLEncoder.encode(pageData, Constants.UTF8);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("deepLink短链encode异常, e : {}", e.getMessage());
|
|
|
+ throw new BaseException("deepLink短链encode异常");
|
|
|
+ }
|
|
|
return Objects.equals(deviceSystem, OsEnum.SYSTEM_ANDROID.getOs()) ? deepLinkAndroid : deepLinkIos;
|
|
|
}
|
|
|
|
|
|
- private ResultMap pcPay(ProductPayParamBO product) {
|
|
|
+ private Map<String, Object> pcPay(ProductPayParamBO product) {
|
|
|
+ AlipayTradePagePayResponse response;
|
|
|
try {
|
|
|
- log.info("pc端支付生成,请求参数 bo:{}", product);
|
|
|
- AlipayTradePagePayResponse response = Factory.Payment
|
|
|
- .Page().asyncNotify(notifyUrl)
|
|
|
+ response = Factory.Payment.Page().asyncNotify(notifyUrl)
|
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), this.returnUrl);
|
|
|
- log.info("pc端支付生成,result:{}", response);
|
|
|
- if (ResponseChecker.success(response)) {
|
|
|
- return ResultMap.ok(product.getPayDevice(), response.getBody(), product.getOutTradeNo());
|
|
|
- } else {
|
|
|
- return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
|
- }
|
|
|
} catch (Exception e) {
|
|
|
- log.error("pc端支付生成异常 e:{}", e.getMessage());
|
|
|
- return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
|
+ log.error("支付宝pc端支付异常, product : {}, e:{}", JsonUtil.toString(product), e.getMessage());
|
|
|
+ throw new BaseException("支付宝pc端支付异常");
|
|
|
+ }
|
|
|
+ if (!ResponseChecker.success(response)) {
|
|
|
+ log.error("支付宝pc端支付失败, product : {}, response : {}", JsonUtil.toString(product), JsonUtil.toString(response));
|
|
|
+ throw new BaseException("支付宝pc端支付失败");
|
|
|
}
|
|
|
+ Map<String, Object> payParamMap = new HashMap<>(3);
|
|
|
+ payParamMap.put("deviceType", product.getPayDevice());
|
|
|
+ payParamMap.put("data", response.getBody());
|
|
|
+ payParamMap.put("orderId", product.getOutTradeNo());
|
|
|
+ return payParamMap;
|
|
|
}
|
|
|
|
|
|
- private ResultMap appPay(ProductPayParamBO product) {
|
|
|
+ private Map<String, Object> appPay(ProductPayParamBO product) {
|
|
|
+ AlipayTradeAppPayResponse response;
|
|
|
try {
|
|
|
- AlipayTradeAppPayResponse response = Factory.Payment
|
|
|
- .App().asyncNotify(notifyUrl)
|
|
|
+ response = Factory.Payment.App().asyncNotify(notifyUrl)
|
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee());
|
|
|
- if (ResponseChecker.success(response)) {
|
|
|
- return ResultMap.ok(product.getPayDevice(), response.getBody(), product.getOutTradeNo());
|
|
|
- } else {
|
|
|
- return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
|
- }
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("app端支付生成异常 e:{}", e.getMessage());
|
|
|
- return ResultMap.error(HttpStatusEnum.FAIL.getMsg());
|
|
|
+ log.error("支付宝app端支付异常, product : {}, e:{}", JsonUtil.toString(product), e.getMessage());
|
|
|
+ throw new BaseException("支付宝app端支付异常");
|
|
|
+ }
|
|
|
+ if (!ResponseChecker.success(response)) {
|
|
|
+ log.error("支付宝app端支付失败, product : {}, response : {}", JsonUtil.toString(product), JsonUtil.toString(response));
|
|
|
+ throw new BaseException("支付宝app端支付失败");
|
|
|
}
|
|
|
+ Map<String, Object> payParamMap = new HashMap<>(3);
|
|
|
+ payParamMap.put("deviceType", product.getPayDevice());
|
|
|
+ payParamMap.put("data", response.getBody());
|
|
|
+ payParamMap.put("orderId", product.getOutTradeNo());
|
|
|
+ return payParamMap;
|
|
|
}
|
|
|
|
|
|
private void configInit(GamePayWayDTO gamePayWayDTO) {
|