laya 发布的体验版 有很大的概率 wx.createUserInfoButton在真机上无效 ,创建不出按钮,但在 开发者工具上 每次都可创建出获取授权按钮
是什么原因呢? 是不是因为没正式发布?还是代码有问题?
private WxLogin() { if (Laya.Browser.onMiniGame) { wx.login({ pkgName: "" , success: res => { let code = res.code; if (code == null ) { LoginScenesMgr.Instance._CloseGame(); return ; } else { UserAccInfo.wx_Code = code; } //获取设置 wx.getSetting({ success: (res) => { //已经进行了授权 if (res.authSetting[ 'scope.userInfo' ]) { console.log( "已经授权了 直接获取数据 " ) wx.getUserInfo({ lang: "zh_CN" , withCredentials: true , success: (res) => { LoginScenesMgr.Instance.SetUserWxInfo(res); console.log( "已经授权 直接获取信息 成功" ); }, fail: () => { console.log( "getUserInfo fail" ); wx.showModal({ title: '友情提醒' , cancelText: "取消" , cancelColor: '#000000' , content: '请允许微信获得授权!' , confirmText: "确定" , showCancel: false , confirmColor: "#3CC51F" , success: res => { }, fail: () => { }, complete: () => { } }); }, complete: () => { } }); } else { console.log( "没有授权 创建登陆按钮" ); LoginScenesMgr.Instance.wxLoginBtn = wx.createUserInfoButton({ type: 'image' , image: 'res/Ui/wxLogin.png' , style: { left: wx.getSystemInfoSync().windowWidth / 2 - 75, bottom: 90, width: 150, height: 60, } }); LoginScenesMgr.Instance.wxLoginBtn.onTap((res) => { if (res.errMsg == "getUserInfo:ok" ) { LoginScenesMgr.Instance.SetUserWxInfo(res); console.log( "点击按钮" ); } else { wx.showModal({ title: '友情提醒' , cancelText: "取消" , cancelColor: '#000000' , content: '请允许微信获得授权!' , confirmText: "确定" , showCancel: false , confirmColor: "#3CC51F" , success: res => { }, fail: () => { }, complete: () => { } }); } }); } }, fail: () => { LoginScenesMgr.Instance._CloseGame(); console.log( "getSetting fail" ); }, complete: () => { } }) //wx.getSetting }, fail: () => { console.log( "wx.login" ); LoginScenesMgr.Instance._CloseGame(); }, complete: () => { } }); } } |
烦请通过以下链接创建一下代码片段,感谢配合。(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。