当前位置:网站首页>With the solution, the nickname of the applet suddenly becomes "wechat user", and the avatar cannot be displayed?
With the solution, the nickname of the applet suddenly becomes "wechat user", and the avatar cannot be displayed?
2022-06-24 16:56:00 【Programming pebbles】
Recently, many small partners are using getUserInfo When getting user nicknames and avatars of applets , The picture turns to the following .
bug splat
A lot of little friends must have doubts , I didn't make any changes in my code , How come all of a sudden . Remember we should have looked like this before .
Brother stone has encountered such a problem recently , There are two reasons I first thought of
1, Wechat official server is down ( The probability is very small )
2, Wechat has changed the rules again ...
With such doubts , I went to ask the official staff of wechat app . The answer is ...
Ten thousand psychological ..... Ah , Can't , Since the official said to change the rules , We as vulnerable groups , It can only be changed according to the official rules .
Code changes
Fortunately, the code change momentum is not very big , Basically change 5 Just one line of code . Let's teach you how to change the code .
1, Let's look at the old code first
js The old code in
You can see that we use old code , What we got is the gray head and WeChat users Such a nickname
2, know wx.getUserProfile
Actually this wx.getUserProfile And we used button combination open-type="getUserInfo" and bindgetuserinfo It doesn't make much difference that events get user information , So let's get to know wx.getUserProfile
In fact, there are some advantages to this change , That is, we just need to call... In the click event wx.getUserProfile You can turn up the authorization pop-up window , There's no need to be button Click events are used in components .
Problem solving code
1,wxml Code changes in
2 js Code changes in
Here we mainly use
wx.getUserProfile({
desc: ' It is used to improve the membership information ', // Declare the purpose of obtaining the user's personal information , The follow-up will be shown in the pop-up window , Please fill in carefully
success: (res) => {
console.log(" User information obtained successfully ", res)
},
fail: res => {
console.log(" Failed to get user information ", res)
}
})You can see that you can successfully turn up the authorization pop-up window
And you can get the real nickname
In fact, we will transform it here , In fact, it's just a matter of a few lines of code , The trouble is that our small program has to be submitted for review again because of this change ....
Supplementary information : Save user information to cache
If we let users click authorization every time we enter the page , It's a little too annoying , In fact, the data can be cached in the local cache when the first authorization successfully obtains the user information . Let's teach you how to cache user information .
The code and complete comments are posted to you
Mainly to call
wx.setStorageSync Save data to local cache
wx.getStorageSync Fetching cache data
wxml The code of the page is also posted to you
And our wxss style
We'll fill the official hole here .
边栏推荐
- Week7 weekly report
- Tencent security officially released the IOT security capability map
- 构建跨公链平台解决DApp开发问题
- How to collect and define project requirements in the early stage of EDI project implementation?
- A survey on dynamic neural networks for natural language processing, University of California
- zblog系统实现前台调用当天发布文章数量的教程
- [the activity is over, and the list of winners is announced] in March, techo youth university open class demo practice
- Can you remember the code of a programming boss? Can you hit it out without Baidu?
- TVP experts talk about geese factory middleware: innovating forward and meeting the future
- It may be a good idea to use simulation software in the cloud for simulation
猜你喜欢
![[leetcode108] convert an ordered array into a binary search tree (medium order traversal)](/img/e1/0fac59a531040d74fd7531e2840eb5.jpg)
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)

Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)

A survey of training on graphs: taxonomy, methods, and Applications

A survey on model compression for natural language processing (NLP model compression overview)

A survey on dynamic neural networks for natural language processing, University of California

MySQL learning -- table structure of SQL test questions
随机推荐
Principle analysis of robot hardware in the loop system
Hook graphics kernel subsystem
TRTC web end imitation Tencent conference microphone mute detection
Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)
zblog系统如何根据用户ID获取用户相关信息的教程
Page scrolling effect library, a little skinny
Development of block hash game guessing system (mature code)
The mystery of redis data migration capacity
Several schemes of traffic exposure in kubernetes cluster
Building a cross public chain platform to solve DAPP development problems
NFT元宇宙源码搭建解析与介绍
One Minute! No code! Add [statistical analysis] to the website
Saying "Dharma" Today: the little "secret" of paramter and localparam
What is a reptile
Today, Tencent safety and SAIC Group officially announced!
[play with Tencent cloud] TSF User Guide
[play with Tencent cloud] my operation strategy from domain name application to website filing in Tencent cloud
Kubernetes 1.20.5 setting up Sentinel
Data acquisition and transmission instrument reservoir dam safety monitoring
Tencent blue whale Zhiyun community version v6.0.3 was officially released together with the container management platform!