通過小程式登錄獲取小程式openID <button hidden="{{is_login}}" class='bottom' type='primary' open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="bindGetUserInfo" ...
通過小程式登錄獲取小程式openID
<button hidden="{{is_login}}" class='bottom' type='primary' open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="bindGetUserInfo" style='width:100px'>
登錄</button>
bindGetUserInfo: function (e) {
if (e.detail.userInfo) {
//用戶按了允許授權按鈕
var that = this;
//插入登錄的用戶的相關信息到資料庫
var openid = getApp().globalData.openid;
var session = getApp().globalData.session
getApp().globalData.userInfo = e.detail.userInfo;
//通過wx.login獲取code 想要獲取用戶信息,必須登錄
wx.login({
success: function(res){
if(res.code){
var code = res.code;
// 獲取 encryptedData iv
wx.getUserInfo({
withCredentials: true,
success: function(res2){
//請求自己的登錄介面
wx.request({
url: config.api_base_url + 'login',
data: {
userinfo: e.detail.userInfo,
openid: openid,
encryptedData:res2.encryptedData,
iv:res2.iv,
session:session
},
header: {
'content-type': 'application/json' // 預設值
},
method: 'post',
success(res) {
if (res.data.result == 1) {
wx.setStorageSync('user', res.data.msg);
that.onLoad();
that.setData({
is_login:true
})
} else {
console.log("寫入失敗")
}
}
})
}
})
}else{
console.log('獲取用戶登錄態失敗!'+res.errMsg);
}
}
})
return ;
//授權成功後,跳轉進入小程式首頁
} else {
//用戶按了拒絕按鈕
wx.showModal({
title: '警告',
content: '您點擊了拒絕授權,將無法進入小程式,請授權之後再進入!!!',
showCancel: false,
confirmText: '返回授權',
success: function (res) {
if (res.confirm) {
console.log('用戶點擊了“返回授權”')
}
}
})
}
},
小程式客服自定義回覆設置
開發->開發設置->找到消息推送,並設置
小程式點擊打開客服消息
通過發送消息,生成關註公眾號帶參數二維碼
然後發送給用戶
用戶通過掃描二維碼關註公眾號,從而實現小程式和公眾號的綁定
高顏值後臺管理系統免費使用 ### 子楓後臺管理系統 ###,可在寶塔面板直接安裝
歡迎關註我的公眾號:子楓的奇妙世界,獲得獨家整理的學習資源和日常乾貨推送。
如果您對我的其他專題內容感興趣,直達我的個人博客:www.wangmingchang.com 。