获取微信的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
        }
     })
  }
})

写在最后:

  

posted @ 2021-09-01 15:08  _小狐狸  阅读(201)  评论(0编辑  收藏  举报