当前位置: 首页 > 工具软件 > Python OpenID > 使用案例 >

微信小程序之获取openid

谷梁玺
2023-12-01

1.获取openid
appid和秘钥在小程序后台可获取

  //获取openid
  openid() {
    let that = this
    wx.login({
      success(res) {
        wx.request({
          url: 'https://api.weixin.qq.com/sns/jscode2session',
          method: 'GET',
          data: {
            appid: "",//appid
            secret: "",//秘钥
            js_code: res.code,
            grant_type: "authorization_code"
          },
          success: (res) => {
             that.setData({
               openid: res.data.openid
             })
          }
        })
      }
    })
  },

 类似资料: