小程序获取form_id

介绍:小程序的 from_id 要在用户发生操作的时候才能产生,所以我们可以用以下方法来做

直接上代码

wxml

form bindsubmit="submitInfo" report-submit='true'      button form-type="submit"               // 此处我们可以定义一些即将要触发的事件的样式    /button  /form  

js

Page({    submitInfo: function (e) {        // 这样我们就可以获取到form_id了        console.log(e.detail.formId);      }})

小程序获取openid

一、首先获取code

      // 获取code        wx.login({            //获取code            success: function (res) {                // 这样我就拿到 code了                console.log(res.code)            }        })

二、根据code 获取openid

   // 获取到了openid    wx.request({        url:`https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${secret}&js_code=${code}&grant_type=authorization_code`,        data: {},        header: {            'content-type': 'application/json'        },        method: 'get',        success: function (res) {            // 这样就获取到了openid            console.log(res.data.openid)        }    })

TAG标签: 微信小程序设备id

http://www.xiaochengxub.com/read-100333.html