- 微信网页授权后重定向未携带code?
授权链接: https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc72f01f43da0083b&redirect_uri=https%3A%2F%2Fmpay.meituan.com%2Fresource%2Ficashier%2Fs%2Findex.html%3Fredr_url%3Dhttps%253A%252F%252Fh5.waimai.meituan.com%252Fwaimai%252Fmindex%252Fhome%26tradeno%3D23063011100300390007728787319008%26auth%3Dv2%26nb_app%3Dweixin%26pay_success_url%3Dhttps%253A%252F%252Fh5.waimai.meituan.com%252Fwaimai%252Fmindex%252Forder-detail%253FmtOrderViewId%253D1100612893758250015%26app_id%3Dwxc72f01f43da0083b%26pay_token%3De8caecb41ace76efec84874473bf7ce1%26isEncoded%3D1%26dp_referrer%3Dfalse%26nb_async%3D0&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect 微信网页授权后在重定向的链接上未拼接上code,这边辛苦看看这个授权链接的记录,看看是什么原因。自己测试这个链接在微信内是可以拿到code的,用户那一笔没有code。
2023-07-05 - 微信网页授权时,已经跳转到redirect uri页面了,但是为什么就是获取不到code?
if (!openId) { // 内存内没有openid let locationUrl = window.location.href // 检测是否参数内有code,若有则跳接口获取openid,若没有则跳授权页 if (locationUrl.indexOf('code') >= 0) { // 链接里有code let url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' + appid + '&secret=' + secret + '&code=' + code + '&grant_type=authorization_code' let result = JSON.parse(window.location.href = url) openId = result.openId if (openId) { localStorage.setItem('openId', openId) getUserInfoByOpenId(openId) } } else { // 链接里没有code let codeUri = encodeURIComponent(href) let url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=' + codeUri + '&response_type=code&scope=' + scope + '&state=123#wechat_redirect' window.location.href = url }
07-31