收藏
回答

laya 发布的体验版小游戏 真机上大概率创建不出获取授权按钮

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小游戏 Bug createUserInfoButton 客户端 7.0.4 2.7.2

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: () => { }
            });
        }
    }



最后一次编辑于  2019-06-20
回答关注问题邀请回答
收藏

1 个回答

  • 小游戏运营专员-宏
    小游戏运营专员-宏
    2019-06-21

    烦请通过以下链接创建一下代码片段,感谢配合。(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2019-06-21
    赞同
    回复
登录 后发表内容