微信小程序登录流程时序
废话不多说,直接上代码:
html 代码
<button open-type="getUserInfo" bindtap="login">授权登录</button>
JS 代码
login(){
//通过wx.getUserProfile弹出授权框
wx.getUserProfile({
desc: 'desc',
success:res=>{
//通过wx.login获取code
wx.login({
success:d=>{
let code = d.code
//发送ajax请求,并将code携带过去
wx.request({
url: 'http://zy.com/index.php/api/wxLogin',
method:"POST",
data:{code},
success:e=>{
if(e.data.status==200){
wx.showToast({
title: e.data.message,
})