微信小程序之登錄
阿新 • • 發佈:2019-05-03
ati func important inline app_id 分享 sns ret clas
微信小程序登錄基本流程就是
1、
wx.login獲取js_code 根據app_id, secret, js_code 數據 wx.request 獲取用戶的openid和session_key 請求地址:https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
wx.login({ success(res) {if (res.code) { console.log(res.code) // 發起網絡請求 wx.request({ url: ‘https://api.weixin.qq.com/sns/jscode2session‘, data: { appid:‘*******‘, secret:‘*******‘, js_code:res.code, grant_type:‘authorization_code‘ }, success:function(data){ console.log(data); }, fail:function(error){ console.log(error); } }) } else { console.log(‘登錄失敗!‘ + res.errMsg) } } })
微信小程序之登錄