小程序获取登录微信用户信息

linkaiyi
Follow

获得登录用户的微信信息

<button class="sys_btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="appLoginWx">{{loginInfo.openid != "" && loginInfo.openid != undefined ? "已授权" : "小程序授权"}}</button>

appLoginWx(e){
                console.log(e)
                // #ifdef MP-WEIXIN
                  uni.getProvider({
                   service: 'oauth',
                   success: function (res) {
                    if (~res.provider.indexOf('weixin')) {
                      uni.login({
                        provider: 'weixin',
                        success: (res) => {
                          //_self.authorization = res.code;
                          uni.getUserInfo({
                            provider: 'weixin',
                            success: (info) => {//这里请求接口
                              console.log(res);
                              console.log(info);

                            },
                            fail: () => {
                              uni.showToast({title:"微信登录授权失败",icon:"none"});
                            }
                          })

                        },
                        fail: () => {
                          uni.showToast({title:"微信登录授权失败",icon:"none"});
                        }
                      })

                    }else{
                      uni.showToast({
                        title: '请先安装微信或升级版本',
                        icon:"none"
                      });
                    }
                   }
                  });
                  //#endif
              },
Object has 0 attachments

Was this article helpful?

This article is viewed 48 times!

Recent Viewed Articles

Related Articles

0 Comments

Leave a Comment

Support