|
@@ -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:
|
|
|
|
|
|
- resultMap = this.pcPay(product);
|
|
|
+ resultMap = this.pcPay(product, config);
|
|
|
break;
|
|
|
case 2:
|
|
|
|
|
|
- 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);
|
|
|
|
|
|
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);
|
|
|
|
|
|
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 {
|
|
|
|
|
|
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());
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
}
|