9***@qq.com
9***@qq.com
  • 发布:2020-12-21 13:47
  • 更新:2020-12-23 10:03
  • 阅读:1551

【报Bug】HTML5+微信登录,使用authorize接口返回的微信code验证登录,报40029错误

分类:HBuilderX

产品分类: HbuilderX

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10 19041.685

HBuilderX版本号: 2.9.8

示例代码:

getAuthServices(fun: Function) {
let plus = window['plus'];
plus.oauth.getServices(function (services) {
fun(services);
}, function (e) {
console.log("获取分享服务列表失败:" + e.message + " - " + e.code);
return null;
});
}

getAuthServices((auths) => {
var s = auths["weixin"];
if (s) {
// 获取登录操作结果
s.authorize(async (event) => {
console.log("获取code成功:" + event.code);
try {
//客户端发送code给服务器,进行验证
let result = await NetMgr.Instance.httpGet({
code: event.code,
shareplayerid: "null"
}, Router.WeixinOpenPlatform);
//继续登录流程
} catch (error) {

                    }  
                }, (e) => {  
                    console.log("获取code失败:" + e.message + " - " + e.code);  
                }, { scope: 'snsapi_userinfo', appid: 'wx0036105ea0a7417b' })  
            } else {  
                console.log("不支持微信登录");  
            }  
        })

操作步骤:

如上,简单的获得code并继续服务器验证。

预期结果:

获得正确的code

实际结果:

获得了过期的code

bug描述:

不在HBuilder中填写appsecret,使用authorize只通过客户都拿code的方式进行微信登录,报40029,估计是code重复获取,且通过authorize接口拿到的是旧的code。我们已多次检查,确定配置以及服务器逻辑都正常。

但如果填写了appsecret,使用login接口可以正常获得微信相关数据。

2020-12-21 13:47 负责人:无 分享
已邀请:
9***@qq.com

9***@qq.com (作者) - ----

后来发现这个问题其实是使用了默认的调试基座造成的。即使在XHuilder中填写了微信的appid没有正式打包前实际用的还是默认基座的appid,导致获取的code与服务器对应不上。

该问题目前已经被锁定, 无法添加新回复