微信小程序使用Opneid接口获取Openid示例

rambo 3个月前 阅读:718 评论:0
微信小程序使用Opneid接口获取Openid示例,此代码放在任何位置都可以执行,比如按钮事件、页面加载事件等、定时事件等。    wx.login({    ...

微信小程序使用Opneid接口获取Openid示例,此代码放在任何位置都可以执行,比如按钮事件、页面加载事件等、定时事件等。

    wx.login({
      success: (res) => {
        wx.request({
          url: 'https://cloud.huaxio.cn/php/openidapi/server/opeapi.php',
          data: {
            apiname: '', //你的接口名称
            apipswd: '', //你的接口密码
            code: res.code
          },
          method: 'post',
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          dataType: 'json',
          responseType: 'text',
          success: (res) => {
            console.log('openid=' + res.data)
          },
        })
      },
    })


热门文章
标签列表