feat(pay): 添加微信支付XStream安全配置解决回调解析异常

- 初始化XStream安全配置允许微信支付相关类的反序列化
- 添加微信支付通知结果、请求、订单等包路径到白名单
- 配置通配符模式支持微信支付SDK的动态类加载
- 添加初始化日志和异常处理确保配置稳定生效
pull/246/head
wuKong 2026-04-03 18:49:38 +08:00
parent 9ffec01fa0
commit e6c23d854f
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.pay.framework.pay.config;
import com.thoughtworks.xstream.XStream;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import org.springframework.context.annotation.Configuration;
/**
* XStream V2
*
* @author wuKong
*/
@Slf4j
@Configuration
public class PayXStreamConfig {
@PostConstruct
public void init() {
log.info("初始化 XStream 安全配置,允许微信支付类的反序列化");
try {
XStream xstream = XStreamInitializer.getInstance();
// 添加白名单
// Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException:
// com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult
xstream.allowTypesByWildcard(new String[] {
"com.github.binarywang.wxpay.bean.notify.**",
"com.github.binarywang.wxpay.bean.result.**",
"com.github.binarywang.wxpay.bean.request.**",
"com.github.binarywang.wxpay.bean.order.**"});
log.info("XStream 安全配置初始化成功");
} catch (Exception e) {
log.error("XStream 安全配置初始化失败", e);
}
}
}