php 验证微信token_php之微信公众号验证token获取access_token
實例
/醫院
*?Created?by?PhpStorm.
*?User:?Administrator
*?Date:?2018/6/1?0001
*?Time:?上午?9:52
*/
namespace?app\index\model;
use?think\facade\Request;
use?think\facade\Config;
use?think\Model;
use?think\Facade\Cache;
class?WeixinModel?extends?Model
{
public?function?checkToken(){
$signature?=?Request::param('signature');
$timestamp?=?Request::param('timestamp');
$nonce?=?Request::param('nonce');
$echostr?=?Request::param('echostr');
$Token?=?Config::get('app.Token');
$tmpArr?=?array($timestamp,?$nonce,?$Token);
sort($tmpArr,?SORT_STRING);
$tmpStr?=?implode($tmpArr);
$tmpStr?=?sha1($tmpStr);
if?($tmpStr?!=?$signature)?{
return?false;
}
return?$echostr;
}
public?function?getAccessToken($isCache?=?true)
{
if?(!$isCache)?{
Cache::rm("access_token");
}
$access_token?=?Cache::get("access_token");
if?($access_token?&&?$isCache)?{
return?$access_token;
}
$APPID?=?Config::get('app.AppID');
$AppSecret?=?Config::get('app.AppSecret');
$url?=?"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="?.?$APPID?.?"&secret="?.?$AppSecret;
$res?=?http_Get($url);
$res?=?json_decode($res,true);
//????????$access_token?=?Request::param('access_token');
//????????$expires_in?=?Request::param('expires_in');
Cache::set("access_token",?$res['access_token'],?$res['expires_in']?-?600);
return?$res['access_token'];
}
}
運行實例 ?
點擊 "運行實例" 按鈕查看在線實例
總結
以上是生活随笔為你收集整理的php 验证微信token_php之微信公众号验证token获取access_token的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java复制类mytool_MyTool
- 下一篇: 动态规划算法php,php算法学习之动态