• 小程序获取form_id 与 小程序获取openid


    小程序获取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)
            }
        })
    
  • 相关阅读:
    Python 三级菜单
    linux 下按文件类型删除
    linux 做内网端口映射
    ss
    fio
    libXtst.so.6 is needed by teamviewer-12.0.76279-0.i686
    copy 浅复制 与深复制
    Git 使用方法
    关于 爬虫使用 urllib.urlopen 提交默认 User-Agent值
    Python 官方模块文档
  • 原文地址:https://www.cnblogs.com/ningzy/p/9166499.html
Copyright © 2020-2023  润新知