文章详情
【微信小程序】微信小程序获取用户信息为“微信用户”解决方案--学习微信小程序之路06
发布时间:2022-01-09
沉默小管-技术博客
微信小程序获取用户信息为“微信用户”解决方案--学习微信小程序之路06
1249
2
原文地址:
https://www.php-china.com//detail/95
H1
H2
H3
H4
H5
H6
# 问题描述 微信小程序使用wx.getUserInfo获取用户信息为微信用户,根据微信小程序文档说明,该函数旧方法应该是被废弃了 [https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html) # 解决流程 wxml代码 ```html <view class='Popup' hidden='{{iShidden}}'> <image src='../../assets/img/logo.png'></image> <view class='title'>授权提醒</view> <view class='tip'>请授权头像等信息,以便为您提供更好的服务</view> <view class='bottom flex'> <view class='item' bindtap='close'>随便逛逛</view> <button class='item grant theme-icon-color-yellow' wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 去授权 </button> <button class='item grant theme-icon-color-yellow' wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 去授权 </button> </view> </view> ``` js代码 ```javascript data: { cloneIner: null, loading:false, errorSum:0, errorNum:3, userInfo: {}, hasUserInfo: false, canIUseGetUserProfile: false }, attached() { //判断微信是否可以使用wx.getUserProfile if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } }, methods: { getUserProfile(e) { wx.showLoading() wx.getUserProfile({ desc: '用于完善会员资料', success: (res) => { this.getWxUserInfo(res); } }) }, getUserInfo(e) { this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) }, getWxUserInfo(res){ console.log(res); let that = this; // let code = res.code; let nickName = res.userInfo.nickName; let avatarUrl = res.userInfo.avatarUrl; console.log(avatarUrl); } }, ```
上一篇
下一篇
收藏
支持
标签:
最新文章
统计信息
联系站长
加入技术群
日志总数:92篇
网站运行:1424天
累计访客:13007
热门文章
1. PHP基础概念
2. redis:ERR AUTH <password> called without any password configured for the default user解决办法
3. PHP的语言结构之包含文件
4. PHP中public,private,protected的区别
5. PHP魔术方法总结
6. php如何转换json格式中的中文
7. PHP7新特性(常用)
8. PHP7上项目报错A non-numeric value encountered解决办法
9. 运行golang出现invalid memory address or nil pointer dereference错误
10. git常用命令集合