Home > Backend Development > PHP Tutorial > Development example of obtaining WeChat access_token_PHP tutorial

Development example of obtaining WeChat access_token_PHP tutorial

WBOY
Release: 2016-07-13 09:57:02
Original
932 people have browsed it

WeChat access_token acquisition development example

Overview

Access_token is the globally unique ticket of the public account. The public account needs to use access_token when calling each interface. Developers need to store it properly. At least 512 characters of space must be reserved for access_token storage. The validity period of access_token is currently 2 hours and needs to be refreshed regularly. Repeated acquisition will cause the last access_token to become invalid.

Acquisition of access_token

1

2

3

4

5

6

7

8

9

10

11

12

13

define("APPID", "您的appid");

define("APPSECRET", "您的appsecret ");

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

$res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容

//echo $res;

$result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量

$access_token = $result['access_token'];

echo $access_token;

php>

1 2 3

4

6 7 8 9 10
11 12
13
<🎜> <🎜> <🎜>define("APPID", "your appid");<🎜> <🎜>define("APPSECRET", "your appsecret ");<🎜> <🎜> <🎜> <🎜>$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;<🎜> <🎜>$res = file_get_contents($token_access_url); //Get the file content or get the content of the network request<🎜> <🎜>//echo $res;<🎜> <🎜>$result = json_decode($res, true); //Accept a JSON format string and convert it into a PHP variable<🎜> <🎜>$access_token = $result['access_token'];<🎜> <🎜>echo $access_token;<🎜> <🎜> <🎜> <🎜>php>
http://www.bkjia.com/PHPjc/985146.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/985146.htmlTechArticle Overview of development examples for obtaining WeChat access_token access_token is the globally unique ticket of the official account, which is required when the official account calls each interface Use access_token. Developers need to save it properly...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template