当前位置: 移动技术网 > IT编程>开发语言>PHP > 微信access_token的获取开发示例

微信access_token的获取开发示例

2018年06月24日  | 移动技术网IT编程  | 我要评论

概述

access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。

access_token的获取

<?php

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>

以上所述就是本文的全部内容了,希望大家能够喜欢。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网