In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Wechat official account development how to carry out silent authorization login, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Basic concepts:
What is openid? a WeChat account and an official account correspond to a fixed openid. So the openid of a WeChat account under an official account is unchanged. If you change a corresponding official account, it will be another openid. And only items opened in Wechat's own browser are available.
What is UnionID? if developers have multiple mobile applications, website apps, official accounts and Mini Program, they can distinguish the uniqueness of users through UnionID, because as long as they are mobile apps, website apps, official accounts and Mini Program under the same Wechat development platform account, the user's UnionID is unique. In other words, the same user, for different applications of the same Wechat development platform, UnionID is unique.
Preparation conditions: an official account, a domain name accessible through the public network, the AppID and AppSecret of the official account, and the authorized domain name of the web page (log in to the public platform settings-> official account settings-> function settings-> web authorized domain name to follow the steps and set up). This domain name is the domain name issued by the web project of openid. Please note that the server must be at port 80.
The first step is to obtain the code// authorization access link after the https://open.weixin.qq.com/connect/oauth3/authorize?appid=XXXXXXXX&redirect_uri=http://test-recycle-h6.jxypapp.com&response_type=code&scope=snsapi_base&state=%7B%22id%22%3D%221%22%2C%22name%22%3A%22xiaoming%22%7D#wechat_redirect// authorization is successful. Redirect Link http://test-recycle-h6.jxypapp.com/?code=0215ZMRH0rVjli29oYTH0exORH05ZMRz&state=%7B%22id%22%3D%221%22%2C%22name%22%3A%22xiaoming%22%7D
Parameter explanation:
Appid: official account appid.
Redirect_uri: enter the url of the jump after the Wechat recognition is successful (encode encoding is required).
Response_type: just fill in code, no need to modify it.
Scope: two values can be entered (snsapi_base (silent authorization) and snsapi_userinfo (authorization method of pop-up authorization page), where the former is only openid and does not require user authorization, and the latter requires user authorization in order to obtain user information.
State: custom parameter. The state parameter will be added after redirection. Developers can enter the parameter value of a-zA-Z0-9, up to 128byte (encode encoding is required to transfer json data).
# wechat_redirect: specify the jump in Wechat, which can be left empty at ordinary times, but must be entered when redirecting!
Note:
Redirect_uri requires encode encoding, otherwise the page will display "redirect_ur parameter error!" !
The domain name of the redirect_uri URL must be. You need to enter the domain name authorized for callback page in the Wechat public platform account. You need to log in to the backend of Wechat public platform, click modify in the user information, and fill in your own domain name. Note: the domain name in the authorized callback page does not have http://.
The second step is to get openid https://api.weixin.qq.com/sns/oauth3/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
Parameter explanation:
Appid: ditto
Secret: ditto
Code: enter the code parameters obtained in the first step
Grant_type: enter as authorization_code
Note:
If the H6 page calls the secondary interface directly, there may be a cross-domain problem. You can ask the backend to call this API.
Return the result:
{"access_token": "ACCESS_TOKEN", "expires_in": 7200, "refresh_token": "REFRESH_TOKEN", "openid": "OPENID", "scope": "SCOPE"} step 3, get access_token
Access_token is the global unique API call credential of the official account, and access_token is required when the official account calls each API. Developers need to save it properly. At least 512 character space should be reserved for access_token storage. The access_token is valid for 2 hours and needs to be refreshed regularly. Repeated acquisition will invalidate the last acquired access_token.
Interface description
Https request method: GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
Parameter description
Grant_type: get access_token and enter client_credential
Appid: unique credentials of third-party users
Secret: the unique credential key of a third-party user, i.e. appsecret
Return the result
{"access_token": "ACCESS_TOKEN", "expires_in": 7200} step 4: get user information API call request description http request method: GET https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
Parameter explanation:
Access_token calls the API credential, and the access_token obtained in step 3
The identity of an ordinary openid user, which is unique to the current official account. The openid obtained in step 2
Lang returns national and regional language version, zh_CN simplified, zh_TW traditional, en English
{"subscribe": 1, / / whether to follow this public account, 0-not, 1-follow "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M", / / the identity of the user, the only "nickname" for the current official account: "Band", / / the nickname "sex" of the user: 1, / / the sex of the user, the value is 1 is male, the value is 2 is female A value of 0 is unknown "language": "zh_CN", / / user's language Simplified Chinese for zh_CN "city": "Guangzhou", / / user's city "province": "Guangdong", / / user's province "country": "China", / / user's country "headimgurl": "http://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0", / / user profile picture" subscribe_time ": 1382694957, / / user's attention time is a timestamp. If the user has followed multiple times, take the last follow time "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL", / / this field will not appear until the user binds the official account to the Wechat open platform account. "remark": ", / / official account operator's remarks to fans Official account operators can add comments to fans in the user management interface of Wechat public platform: "groupid": 0, / / the grouping of users ID (compatible with the old user grouping interface) "tagid_list": [128 dome 2], the ID list marked with the tag "subscribe_scene": "ADD_SCENE_QR_CODE", / / return the channel source of the user's attention, and search on the ADD_SCENE_SEARCH official account. ADD_SCENE_ACCOUNT_MIGRATION official account migration, ADD_SCENE_PROFILE_CARD business card sharing, ADD_SCENE_QR_CODE scan QR code, name click in ADD_SCENEPROFILE LINK picture and text page, menu in the upper right corner of ADD_SCENE_PROFILE_ITEM picture and text page, ADD_SCENE_PAID follow after payment, ADD_SCENE_OTHERS other "qr_scene": 98765, "qr_scene_str": ""} read the above content Have you mastered the method of silent authorization login in the development of Wechat official account? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.