|
@@ -54,6 +54,7 @@ const Login2pProvider: React.FC<ContextProviderProps> = ({ children }: ContextPr
|
|
|
history.go(0)
|
|
|
}
|
|
|
const loginWechatLaunch = (redirectURI: string) => {
|
|
|
+ const windowFeatures = 'left=500,top3100,width=500,height=500'
|
|
|
if (isWechat) {
|
|
|
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${
|
|
|
process.env.REACT_APP_WECHART_APPID_NEW
|
|
@@ -61,11 +62,24 @@ const Login2pProvider: React.FC<ContextProviderProps> = ({ children }: ContextPr
|
|
|
redirectURI
|
|
|
)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
|
|
|
} else {
|
|
|
- window.location.href = `https://open.weixin.qq.com/connect/qrconnect?appid=${
|
|
|
- process.env.REACT_APP_WECHAT_OPEN_APPID_NEW
|
|
|
- }&redirect_uri=${encodeURIComponent(
|
|
|
- redirectURI
|
|
|
- )}&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect`
|
|
|
+ // 创建 BroadcastChannel 实例
|
|
|
+ const channel = new BroadcastChannel('myChannel')
|
|
|
+
|
|
|
+ // 监听广播通道的消息
|
|
|
+ channel.addEventListener('message', event => {
|
|
|
+ loginWechat(event.data.code, decodeURIComponent(event.data.next ? event.data.next : '/')).then(r =>
|
|
|
+ console.log(r)
|
|
|
+ )
|
|
|
+ })
|
|
|
+ window.open(
|
|
|
+ `https://open.weixin.qq.com/connect/qrconnect?appid=${
|
|
|
+ process.env.REACT_APP_WECHAT_OPEN_APPID_NEW
|
|
|
+ }&redirect_uri=${encodeURIComponent(
|
|
|
+ redirectURI
|
|
|
+ )}&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect`,
|
|
|
+ 'mozillaWindow',
|
|
|
+ windowFeatures
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
const loginWechat = async (code: string, next: string) =>
|