微信小程序微信登陆

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=开发接口
登陆
wx.login
wx.checkSession
签名加密小程序

小程序登陆
小程序能够经过微信官方提供的登陆能力方便地获取微信提供的用户身份标识,快速创建小程序内的用户体系。服务器

登陆流程时序微信

小程序,开发者服务器,微信接口服务网络

wx.login()获取code
wx.request()发送codesession

登陆凭证校验接口
appid+appsecret+code
session_key+openid等app

自定义登陆
与openid,session_key关联ide

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

微信登陆受权:加密

wx.authorize
提早向用户发起受权请求,调用后会马上弹窗询问用户是否赞成受权小程序使用某项目功能或获取用户的某些数据,但不会实际调用对应的接口,若是用户以前就已经赞成受权,则不会出现弹窗。url

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

  •  
<button open-type="getUserInfo"></button>

userInfo参数说明:
nickName
avatarUrl
gender
city
province
country
language3d

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

  •  
wx.login({success (res) {if (res.code) {//发起网络请求wx.request({url: 'https://test.com/onLogin',data: {code: res.code}})} else {console.log('登陆失败!' + res.errMsg)}}})

wx.checkSession(Object object)
检查登陆态是否过时。

 

  •  
wx.checkSession({success () {//session_key 未过时,而且在本生命周期一直有效},fail () {// session_key 已经失效,须要从新执行登陆流程wx.login() //从新登陆}})

wx.getUserInfo(Object object)
获取用户信息。

  •  
// 必须是在用户已经受权的状况下调用wx.getUserInfo({success: function(res) {var userInfo = res.userInfovar nickName = userInfo.nickNamevar avatarUrl = userInfo.avatarUrlvar gender = userInfo.gender //性别 0:未知、1:男、2:女var province = userInfo.provincevar city = userInfo.cityvar country = userInfo.country}})
  •  
<!-- 若是只是展现用户头像昵称,能够使用 <open-data /> 组件 --><open-data type="userAvatarUrl"></open-data><open-data type="userNickName"></open-data><!-- 须要使用 button 来受权登陆 --><button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">受权登陆</button><view wx:else>请升级微信版本</view>
Page({data: {canIUse: wx.canIUse('button.open-type.getUserInfo')},onLoad: function() {// 查看是否受权wx.getSetting({success (res){if (res.authSetting['scope.userInfo']) {// 已经受权,能够直接调用 getUserInfo 获取头像昵称wx.getUserInfo({success: function(res) {console.log(res.userInfo)}})}}})},bindGetUserInfo (e) {console.log(e.detail.userInfo)}})

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

小程序登陆

  •  
const app = getApp()
Page({data: {},onLoad: function(params) {},// 登陆doLogin: function(e) {console.log(e.detail.errMsg)console.log(e.detail.userInfo)console.log(e.detail.rawData)wx.login({success (res) {if (res.code) {//发起网络请求wx.request({url: 'https://test.com/onLogin',data: {code: res.code}})} else {console.log('登陆失败!' + res.errMsg)}}})}})
  •  
<view><button class="goRegistBtn" type="warn" open-type='getUserInfo' bindgetusrinfo="doLogin">微信登陆</button></view>

 

wx.getUserInfo(Object object)

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

  •  
App({serverUrl: "",userInfo: null,setGlobalUserInfo: function(user) {wx.setStorageSync("userInfo", user);},
getGlobalUserInfo: function() {return wx.getStorageSync("userInfo");},
})

获取微信session_key和secret

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

相关文章
相关标签/搜索