小程序模板網(wǎng)

微信小程序獲得openid免密登錄

發(fā)布時(shí)間:2018-12-29 08:41 所屬欄目:小程序開發(fā)教程
{
  wx.login({
    success: res => {
      let d = {
        appid: 'wx111111111111', // 從微信公眾平臺開發(fā)設(shè)置中獲取
        secret: 'sec2222222222' // 從微信公眾平臺開發(fā)設(shè)置中獲取
      };
      // 微信官方的獲取openid的接口
      var wxLoginUrl = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + d.appid +'&secret=' 
      + d.secret + '&js_code=' + res.code + '&grant_type=authorization_code';
      wx.request({
        url: wxLoginUrl,
        data: {},
        method: 'GET',
        success: res => {
           let openid = res.data.openid;
          this.judgeIsWxlogin(openid); // 向后端發(fā)送openid判斷是否可以直接用該微信號登陸
        }
      });
    }
  });
}
從微信公眾平臺開發(fā)設(shè)置中獲取appid和secret:
 
 
 
 


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.u-renovate.com/wxmini/doc/course/25054.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢
AI智能客服 ×