|
@@ -76,11 +76,6 @@ public class WxPayService extends PayBaseService {
|
|
|
@Value("${payConfig.wxPay.notifyUrl}")
|
|
|
private String notifyUrl;
|
|
|
|
|
|
- /**
|
|
|
- * 微信支付配置
|
|
|
- */
|
|
|
- private WxPayConfigDTO config;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IOrderPayParamService orderPayParamService;
|
|
|
|
|
@@ -102,7 +97,7 @@ public class WxPayService extends PayBaseService {
|
|
|
@Override
|
|
|
public Map<String, Object> create(ProductPayParamDTO product, GamePayWayDTO gamePayWayDTO) {
|
|
|
//初始化配置
|
|
|
- this.configInit(gamePayWayDTO);
|
|
|
+ WxPayConfigDTO config = this.configInit(gamePayWayDTO);
|
|
|
//支付方式
|
|
|
int payDevice = product.getPayDevice().intValue();
|
|
|
//不同的支付途径
|
|
@@ -110,17 +105,17 @@ public class WxPayService extends PayBaseService {
|
|
|
switch (payDevice) {
|
|
|
case 1:
|
|
|
//PC
|
|
|
- resultMap = this.pcPay(product);
|
|
|
+ resultMap = this.pcPay(product, config);
|
|
|
break;
|
|
|
case 2:
|
|
|
//H5
|
|
|
- resultMap = this.h5Pay(product);
|
|
|
+ resultMap = this.h5Pay(product, config);
|
|
|
break;
|
|
|
case 4:
|
|
|
case 6:
|
|
|
case 7:
|
|
|
//小程序
|
|
|
- resultMap = this.miniAppPay(product);
|
|
|
+ resultMap = this.miniAppPay(product, config);
|
|
|
break;
|
|
|
default:
|
|
|
throw new RuntimeException("未知支付方式");
|
|
@@ -144,18 +139,16 @@ public class WxPayService extends PayBaseService {
|
|
|
String requestStr = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
|
|
// 解析xml成map
|
|
|
Map<String, String> packageParams = XmlUtil.xmlToMap(requestStr);
|
|
|
- log.error("微信支付回调参数, packageParams : {}, config : {}", JsonUtil.toString(packageParams), JsonUtil.toString(config));
|
|
|
+ log.error("微信支付回调参数, packageParams : {}", JsonUtil.toString(packageParams));
|
|
|
//获取订单信息
|
|
|
String attachStr = packageParams.get("attach");
|
|
|
ProductPayAttachParamDTO attachBO = JsonUtil.toObj(attachStr, ProductPayAttachParamDTO.class);
|
|
|
-
|
|
|
log.error("微信支付回调参数, attachBO : {}", JsonUtil.toString(attachBO));
|
|
|
-
|
|
|
if (attachBO == null) {
|
|
|
log.info("回调参数中attach值为空");
|
|
|
return null;
|
|
|
}
|
|
|
- configInit(gamePayWayService.getById(attachBO.getGamePayWayId()));
|
|
|
+ WxPayConfigDTO config = this.configInit(gamePayWayService.getById(attachBO.getGamePayWayId()));
|
|
|
// 账号信息
|
|
|
String key = config.getApiKey();
|
|
|
// 判断签名是否正确
|
|
@@ -171,7 +164,7 @@ public class WxPayService extends PayBaseService {
|
|
|
String orderNo = packageParams.get("out_trade_no");
|
|
|
String totalFee = String.valueOf(Float.parseFloat(packageParams.get("total_fee")) / 100);
|
|
|
log.info("微信订单号回调成功, orderId : {}", orderNo);
|
|
|
- if (paySuccess(attachBO.getOrderId(), totalFee, packageParams.get("transaction_id"))) {
|
|
|
+ if (paySuccess(orderNo, totalFee, packageParams.get("transaction_id"))) {
|
|
|
// 通知微信.异步确认成功.必写.不然会一直通知后台.八次之后就认为交易失败了
|
|
|
xmlMap.put("return_code", "SUCCESS");
|
|
|
xmlMap.put("return_msg", "OK");
|
|
@@ -190,9 +183,9 @@ public class WxPayService extends PayBaseService {
|
|
|
return HttpStatusEnum.SUCCESS.getMsg();
|
|
|
}
|
|
|
|
|
|
- private Map<String, Object> pcPay(ProductPayParamDTO product) {
|
|
|
+ private Map<String, Object> pcPay(ProductPayParamDTO product, WxPayConfigDTO config) {
|
|
|
//下单
|
|
|
- Map<String, String> successMap = this.unifiedOrder(product, WX_PAY_NATIVE, null);
|
|
|
+ Map<String, String> successMap = this.unifiedOrder(product, WX_PAY_NATIVE, null, config);
|
|
|
//获取二维码链接
|
|
|
String urlCode = successMap.get("code_url");
|
|
|
//判断是否获取到支付链接
|
|
@@ -207,9 +200,9 @@ public class WxPayService extends PayBaseService {
|
|
|
return payParamMap;
|
|
|
}
|
|
|
|
|
|
- private Map<String, Object> h5Pay(ProductPayParamDTO product) {
|
|
|
+ private Map<String, Object> h5Pay(ProductPayParamDTO product, WxPayConfigDTO config) {
|
|
|
//下单
|
|
|
- Map<String, String> successMap = this.unifiedOrder(product, WX_PAY_MWEB, null);
|
|
|
+ Map<String, String> successMap = this.unifiedOrder(product, WX_PAY_MWEB, null, config);
|
|
|
//获取h5支付链接
|
|
|
String urlCode = successMap.get("mweb_url");
|
|
|
if (Strings.isBlank(urlCode)) {
|
|
@@ -231,7 +224,7 @@ public class WxPayService extends PayBaseService {
|
|
|
return payParamMap;
|
|
|
}
|
|
|
|
|
|
- private Map<String, Object> miniAppPay(ProductPayParamDTO product) {
|
|
|
+ private Map<String, Object> miniAppPay(ProductPayParamDTO product, WxPayConfigDTO config) {
|
|
|
try {
|
|
|
//用户openId
|
|
|
String openId = product.getOpenId();
|
|
@@ -241,7 +234,7 @@ public class WxPayService extends PayBaseService {
|
|
|
config.getAppletType()).get("openid");
|
|
|
}
|
|
|
//下单
|
|
|
- Map<String, String> successMap = this.unifiedOrder(product, WX_PAY_JSAPI, openId);
|
|
|
+ Map<String, String> successMap = this.unifiedOrder(product, WX_PAY_JSAPI, openId, config);
|
|
|
// 支付参数
|
|
|
String prepayId = successMap.get("prepay_id");
|
|
|
// 随机字符串
|
|
@@ -289,7 +282,7 @@ public class WxPayService extends PayBaseService {
|
|
|
GamePayWayDTO gamePayWayDTO = gamePayWayService.getGamePayWay(platformOrderDTO.getGameId(),
|
|
|
platformOrderDTO.getPayWayId(), platformOrderDTO.getPayDeviceId());
|
|
|
//初始化配置
|
|
|
- this.configInit(gamePayWayDTO);
|
|
|
+ WxPayConfigDTO config = this.configInit(gamePayWayDTO);
|
|
|
try {
|
|
|
Map<String, String> paramData = new HashMap<>(6);
|
|
|
paramData.put("appid", config.getAppId());
|
|
@@ -315,7 +308,12 @@ public class WxPayService extends PayBaseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Map<String, String> unifiedOrder(ProductPayParamDTO product, String tradeType, String openId) {
|
|
|
+ private Map<String, String> unifiedOrder(ProductPayParamDTO product, String tradeType, String openId, WxPayConfigDTO config) {
|
|
|
+ ProductPayAttachParamDTO attachBO = new ProductPayAttachParamDTO();
|
|
|
+ attachBO.setUserId(product.getUserId());
|
|
|
+ attachBO.setOrderId(product.getOutTradeNo());
|
|
|
+ attachBO.setPayWay(product.getPayWay());
|
|
|
+ attachBO.setGamePayWayId(config.getGamePayWayId());
|
|
|
try {
|
|
|
Map<String, String> paramData = new HashMap<>(13);
|
|
|
paramData.put("appid", config.getAppId());
|
|
@@ -328,7 +326,7 @@ public class WxPayService extends PayBaseService {
|
|
|
paramData.put("spbill_create_ip", product.getSpbillCreateIp());
|
|
|
paramData.put("notify_url", notifyUrl);
|
|
|
paramData.put("trade_type", tradeType);
|
|
|
- paramData.put("attach", JsonUtil.toString(this.attach));
|
|
|
+ paramData.put("attach", JsonUtil.toString(attachBO));
|
|
|
paramData.put("sign_type", config.getSignType());
|
|
|
//小程序商城下单需要携带openId
|
|
|
if (Strings.isNotBlank(openId)) {
|
|
@@ -357,7 +355,7 @@ public class WxPayService extends PayBaseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void configInit(GamePayWayDTO gamePayWayDTO) {
|
|
|
+ private WxPayConfigDTO configInit(GamePayWayDTO gamePayWayDTO) {
|
|
|
//商户信息
|
|
|
PayMerchantDTO payMerchantDTO;
|
|
|
//支付应用信息
|
|
@@ -376,7 +374,8 @@ public class WxPayService extends PayBaseService {
|
|
|
payConfigBO.setAppSecret(payApplicationDTO.getAppSecret());
|
|
|
payConfigBO.setAppletType(payApplicationDTO.getType());
|
|
|
payConfigBO.setMachName(payMerchantDTO.getMerchantName());
|
|
|
+ payConfigBO.setGamePayWayId(gamePayWayDTO.getId());
|
|
|
//赋值配置信息
|
|
|
- this.config = payConfigBO;
|
|
|
+ return payConfigBO;
|
|
|
}
|
|
|
}
|