流程图
创建授权按钮,向后台获取unionid
<template>
<view style="margin-top: 60%;">
<!-- <button type="default" open-type="getUserInfo" @getuserinfo='getuserinfo'>微信授权</button> -->
<view style="text-align: center;">申请获取你的公开信息(昵称,头像等)</view>
<button
open-type="getUserInfo"
withCredentials="true"
class="mc btn-auth"
@getuserinfo="getUserInfo"
>
授权登录
</button>
</view>
</template>
<script>
export default {
data() {
return {
code:"",
next:"",
}
},
onLoad(e) {
this.next=e.next;
},
onReady() {
},
methods: {
getUserInfo() {
// let = {};
// var that= this
let _this = this;
uni.login({
provider: "weixin",
success: (res) => {
let code = res.code;
uni.getUserInfo({
provider: "weixin",
lang: "zh_CN",
success: function(res) {
uni.request({
url: getApp().globalData.url+'/wechat/login',
data: {
rawData:res.rawData,//用户信息
signature:"111",
code: code,
encryptedData:res.encryptedData,
iv:res.iv,
},
method:'POST',
header: {
'Content-Type': 'application/json',
},
success: (res) => {
if(res.data.status==200){
// 添加缓存
uni.setStorage({
key: 'unionId',
data: res.data.data.userInfo.unionId,
success: function () {
console.log(