uniapp发布的H5网站,给服务端发送请求,服务端请求微信获取code,拿着code再次请求微信获取openid等信息提示跨域,报错信息如下:
XMLHttpRequest cannot load https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID…type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xxx.xxx.com' is therefore not allowed access.
如果直接访问服务端接口,是可以拿到openid的,如果从网页调用服务端接口,就会提示跨域,微信公众平台网页回调域名也设置了。然后前端还会返回一条错误:Please enable JavaScript to continue.请问有大神遇到过这种问题吗?
补充:后端是thinkphp开发的,使用thinkphp的网页调用接口不会出现跨域,uniapp打包的H5调用接口就会出现跨域