收藏
回答

Unity中用C#脚本编写用户授权按纽,在微信开发者工具中或真机中没有弹出授权窗,请问这是为什么?

C#脚本创建授权按纽:

var btn = WXBase.CreateUserInfoButton(50, 50,300,50, "zh_CN", false);
btn.Show();


继而onTap也没有反应

btn.OnTap(response =>
{
    Debug.Log("用户点击了按纽");
    Debug.Log(response.userInfo);
    Debug.Log(response.callbackId);
    Debug.Log(response.errMsg);
});

btn.OnTap(delegate(WXUserInfoResponse response)
{
    print(response.userInfo);
    print(response.callbackId);
    print(response.errMsg);
});
回答关注问题邀请回答
收藏

1 个回答

  • 春季电脑13832625952
    春季电脑13832625952
    2023-01-03

    自己在GitHub上找到的官方示例,针对自己的项目,相应的修改一下,即可使用。

    // 创建用户信息获取按钮,在底部1/3区域创建一个透明区域
    // 首次获取会弹出用户授权窗口, 可通过右上角-设置-权限管理用户的授权记录
    var systemInfo = WX.GetSystemInfoSync();
    var canvasWith = (int)(systemInfo.screenWidth * systemInfo.pixelRatio);
    var canvasHeight = (int)(systemInfo.screenHeight * systemInfo.pixelRatio);
    var buttonHeight = (int)(canvasWith / 1080f * 300f);
    var infoButton = WX.CreateUserInfoButton(0, canvasHeight - buttonHeight, canvasWith, buttonHeight, "zh_CN", false);
    infoButton.OnTap((userInfoButonRet) =>
                {
                    Debug.Log(JsonUtility.ToJson(userInfoButonRet.userInfo));
                    txtUserInfo.text = $"nickName:{userInfoButonRet.userInfo.nickName}, avartar:{userInfoButonRet.userInfo.avatarUrl}";
                });
    Debug.Log("infoButton Created");
    


    2023-01-03
    有用 2
    回复
登录 后发表内容