微信公众号获取acess_token并存储(php)
<?php
define("appid", "你的appid");
define("appsecret", "你的appsecret"); //获取access_token,每7000s重新获取
function getAccessToken() {
$tokenFile = "./access_token.txt";
$data = json_decode(file_get_contents($tokenFile)); if ($data->expire_time < time() || !$data->expire_time) {
$appid = appid;
$appsecret = appsecret;
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$res = json_decode(file_get_contents($url));
$access_token = $res->access_token;
if($access_token) {
$data_new['expire_time'] = time() + 7000;
$data_new['access_token'] = $access_token;
file_put_contents($tokenFile, json_encode($data_new));
}
}else{
$access_token = $data->access_token;
}
return $access_token;
} // var_dump(getAccessToken());
?>
亲测可用,也许会遇到读写权限问题。
微信公众号获取acess_token并存储(php)的更多相关文章
- 微信公众号获取粉丝openid系统
做为一名开发人员,在测试当中也经常需要用到openid,但是微信公众号获取openid的方法也是特别麻烦!网页授权是最常见的方式, 但是网页授权的流程太复杂,不仅要开发,还要在公众号后台设置回调域名( ...
- 微信公众号获取openid(php实例)
微信公众号获取openid 公众号获取openid的方法跟小程序获取openid其实是一样的,只是code获取的方式不一样 小程序获取code: 用户授权登录时调用wx.login即可获取到code ...
- ASP.NET微信公众号获取AccessToken
access_token是公众号的全局唯一接口调用凭据,公众号调用各接口时都需使用access_token.开发者需要进行妥善保存.access_token的存储至少要保留512个字符空间.acces ...
- 微信公众号获取access_token
一般我们在进行微信公众号开发的时候,都需要用到access_token,但是具体的获取及其使用方式如何呢?下面展示一种获取的方式(具体的微信公众号申请和配置,请参考开放文档,具体在这里就不详细说明了) ...
- 微信公众号 --- 获取access_token
获取access_token 在左侧菜单栏中也可以找到 可以一步步的进行设置 , 身份验证的时候要 注意:密码是你创建微信公众号的密码 往一步步的执行就可以了 接下来就是获取ip 白名单,进行设置 ...
- php开发微信公众号获取信息LBS
1.一般的公众号都可以在微信公众平台里面设置自定义菜单和自动回复消息,如果需要获取用户位置,则必须开启 服务器配置,当次功能开启后,微信公众平台的自定义菜单和自动回复则失效. 需要通过接口开发来实现微 ...
- php,微信公众号,获取用户地理位置 定位 经纬度
<?php //php插件下载地址: https://files.cnblogs.com/files/fan-bk/jssdk_php.rar //建立一个php文件 require_once ...
- 微信公众号获取微信token
微信在公众号和小程序的开发都有开放文档一般看文档开发就行,很简单这里写一个小demo获取微信token,之后根据自己的业务获取信息处理即可 package com.demo.ccx; import o ...
- .net MVC 微信公众号 获取 access_token
官方文档说明:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_ ...
随机推荐
- updateByPrimaryKey 和 updateByPrimaryKeySelective
1. 数据库记录 2. updateByPrimaryKey Preparing: UPDATE t_token_info SET entity_id = ?,entity_type = ?,time ...
- Info - Get technical information from the Internet
Official Sites Overview / QuickStart Guide / Docs / E-books Community / Fourm / Blog Demo / Download ...
- 利用django-simple-captcha生成验证码
参考文档 http://django-simple-captcha.readthedocs.io/en/latest/ django支持1.7+ 1.安装 pip install django-sim ...
- Delphi:程序自己删除自己,适用于任何windows版本(含源码)
Delphi:程序自己删除自己,适用于任何windows版本(含源码) function Suicide: Boolean; var sei: TSHELLEXECUTEINFO; szMod ...
- Mac 下配置 Python 开发环境
➜ ~ sudo brew install python3 ==> Downloading https://www.python.org/ftp/python/3.5.1/Python-3.5. ...
- [个人项目] 使用 Vuejs 完成的音乐播放器
Foreword 虽然音乐播放这类的项目的静态展示居多,业务逻辑并不复杂,但是对于我这种后端出身的前端萌新来说,能使用vuejs完成大部分功能, 也会有许多收获. api:我使用的是一个开源的 nod ...
- setPreferredContentSize error in ios app
Creating "IOS Project" in xcode 5 causes the following when launching for iPad simulator. ...
- Mybatis在非spring环境下配置文件中使用外部数据源(druidDatasource)
Spring环境下, MyBatis可以通过其本身的增强mybatis-spring提供的org.mybatis.spring.SqlSessionFactoryBean来注入第三方DataSourc ...
- Oracle10g 64位 在Windows 2008 Server R2 中的安装 解决方案
背景: 操作系统Windows 2008 Server R2 要安装Oracle10g 64位版本 安装时出现如下错误: 检查操作系统版本:必须是5.0,5.1,5.2 or 6.0.实际为6.1 未 ...
- 【IT笔试面试题整理】不用加减乘除做加法
[试题描述]写一个函数,求两个整数的和,要求在函数体内不得使用加减乘除四则运算符合. 基本思路是这样的: int A, B;A&B //看哪几位有进位A^B //不带进位加 考虑二进制加法的过 ...