您的位置:首页 > 移动开发 > 微信开发

uniapp做微信登录

2020-06-04 06:47 330 查看

下面展示一些

内联代码片

// An highlighted block
<!-- #ifdef MP-WEIXIN -->
<view>
<view>
<view class='header'>
<image src='/static/common/WeChat.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="wxLogin">
授权登录
</button>
</view>
</view>
<!-- #endif -->
// An highlighted block
<!-- #ifdef MP-WEIXIN -->
<view>
<view>
<view class='header'>
<image src='/static/common/WeChat.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="wxLogin">
授权登录
</button>
</view>
</view>
<!-- #endif -->
// An highlighted block
wxLogin(e) {
let _this = this;
if (e.detail.userInfo) {
uni.login({
provider: "weixin",
success(res) {
//获得微信授权码
var code = res.code
_this.$LoadingMsg("登录中")
uni.request({
url: _this.$api.getAccessToken,
data: {
code: code,
},
method: 'GET',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success(res) {
if (res.data.code == 0) {
uni.hideLoading()
if(res.data.data.code){
uni.navigateTo({
url:"/pages/login/sms?openId="+res.data.data.openId
})
}else{

}

}
}
})
}
})
} else {
console.log("拒绝")
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: