收藏
回答

大佬指点一下萌新 怎么获取微信昵称头像吧?

<template>

<view>


<view>

<view>

<view class='header'>

<image src='../../static/image/wx_login.png'></image>

</view>

<view class='content'>

<view>申请获取以下权限</view>

<text>获得你的公开信息(昵称,头像、地区等)</text>

</view>

<!-- 

<button class='bottom' type='primary' open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="getUserInfo">

授权登录

</button> -->

<button class='bottom' type='primary' withCredentials="true" lang="zh_CN" @click="getUserInfo">

授权登录

</button>


<button class='bottom' type='primary' open-type="getUserInfo" withCredentials="true" lang="zh_CN"

@click="quxiao">

暂不登录

</button>

</view>

</view>


</view>

</template>

<script>

import {


} from 'vuex';

export default {

// computed: {  

//           ...mapState(['userInfo'])

//       },

data() {

return {


}

},

onLoad() {


// 获取用户信息

var _self = this;

_self.$uniApi.checkPhone("");

            this.get_wx_code();

},

methods: {

get_wx_code(){

uni.login({

provider: 'weixin',

success: (res) => {

this.code = res.code;

}

})

},

getUserInfo() {

    const that = this; 

uni.getUserProfile({

// provider: 'weixin',

desc:'仅用于展示用户头像与昵称',

success: function(infoRes) {

if (infoRes.errMsg == "getUserProfile:ok") {

console.log(infoRes);

uni.request({

url: 'https://xxx.com/App/Zm/oneRegister',

header: {

'content-type': 'application/x-www-form-urlencoded',

},

method: 'POST',

data: {

uuid: that.code,

avatarUrl: infoRes.userInfo.avatarUrl,

nickName: infoRes.userInfo.nickName

},

success: (ret) => {

console.log(JSON.stringify(ret.data));

if (ret.statusCode !== 200) {

console.log('请求失败', ret);

return;

}

if (ret.data.code == 1) {

// 取数据并赋值

uni.setStorageSync('user_id', ret.data

.msg.id);

uni.setStorageSync('username', ret.data

.msg.username);

uni.setStorageSync('userimg', ret.data

.msg.userimg);

uni.setStorageSync('jifen', ret.data

.msg.jifen);

uni.setStorageSync('viptime', ret.data

.msg.viptime);

uni.setStorageSync('buy', ret.data.msg

.buy);

uni.setStorageSync('collect', ret.data

.msg.collect);

// 关闭动画

uni.hideLoading();

// 跳转到首页

uni.reLaunch({

url: '../index/index'

});

} else {

// 关闭动画

// 气泡提示

uni.showToast({

title: ret.data.msg,

icon: 'none',

duration: 2000

});

}

}

});

} else {

uni.showToast({

title: '系统异常,请联系管理员!'

})

}

},

fail: () => {

uni.showToast({

title: '获取用户信息失败',

icon: 'none'

});

}

});


},

quxiao() {

uni.reLaunch({

url: '../index/index'

});

}


},



}

</script>

<style>

.header {

margin: 90rpx 0 90rpx 50rpx;

border-bottom: 1px solid #ccc;

text-align: center;

width: 650rpx;

height: 300rpx;

line-height: 450rpx;

}


.header image {

width: 200rpx;

height: 200rpx;

}


.content {

margin-left: 50rpx;

margin-bottom: 90rpx;

}


.content text {

display: block;

color: #9d9d9d;

margin-top: 40rpx;

}


.bottom {

border-radius: 80rpx;

margin: 70rpx 50rpx;

font-size: 35rpx;

}

</style>

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容