[微擎]多系统共用accesstoken
多系统共用accesstoken
当一个公众号或者小程序接入多个系统时,由于微信接口的限制,会导致accesstoken调用次数超出有效范围,故微擎系统提供了下面的接口,供其他系统调用。
URL
请求方式: GET
http://域名/api/accesstoken.php?type=TYPE&appid=APPID&secret=SECRET
1
返回
正常情况下,会返回下述JSON数据包:
{
“accesstoken”:“ACCESS_TOKEN”
}
accesstoken
<?php /** * [WeEngine System] Copyright (c) 2014 WE7.CC * WeEngine is NOT a free software, it under the license terms, visited http://www.w7.cc/ for more details. */ error_reporting(0); define('IN_SYS', true); define('WECHATS', 1); define('WXAPP', 4); function account_tablename($type) { $account_types = array( WECHATS => 'account_wechats', WXAPP => 'account_wxapp', ); return !empty($account_types[$type]) ? $account_types[$type] : ''; } require '../framework/bootstrap.inc.php'; parse_str($_SERVER['QUERY_STRING'], $query); if(is_array($query) && count($query) == 3 && in_array($query['type'], array(WECHATS, WXAPP)) && !empty($query['appid']) && !empty($query['secret'])) { $table_name = account_tablename($query['type']); if (empty($table_name)) { exit('Invalid Type'); } $account_info = pdo_get($table_name, array('key' => $query['appid'])); if (empty($account_info) || empty($account_info['uniacid'])) { exit('Appid Not Found'); } $account_api = WeAccount::createByUniacid($account_info['uniacid']); $result = array('accesstoken' => $account_api->getAccessToken()); echo json_encode($result); exit; } exit('Invalid Request');
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2019-07-04 * Time: 18:16 */ require_once("../framework/bootstrap.inc.php");//引入微擎文件 $_W['account']['acid']=$_GET['uniacid']; //这个是每个公众号对应的acid $account_api = WeAccount::create(); $token = $account_api->clearAccessToken(); //清除失效的accesstoken(可不用) $token = $account_api->getAccessToken(); echo ($token); ?>
版权声明:
作者:admin
链接:http://blog.mryxh.cn/722.html
文章版权归作者所有,未经允许请勿转载。
THE END