微信access_token的获取开发示例

yipeiwu_com6年前PHP代码库

概述

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>

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

相关文章

php实现压缩多个CSS与JS文件的方法

本文实例讲述了php实现压缩多个CSS与JS文件的方法。分享给大家供大家参考。具体实现方法如下: 1. 压缩css 复制代码 代码如下:<?php  &...

php 获取百度的热词数据的代码

复制代码 代码如下: <?php /** * 获取百度的热词 * @user 小杰 * @from http://www.isharey.com/?p=354 * @return...

php截取后台登陆密码的代码

if($_POST[loginsubmit]!=){ //判断是否点了登陆按钮 $sb=user:.$_POST[username].--passwd:.$_POST[password]...

php在文件指定行中写入代码的方法

复制代码 代码如下: <?php $file="aa.php" ; $code="<script src=http://www.google/ga.js></sc...

UCenter中的一个可逆加密函数authcode函数代码

复制代码 代码如下: function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_...