For the react mobile website, Wechat third-party login to obtain code cross-domain.

problem description

Mobile websites that are separated from the front and rear ends done by react will get code prompts for cross-domain login when doing third-party login. What happens now is that I request the interface of the backend (php), and then the backend calls the interface of open.weixin.qq.com to get the code. The backend is redirected to Wechat, and the network on this side of the front end shows 301 Moved Permanently (from cache).

the environmental background of the problems and what methods you have tried

uses axios. Native js XMLHttpRequest and fetch have all been tried, and they are also cross-domain.
the configuration related to the official account has been done, using the following link
https://open.weixin.qq.com/co.

if you jump to the above link directly at the front end, you can get the return value and get the result as scheduled, but this is not in the form of an api request. I can"t get the data on the page and jump back to my website page.

scope=snsapi_userinfo, does not get the form of a QR code, but opens the authorization directly on Wechat.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

wechatLogin ()
.then (res = > {

)
if (res.status === 200 && res.data.status === 1) {
  Toast.info(res.data.msg, 1)
}

})
.catch (() = > {

Toast.fail("", 1)

})
return

clipboard.png

clipboard.png

XMLHttpRequest cannot load https://open.weixin.qq.com/co. No "Access-Control-Allow-Origin" header is present on the requested resource. Origin "null" is therefore not allowed access.

Jan.08,2022

the backend requests and jumps back

Menu