Home Backend Development PHP Tutorial ACCESS TOKEN_PHP Tutorial

ACCESS TOKEN_PHP Tutorial

Jul 13, 2016 pm 05:17 PM
access token exist land platform develop WeChat interface

Access Token

In the development of WeChat public platform interfaces, Access Token occupies a very important position, which is equivalent to the key to enter various interfaces. Only with this key can you have the authority to call various other special interfaces.

Access_token is the globally unique ticket of the public account. The public account needs to use access_token when calling each interface. Under normal circumstances, the access_token is valid for 7200 seconds. Repeated acquisition will cause the last access_token to become invalid.

Official accounts can use AppID and AppSecret to call this interface to obtain access_token. AppID and AppSecret can be obtained in development mode (you need to be a developer and your account has no abnormal status). Note that the https protocol must be used when calling all WeChat interfaces.

Interface call request description

http request method: GET

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

Parameter Description

参数

是否必须

说明

grant_type

获取access_token填写client_credential

appid

第三方用户唯一凭证

secret

第三方用户唯一凭证密钥,既appsecret

Parameters

Is it necessary

Description

grant_type

Yes

参数

说明

access_token

获取到的凭证

expires_in

凭证有效时间,单位:秒

Get access_token and fill in client_credential

appid

Yes

Unique credentials for third-party users

secret Yes
<span $appid</span> = "wxbad0b4x543aa0b5e"<span ;
</span><span $appsecret</span> = "ed222a84da15cd24c4bdfa5d9adbabf2"<span ;
</span><span $url</span> = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=<span $appid</span>&secret=<span $appsecret</span>"<span ;

</span><span $ch</span> =<span  curl_init();
curl_setopt(</span><span $ch</span>, CURLOPT_URL, <span $url</span><span );
curl_setopt(</span><span $ch</span>, CURLOPT_SSL_VERIFYPEER, <span FALSE</span><span ); 
curl_setopt(</span><span $ch</span>, CURLOPT_SSL_VERIFYHOST, <span FALSE</span><span ); 
curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, 1<span );
</span><span $output</span> = curl_exec(<span $ch</span><span );
curl_close(</span><span $ch</span><span );
</span><span $jsoninfo</span> = json_decode(<span $output</span>, <span true</span><span );
</span><span $access_token</span> = <span $jsoninfo</span>["access_token"];
Copy after login

Third-party user unique credential key, appsecret

Return instructions

Under normal circumstances, WeChat will return the following JSON data packet to the official account:

{"access_token":"ACCESS_TOKEN","expires_in":7200}

Parameters

access_token Obtained voucher
expires_in Voucher validity time, unit: seconds
When an error occurs, WeChat will return error code and other information. The JSON data packet example is as follows (this example is an invalid AppID error): {"errcode":40013,"errmsg":"invalid appid"}
Code implementation Special Instructions In OAuth2.0 authentication, we will see another Access Token, please pay attention to the difference. http://www.bkjia.com/PHPjc/626601.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/626601.htmlTechArticleAccess Token In the development of the WeChat public platform interface, Access Token occupies a very important position, which is equivalent to entering various A key to an interface. Only with this key can you call various other special features...
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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

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)

The difference between H5 and mini-programs and APPs The difference between H5 and mini-programs and APPs Apr 06, 2025 am 10:42 AM

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

What is the difference between an abstract class and an interface in PHP? What is the difference between an abstract class and an interface in PHP? Apr 08, 2025 am 12:08 AM

The main difference between an abstract class and an interface is that an abstract class can contain the implementation of a method, while an interface can only define the signature of a method. 1. Abstract class is defined using abstract keyword, which can contain abstract and concrete methods, suitable for providing default implementations and shared code. 2. The interface is defined using the interface keyword, which only contains method signatures, which is suitable for defining behavioral norms and multiple inheritance.

What is the difference between H5 page production and WeChat applets What is the difference between H5 page production and WeChat applets Apr 05, 2025 pm 11:51 PM

H5 is more flexible and customizable, but requires skilled technology; mini programs are quick to get started and easy to maintain, but are limited by the WeChat framework.

How to choose H5 and applets How to choose H5 and applets Apr 06, 2025 am 10:51 AM

The choice of H5 and applet depends on the requirements. For applications with cross-platform, rapid development and high scalability, choose H5; for applications with native experience, rich functions and platform dependencies, choose applets.

Unable to log in to mysql as root Unable to log in to mysql as root Apr 08, 2025 pm 04:54 PM

The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

What are the different ways of promoting H5 and mini programs? What are the different ways of promoting H5 and mini programs? Apr 06, 2025 am 11:03 AM

There are differences in the promotion methods of H5 and mini programs: platform dependence: H5 depends on the browser, and mini programs rely on specific platforms (such as WeChat). User experience: The H5 experience is poor, and the mini program provides a smooth experience similar to native applications. Communication method: H5 is spread through links, and mini programs are shared or searched through the platform. H5 promotion methods: social sharing, email marketing, QR code, SEO, paid advertising. Mini program promotion methods: platform promotion, social sharing, offline promotion, ASO, cooperation with other platforms.

How to use sql if statement How to use sql if statement Apr 09, 2025 pm 06:12 PM

SQL IF statements are used to conditionally execute SQL statements, with the syntax as: IF (condition) THEN {statement} ELSE {statement} END IF;. The condition can be any valid SQL expression, and if the condition is true, execute the THEN clause; if the condition is false, execute the ELSE clause. IF statements can be nested, allowing for more complex conditional checks.

The difference between H5 page production and traditional web pages The difference between H5 page production and traditional web pages Apr 06, 2025 am 07:27 AM

The H5 page adopts client rendering, focusing on visual effects and interactivity, and is suitable for mobile display; traditional web pages rely on server-side rendering, focusing on content and SEO, and are suitable for occasions where a large amount of data needs to be processed and SEO is paid attention to. Depending on the project requirements, you can choose the appropriate technical solution to balance the lightweight experience and the implementation of complex functions.

See all articles