国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home WeChat Applet WeChat Development Implementation steps for obtaining web page authorization for WeChat public accounts

Implementation steps for obtaining web page authorization for WeChat public accounts

Apr 02, 2017 pm 04:08 PM

Develop official documents based on WeChat public account:

The steps to obtain user information are as follows:

1 Step 1: User agrees to authorize and obtain code
2 Step 2 : Exchange webpage authorization access_token through code
3 Step 3: Refresh access_token (if necessary)
4 Step 4: Pull user information (need to have scope snsapi_userinfo)

1 Get code

Under the premise of ensuring that the WeChat public account has the permissions of the authorization scope (scope parameter) (the service account obtains advanced Interface, by default it has snsapi_base and snsapi_userinfo in the scope parameter).

If it prompts "The link cannot be accessed", please check whether the parameters are filled in incorrectly and whether you have the corresponding scope parameters. Authorization scope permissions.

Special attention: Due to the high security level of authorization operations, when initiating an authorization request, WeChat will perform a regular strong matching check on the authorization link. If the order of the parameters of the link is incorrect, , the authorization page will not be accessible normally

Among them:

AppID - the unique identifier of the official account
REDIRECT_URI - jump url
SCOPE - the value is snsapi_base (no pop-up The authorization page jumps directly and can only obtain the user's openid) or snsapi_userinfo (the authorization page pops up and you can get the nickname, gender, and location through openid. Moreover, even if you are not following the user, you can also obtain the information as long as the user authorizes it. )
STATE - Developers can customize the parameter value of a-zA-Z0-9

2 Exchange the code for web page authorization access_token

If the user agrees to the authorization, the page will jump Go to redirect_uri/?code=CODE&state=STATE.
state is the STATE parameter passed as it is.

Implementation code:

<code class="hljs php">$code = I(&#39;get.code&#39;);
if (empty($code)) {
   //todo 非微信訪問
   exit(&#39;</code>&#39;);
 }else{ //授權后操作 }

Here we can get the code. To obtain the access_token later.

After obtaining the code, request the following link to obtain the access_token:

appid - the unique identifier of the official account
secret - the key
code - returned by the above The code
grant_type - the value is authorization_code

implementation code:

<code class="hljs bash">$url = &#39;https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=&#39; . C(&#39;wechat.AppID&#39;) . &#39;&secret=&#39; . C(&#39;wechat.AppSecret&#39;);
$str = file_get_contents($url);
$str = json_decode($str, true);
$access_token = $str[&#39;access_token&#39;];</code>

The access_token here can be cache processed to avoid frequent retrieval of the
implementation code to Take the TP framework as an example:

<code class="hljs php">$access_token = S(&#39;access_token&#39;);
if (empty($access_token)) {
  $url = &#39;https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=&#39; . C(&#39;wechat.AppID&#39;) . &#39;&secret=&#39; . C(&#39;wechat.AppSecret&#39;);
  $str = file_get_contents($url);
  $str = json_decode($str, true);
  $access_token = $str[&#39;access_token&#39;];
  S(&#39;access_token&#39;, $access_token, 3600);
}</code>

After obtaining the access_token, openid (the user’s unique identifier) ??will also be returned. The official WeChat document explains: The user’s unique identifier. Please note that when you are not following the official account, When a user visits the webpage of an official account, an OpenID unique to the user and the official account will also be generated.

openid uniquely identifies the WeChat user. If the user is not logging in for the first time, he can get the openidQueryWhether the database has a user bound to this openid, then there is no need to re-obtain user data, directly obtain the database user_id settingsession, directly log in to access

3 Step 3 Ignore, just re-obtain the access_token when needed

4 Pull user information (need to have scope snsapi_userinfo)

If the database does not have this WeChat ID user binding, it is equivalent to the user When logging in for the first time, go through the fourth step to obtain user information (in the case of user authorization, the web page authorization scope is snsapi_userinfo, then the developer can pull user information through access_token and openid at this time), and then create a user in the background and bind it Define this WeChat user

(via openid)

Request method

http: GET (please use https protocol)

access_token - the access_token obtained above
openid - the unique identifier of the official account

<code class="hljs php">$url="https://api.weixin.qq.com/cgi-bin/user/info?access_token=$access_token&openid=$openid&lang=zh_CN";
   $str = file_get_contents($url);
   $str = json_decode($str, true);
   if (empty($str[&#39;errcode&#39;])) {  
   //創(chuàng)建user并綁定
   openid}else{  
   //錯誤處理}</code>

The above is the detailed content of Implementation steps for obtaining web page authorization for WeChat public accounts. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
Scrapy implements crawling and analysis of WeChat public account articles Scrapy implements crawling and analysis of WeChat public account articles Jun 22, 2023 am 09:41 AM

Scrapy implements article crawling and analysis of WeChat public accounts. WeChat is a popular social media application in recent years, and the public accounts operated in it also play a very important role. As we all know, WeChat public accounts are an ocean of information and knowledge, because each public account can publish articles, graphic messages and other information. This information can be widely used in many fields, such as media reports, academic research, etc. So, this article will introduce how to use the Scrapy framework to crawl and analyze WeChat public account articles. Scr

What are the differences between WeChat official account certification and non-certification? What are the differences between WeChat official account certification and non-certification? Sep 19, 2023 pm 02:15 PM

The difference between WeChat public account authentication and non-authentication lies in the authentication logo, function permissions, push frequency, interface permissions and user trust. Detailed introduction: 1. Certification logo. Certified public accounts will obtain the official certification logo, which is the blue V logo. This logo can increase the credibility and authority of the public account and make it easier for users to identify the real official public account; 2. Function permissions. Certified public accounts have more functions and permissions than uncertified public accounts. For example, certified public accounts can apply to activate the WeChat payment function to achieve online payment and commercial operations, etc.

Practical crawler combat in Python: WeChat public account crawler Practical crawler combat in Python: WeChat public account crawler Jun 10, 2023 am 09:01 AM

Python is an elegant programming language with powerful data processing and web crawling capabilities. In this digital era, the Internet is filled with a large amount of data, and crawlers have become an important means of obtaining data. Therefore, Python crawlers are widely used in data analysis and mining. In this article, we will introduce how to use Python crawler to obtain WeChat public account article information. WeChat official account is a popular social media platform for publishing articles online and is an important tool for promotion and marketing of many companies and self-media.

Use PHP to build a WeChat public account API interface Use PHP to build a WeChat public account API interface May 13, 2023 pm 12:01 PM

In today's Internet era, WeChat official accounts have become an important marketing channel for more and more companies. If you want your WeChat official account to implement more functions, you often need to write corresponding interfaces. This article will use PHP language as an example to introduce how to build a WeChat public account API interface. 1. Preparation Before writing the WeChat public account API interface, the developer needs to have a WeChat public account and apply for developer interface permissions in the WeChat public platform. After the application is successful, you can obtain the relevant developer AppID and AppSe

How to use Laravel to develop an online ordering system based on WeChat public account How to use Laravel to develop an online ordering system based on WeChat public account Nov 02, 2023 am 09:42 AM

How to use Laravel to develop an online ordering system based on WeChat official accounts. With the widespread use of WeChat official accounts, more and more companies are beginning to use them as an important channel for online marketing. In the catering industry, developing an online ordering system based on WeChat public accounts can improve the efficiency and sales of enterprises. This article will introduce how to use the Laravel framework to develop such a system and provide specific code examples. Project preparation First, you need to ensure that the Laravel framework has been installed in the local environment. OK

Can the official account only post one article per day? Can the official account only post one article per day? Jun 16, 2023 pm 02:04 PM

The public account can not only post one article per day, but can publish up to eight articles at a time. How to publish multiple articles: 1. Click "Material Management" on the left, and then click "New Graphic and Text Material" to start editing. First article; 2. After editing the first article, click the + sign under the first article on the left and click "Graphic Message" to edit the second article; 3. After finishing multiple images and text, click " Save and send in bulk" to complete the publishing of multiple articles.

Build WeChat public account application using Go language framework Build WeChat public account application using Go language framework Jun 04, 2023 am 10:40 AM

With the popularity of the Internet and the widespread use of mobile devices, WeChat official accounts have become an indispensable part of corporate marketing. Through WeChat public accounts, companies can easily interact with users, promote products and services, and increase brand awareness. In order to better develop WeChat public account applications, more and more developers and companies choose to use Go language to build WeChat public account applications. Go language is a programming language developed by Google. Its syntax is concise and suitable for building high-performance, high-concurrency real-time applications. In terms of ease of use and

WeChat announced that it will regulate the content of 'feudal superstitions, using religion, feng shui, luck and other gimmicks to make money or gain attention' WeChat announced that it will regulate the content of 'feudal superstitions, using religion, feng shui, luck and other gimmicks to make money or gain attention' Aug 05, 2024 pm 10:26 PM

According to news from this website on August 1, the WeChat Public Platform Operations Center issued an article today saying that the platform found that some articles published by operators contain feudal superstitions and use religion, feng shui, fortune and other gimmicks to make money or gain attention. Such content is very likely Causing misleading or property damage to users. WeChat will conduct continuous inspections, and once any illegal content is discovered, corresponding actions will be taken according to the specific degree of the violation. The violation cases attached to this site are as follows: publishing superstition-related titles, using intimidation, inducement and other tones to exaggerate the harm or negative impact of a certain behavior. ▲Picture source WeChat Public Platform Operation Center, the same article below provides services with feudal superstitions such as fortune telling, fortune telling, and divination, and includes paid items, such as the sale of transshipment and disaster relief products. Improperly collecting users’ personal privacy information in the name of providing relevant services

See all articles