name: 微信H5支付出现跨域
about: 微信H5支付出现跨域
版本信息
IJPay 版本:master
开发环境: dev
支付方式: 微信H5支付
调用的接口: #(ctxPath)/wxPay/wapPay
报错信息 (注意格式化)
Access to XMLHttpRequest at 'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx211427144424841092ccbd92efdcf30000&package=3589738026' (redirected from 'http://wxykt.zt.net.cn:8881/wxPay/wapPay2?productDesc=1&extraData=2&totalFee=1') from origin 'http://wxykt.zt.net.cn:8881' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
问题描述(包括回显步骤、截图 )
使用微信H5付款方式,前端使用这样的方式进行访问:
$.post("#(ctxPath)/wxPay/wapPay2", {
productDesc: productDesc,
extraData: extraData,
totalFee: totalFee
}, function () {
});
采用ajax进行访问时出现跨域错误,但是已经在后端配置了跨域策略
@SilenceDN
public class CorsFilter implements Filter {
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) arg1;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
response.setHeader("Access-Control-Allow-Headers", "Content-Type,XFILENAME,XFILECATEGORY,XFILESIZE");
arg2.doFilter(arg0, arg1);
}
}
跨域策略不起作用。
但是,如果直接在H5页面的a标签中使用href进行跳转,则没有问题。可以进行支付。
预期效果描述
可以调用出微信付款
交流群
IJPay 让支付触手可及交流群:723992875
TNWX 微信公众号开发脚手架交流群:114196246