当前位置:网站首页>Unicloud cloud development obtains applet user openid
Unicloud cloud development obtains applet user openid
2022-06-26 05:41:00 【Xiaojiexue front end】
Catalog
Two 、openid What is difficult to obtain
3、 ... and 、 Cloud development obtains openid
One 、 Introduce openid
We all need to use... When distinguishing applet users openid, user openid It is equivalent to the user's ID card in the applet . As the unique identification of the user , So get the user openid It's very important , Today, let's teach you how to get the unique identifier of the user openid
Two 、openid What is difficult to obtain
Today I tried many methods on the Internet , It can still be obtained during real machine debugging , As a result, once you upload the code, you can't get it , There should be many students who have encountered this problem , therefore We should put code The value goes to the back end to get openid, Because in the front end it may be caught or crawled to your appid and secret, unsafe , If you put it on the back end to get openid, Unless your server is attacked , Or it's safe .
3、 ... and 、 Cloud development obtains openid
1. First of all we have uniCloud In the catalog cloudfunctions Right click to create cloud function

2. Write cloud functions
'use strict';
exports.main = async (event, context) => {
let appid = "wxc00000000000";// Your own appid
let secret = "xxxxxxxxxxxxxxxxxxxxxxxx";// Your own appsecret
let url =
"https://api.weixin.qq.com/sns/jscode2session?appid=" +
appid +
"&secret=" +
secret +
"&js_code=" +
event.code +
"&grant_type=authorization_code";
let res = await uniCloud.httpclient.request(
url ,// Request path ,
{
dataType:"json"
}
);
let openid = res.data.openid
return openid
};Notice the appid and secret Use your own
3. Client calls uni.login(), Use what you get code Call cloud function
uni.login({
provider: "weixin",
success: function (res) {
uniCloud.callFunction({
name: 'openid',
data: {
code: res.code
},
success: (res) => {
console.log(' The value returned by the cloud function ::::', res.result)
},
fail: () => {
console.log(' Cloud function call failed ')
}
})
},
});4. Look at the output
Now we have successfully obtained the user's openid , It's too difficult to cross the river by feeling the stones , It's all blood and tears
边栏推荐
- 机器学习 07:PCA 及其 sklearn 源码解读
- cartographer_ local_ trajectory_ builder_ 2d
- Secondary bootloader about boot28 Precautions for ASM application, 28035
- SOFA Weekly | 开源人—于雨、本周 QA、本周 Contributor
- Redis discovery bloom filter
- 国务院发文,完善身份认证、电子印章等应用,加强数字政府建设
- Daily production training report (15)
- SDN based DDoS attack mitigation
- What management systems (Updates) for things like this
- Win socket programming (Mengxin initial battle)
猜你喜欢
The wechat team disclosed that the wechat interface is stuck with a super bug "15..." The context of

Mongodb image configuration method

MySQL数据库-01数据库概述
Posting - don't get lost in the ocean of Technology

Uni app ceiling fixed style
![[upsampling method opencv interpolation]](/img/6b/5e8f3c2844f0cbbbf03022e0efd5f0.png)
[upsampling method opencv interpolation]

Henkel database custom operator '~~‘
![[red team] what preparations should be made to join the red team?](/img/03/f246f18f8925167dbd5e9d63912faa.png)
[red team] what preparations should be made to join the red team?

When was the autowiredannotationbeanpostprocessor instantiated?

5分钟包你学会正则表达式
随机推荐
DOM文档
REUSE_ ALV_ GRID_ Display event implementation (data_changed)
bingc(继承)
Data storage: the difference between MySQL InnoDB and MyISAM
【活动推荐】云原生、产业互联网、低代码、Web3、元宇宙……哪个是 2022 年架构热点?...
最后一次飞翔
写在父亲节前
How to make your big file upload stable and fast?
cross entropy loss = log softmax + nll loss
Mise en file d'attente des messages en utilisant jedis Listening redis stream
RIA ideas
基于SDN的DDoS攻击缓解
新的征程
Redis installation on Linux
5分钟包你学会正则表达式
慢慢学JVM之缓存行和伪共享
A love that never leaves
pytorch(环境、tensorboard、transforms、torchvision、dataloader)
cartographer_ pose_ graph_ 2d
skimage. morphology. medial_ axis