获取微信的openId

原料 :
  需要 appidsecret
备注:
  前端写死appid和secret的话,小程序不给过审。
  so,最好是服务端获取openId
wx.login({
   success (res) {
     wx.request({
        url: 'https://api.weixin.qq.com/sns/jscode2session', //固定接口
        method: 'get',
        data: {
             appid: 'appid',
             secret: 'secret',
             js_code:res.code,
             grant_type:'authorization_code'
        },
        header: {
             'content-type': 'application/json' // 默认值
        },
        success (res) {
             console.log( res.data.openid ) // openid
        }
     })
  }
})

写在最后:

  

本文来自博客园,作者:_小狐狸,转载请注明原文链接:https://www.cnblogs.com/zwh520/p/15214698.html

原文地址:https://www.cnblogs.com/zwh520/p/15214698.html