微信小程序前端获取OpenID和session_key

微信小程序前端获取OpenID和session_key

code2Session:

json 复制代码
https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code 
js 复制代码
wx.login({
    success: (res) => {
        console.log(res.code) //拿到code
        uni.request({
            url:
         	`https://api.weixin.qq.com/sns/jscode2session?
            appid=${appid}&secret=${密钥}&js_code=${res.code}&grant_type=authorization_code `,
            method: 'GET',
            success: (res) => {
                const {openid,session_key} = res.data;//拿到openid和session_key
                // 若要进行登录状态校验,需要在后端调用checkSessionKey接口
            }
        })
    }
})

checkSessionKey:

http 复制代码
https://api.weixin.qq.com/wxa/checksession?access_token=ACCESS_TOKEN&signature=SIGNATURE&openid=OPENID&sig_method=SIG_METHOD

参考文档1

参考文档2

相关推荐
万少21 小时前
Vibe Coding不停歇,移动端 TRAE SOLO 让你用手机也能编程啦
前端·javascript·后端
kyriewen1121 小时前
WebAssembly:前端界的“外挂”,让C++代码在浏览器里跑起来
开发语言·前端·javascript·c++·单元测试·ecmascript
烛衔溟1 天前
TypeScript 接口的基本使用 —— 定义对象形状
前端·javascript·typescript
铁皮饭盒1 天前
成为AI全栈 - 第3课:路由 RESTful Elysia 状态码 设计规范
前端·后端·全栈
顾昂_1 天前
Web 性能优化完全指南
前端·面试·性能优化
前端程序媛-Tian1 天前
前端 AI 提效实战:从 0 到 1 打造团队专属 AI 代码评审工具
前端·人工智能·ai
支付宝体验科技1 天前
Ant Design Pro v6.0.0 发布
前端
T畅N1 天前
审批流设计器(前端)
前端·elementui·vue·html·流程图·js
AlunYegeer1 天前
JAVA,以后端的视角理解前端。在全栈的路上迈出第一步。
java·开发语言·前端
IT_陈寒1 天前
Redis这个内存杀手,差点让我们运维半夜追杀我
前端·人工智能·后端