记得上下班打卡 | git大法好,push需谨慎

Commit 385affa1 authored by 姜秀龙's avatar 姜秀龙

fix(order): 小程序支付 appid 读配置并兼容老 paymentType

WepayAppletPayConfigure 从 liquidnet.wechat.applet.* 解析 appid;
退款/查单兼容 APPLET*WEPAY 与 PAYB 老摩登单。
Co-authored-by: 's avatarCursor <cursoragent@cursor.com>
parent fdbe495a
...@@ -216,6 +216,10 @@ public class DragonConstant { ...@@ -216,6 +216,10 @@ public class DragonConstant {
return arry[i]; return arry[i];
} }
} }
// 兼容 APPLETDOUDOUWEPAY 等新类型:查单仍走小程序微信策略
if (code != null && code.contains("APPLET") && code.endsWith("WEPAY")) {
return PAYMENT_TYPE_APPLET_WEPAY;
}
return null; return null;
} }
......
...@@ -3,7 +3,7 @@ package com.liquidnet.service.dragon.support; ...@@ -3,7 +3,7 @@ package com.liquidnet.service.dragon.support;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto; import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
/** /**
* 微信小程序支付:deviceFrom / appIdType 与微信 appid 映射 * 微信小程序支付:deviceFrom / appIdType / paymentType 约定(不含 appid,appid 见 order 内 {@code WepayAppletPayConfigure})
*/ */
public final class WepayAppletPaySupport { public final class WepayAppletPaySupport {
...@@ -17,12 +17,6 @@ public final class WepayAppletPaySupport { ...@@ -17,12 +17,6 @@ public final class WepayAppletPaySupport {
public static final String APP_ID_TYPE_MOOTOO = "mootoo"; public static final String APP_ID_TYPE_MOOTOO = "mootoo";
public static final String APP_ID_TYPE_WENQUE = "wenque"; public static final String APP_ID_TYPE_WENQUE = "wenque";
private static final String APPLET_DEFAULT = "wx4732efeaa2b08086";
private static final String APPLET_B = "wxe3a093ce7278d5b1";
private static final String APPLET_DOUDOU = "wxa4b24c3ed55e4e18";
private static final String APPLET_MOOTOO = "wxe86ab49478ec3ee9";
private static final String APPLET_WENQUE = "wxacbe59cb64cb3ed4";
private WepayAppletPaySupport() { private WepayAppletPaySupport() {
} }
...@@ -69,40 +63,10 @@ public final class WepayAppletPaySupport { ...@@ -69,40 +63,10 @@ public final class WepayAppletPaySupport {
return paymentType != null && paymentType.contains("APPLETB"); return paymentType != null && paymentType.contains("APPLETB");
} }
public static String resolveAppletAppIdByAppIdType(String appIdType) { /**
if (appIdType == null || appIdType.trim().isEmpty()) { * 小程序微信 JSAPI:含历史 APPLETWEPAY、APPLETBWEPAY 及 APPLETDOUDOUWEPAY 等。
return APPLET_DEFAULT; */
} public static boolean isAppletWechatPaymentType(String paymentType) {
switch (appIdType) { return paymentType != null && paymentType.contains("APPLET") && paymentType.endsWith("WEPAY");
case APP_ID_TYPE_B:
return APPLET_B;
case APP_ID_TYPE_DOUDOU:
return APPLET_DOUDOU;
case APP_ID_TYPE_MOOTOO:
return APPLET_MOOTOO;
case APP_ID_TYPE_WENQUE:
return APPLET_WENQUE;
default:
return APPLET_DEFAULT;
}
}
public static String resolveAppletAppIdByPaymentType(String paymentType) {
if (paymentType == null) {
return APPLET_DEFAULT;
}
if (paymentType.contains("APPLETB")) {
return APPLET_B;
}
if (paymentType.contains("DOUDOU")) {
return APPLET_DOUDOU;
}
if (paymentType.contains("MOOTOO")) {
return APPLET_MOOTOO;
}
if (paymentType.contains("WENQUE")) {
return APPLET_WENQUE;
}
return APPLET_DEFAULT;
} }
} }
...@@ -16,6 +16,7 @@ import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto; ...@@ -16,6 +16,7 @@ import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto; import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto; import com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto;
import com.liquidnet.service.dragon.utils.DataUtilsDragon; import com.liquidnet.service.dragon.utils.DataUtilsDragon;
import com.liquidnet.service.dragon.config.WepayAppletPayConfigure;
import com.liquidnet.service.dragon.support.WepayAppletPaySupport; import com.liquidnet.service.dragon.support.WepayAppletPaySupport;
import com.liquidnet.service.dragon.utils.PayWepayUtils; import com.liquidnet.service.dragon.utils.PayWepayUtils;
import com.liquidnet.service.dragon.utils.XmlUtil; import com.liquidnet.service.dragon.utils.XmlUtil;
...@@ -202,7 +203,7 @@ public abstract class AbstractWepayStrategy implements IWepayStrategy { ...@@ -202,7 +203,7 @@ public abstract class AbstractWepayStrategy implements IWepayStrategy {
public DragonPayOrderQueryRespDto checkOrderStatus(String code) { public DragonPayOrderQueryRespDto checkOrderStatus(String code) {
DragonOrdersDto ordersDto = dataUtilsDragon.getPayOrderByCode(code); DragonOrdersDto ordersDto = dataUtilsDragon.getPayOrderByCode(code);
Map<String, Object> resultMap = null; Map<String, Object> resultMap = null;
String queryAppid = WepayAppletPaySupport.resolveAppletAppIdByPaymentType(ordersDto.getPaymentType()); String queryAppid = WepayAppletPayConfigure.resolveAppletAppIdForTradeQuery(ordersDto.getPaymentType(), code);
resultMap = wepayBiz.tradeQuery(code, queryAppid); resultMap = wepayBiz.tradeQuery(code, queryAppid);
DragonPayOrderQueryRespDto respDto = dragonPayBiz.buildPayOrderQueryRespDto(ordersDto); DragonPayOrderQueryRespDto respDto = dragonPayBiz.buildPayOrderQueryRespDto(ordersDto);
......
...@@ -5,7 +5,7 @@ import com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWe ...@@ -5,7 +5,7 @@ import com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWe
import com.liquidnet.service.dragon.constant.DragonConstant; import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto; import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto; import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.support.WepayAppletPaySupport; import com.liquidnet.service.dragon.config.WepayAppletPayConfigure;
import com.liquidnet.service.dragon.utils.PayWepayUtils; import com.liquidnet.service.dragon.utils.PayWepayUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -33,7 +33,7 @@ public class WepayStrategyAppletImpl extends AbstractWepayStrategy{ ...@@ -33,7 +33,7 @@ public class WepayStrategyAppletImpl extends AbstractWepayStrategy{
@Override @Override
SortedMap<String, Object> appendRequestParam(SortedMap<String, Object> requestMap, DragonPayBaseReqDto dragonPayBaseReqDto) { SortedMap<String, Object> appendRequestParam(SortedMap<String, Object> requestMap, DragonPayBaseReqDto dragonPayBaseReqDto) {
requestMap.put("trade_type", "JSAPI"); requestMap.put("trade_type", "JSAPI");
requestMap.put("appid", WepayAppletPaySupport.resolveAppletAppIdByAppIdType(dragonPayBaseReqDto.getAppIdType())); requestMap.put("appid", WepayAppletPayConfigure.resolveAppletAppIdByAppIdType(dragonPayBaseReqDto.getAppIdType()));
requestMap.put("openid", dragonPayBaseReqDto.getOpenId()); //只有trade_type="JSAPI"时必须传 requestMap.put("openid", dragonPayBaseReqDto.getOpenId()); //只有trade_type="JSAPI"时必须传
return requestMap; return requestMap;
} }
......
package com.liquidnet.service.dragon.config;
import com.liquidnet.service.dragon.support.WepayAppletPaySupport;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* 小程序微信支付 appid,与 sweet {@code liquidnet.wechat.applet.*} 配置一致。
*/
@Configuration
public class WepayAppletPayConfigure {
private static String appidZhengzai;
private static String appidModern;
private static String appidDoudou;
private static String appidMootoo;
private static String appidWenque;
@Value("${liquidnet.wechat.applet.zhengzai.appid}")
public void setAppidZhengzai(String appidZhengzai) {
WepayAppletPayConfigure.appidZhengzai = appidZhengzai;
}
@Value("${liquidnet.wechat.applet.modern.appid}")
public void setAppidModern(String appidModern) {
WepayAppletPayConfigure.appidModern = appidModern;
}
@Value("${liquidnet.wechat.applet.doudou.appid}")
public void setAppidDoudou(String appidDoudou) {
WepayAppletPayConfigure.appidDoudou = appidDoudou;
}
@Value("${liquidnet.wechat.applet.mootoo.appid}")
public void setAppidMootoo(String appidMootoo) {
WepayAppletPayConfigure.appidMootoo = appidMootoo;
}
@Value("${liquidnet.wechat.applet.wenque.appid}")
public void setAppidWenque(String appidWenque) {
WepayAppletPayConfigure.appidWenque = appidWenque;
}
public static String resolveAppletAppIdByAppIdType(String appIdType) {
if (appIdType == null || appIdType.trim().isEmpty()) {
return appidZhengzai;
}
switch (appIdType) {
case WepayAppletPaySupport.APP_ID_TYPE_B:
return appidModern;
case WepayAppletPaySupport.APP_ID_TYPE_DOUDOU:
return appidDoudou;
case WepayAppletPaySupport.APP_ID_TYPE_MOOTOO:
return appidMootoo;
case WepayAppletPaySupport.APP_ID_TYPE_WENQUE:
return appidWenque;
default:
return appidZhengzai;
}
}
public static String resolveAppletAppIdByPaymentType(String paymentType) {
if (paymentType == null) {
return appidZhengzai;
}
if (paymentType.contains("APPLETB")) {
return appidModern;
}
if (paymentType.contains("DOUDOU")) {
return appidDoudou;
}
if (paymentType.contains("MOOTOO")) {
return appidMootoo;
}
if (paymentType.contains("WENQUE")) {
return appidWenque;
}
return appidZhengzai;
}
/**
* 查单/退款:优先 paymentType;老摩登单可能 payment_type=APPLETWEPAY 但 pay_code 为 PAYB 前缀。
*/
public static String resolveAppletAppIdForTradeQuery(String paymentType, String payCode) {
String appId = resolveAppletAppIdByPaymentType(paymentType);
if (appidZhengzai != null && appidZhengzai.equals(appId) && payCode != null
&& (payCode.startsWith("PAYB") || payCode.contains("b"))) {
return appidModern;
}
return appId;
}
}
...@@ -24,6 +24,7 @@ import com.liquidnet.service.dragon.constant.DragonConstant; ...@@ -24,6 +24,7 @@ import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.constant.DragonErrorCodeEnum; import com.liquidnet.service.dragon.constant.DragonErrorCodeEnum;
import com.liquidnet.service.dragon.dto.*; import com.liquidnet.service.dragon.dto.*;
import com.liquidnet.service.dragon.service.IDragonOrderRefundsService; import com.liquidnet.service.dragon.service.IDragonOrderRefundsService;
import com.liquidnet.service.dragon.config.WepayAppletPayConfigure;
import com.liquidnet.service.dragon.support.WepayAppletPaySupport; import com.liquidnet.service.dragon.support.WepayAppletPaySupport;
import com.liquidnet.service.dragon.utils.*; import com.liquidnet.service.dragon.utils.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -93,7 +94,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -93,7 +94,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
String localDouYinCallBackUrl = url + "/refund/callBack/douyinpay"; String localDouYinCallBackUrl = url + "/refund/callBack/douyinpay";
String localUnionPayCallBackUrl = url + "/refund/callBack/union"; String localUnionPayCallBackUrl = url + "/refund/callBack/union";
if (insertResult) { if (insertResult) {
switch (paymentType) { if (WepayAppletPaySupport.isAppletWechatPaymentType(paymentType)) {
dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime);
} else switch (paymentType) {
case DragonConstant.REFUND_TYPE_APP_ALIPAY: case DragonConstant.REFUND_TYPE_APP_ALIPAY:
dto = aliPayRefund(code, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime); dto = aliPayRefund(code, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
break; break;
...@@ -124,12 +127,6 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -124,12 +127,6 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
case DragonConstant.REFUND_TYPE_MICROPAY_WEPAY: case DragonConstant.REFUND_TYPE_MICROPAY_WEPAY:
dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime); dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime);
break; break;
case DragonConstant.REFUND_TYPE_APPLET_WEPAY:
dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_APPLETB_WEPAY:
dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_APPLET_DOUYIN: case DragonConstant.REFUND_TYPE_APPLET_DOUYIN:
dataUtilsDragon.setOrderCode(orderRefundCode, orderCode); dataUtilsDragon.setOrderCode(orderRefundCode, orderCode);
dto = douYinRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localDouYinCallBackUrl, nowTime); dto = douYinRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localDouYinCallBackUrl, nowTime);
...@@ -421,8 +418,8 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -421,8 +418,8 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
parameters.put("appid", PayWepayUtils.getInstance().getWEB_APP_ID()); parameters.put("appid", PayWepayUtils.getInstance().getWEB_APP_ID());
} else if (paymentType.equalsIgnoreCase(DragonConstant.PayTypeEnum.PAYMENT_TYPE_APP_WEPAY.getCode())) { } else if (paymentType.equalsIgnoreCase(DragonConstant.PayTypeEnum.PAYMENT_TYPE_APP_WEPAY.getCode())) {
parameters.put("appid", PayWepayUtils.getInstance().getAPP_ID()); parameters.put("appid", PayWepayUtils.getInstance().getAPP_ID());
} else if (paymentType != null && paymentType.contains("APPLET") && paymentType.contains("WEPAY")) { } else if (WepayAppletPaySupport.isAppletWechatPaymentType(paymentType)) {
parameters.put("appid", WepayAppletPaySupport.resolveAppletAppIdByPaymentType(paymentType)); parameters.put("appid", WepayAppletPayConfigure.resolveAppletAppIdForTradeQuery(paymentType, code));
if (WepayAppletPaySupport.usesMerchantBByPaymentType(paymentType)) { if (WepayAppletPaySupport.usesMerchantBByPaymentType(paymentType)) {
parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantBId()); parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantBId());
type = 1; type = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment