[微擎]多系統共用accesstoken

多系統共用accesstoken
當一個公衆號或者小程序接入多個系統時,由於微信接口的限制,會導致accesstoken調用次數超出有效範圍,故微擎系統提供了下面的接口,供其他系統調用。

URL
請求方式: GET

http://域名/api/accesstoken.php?type=TYPE&appid=APPID&secret=SECRET

參數名稱	類型	是否必填	描述	type	int	是	賬號類型:1、公衆號;2、小程序	appid	string	是	請求賬號的appid	secret	string	是	請求賬號的appsecret
返回
正常情況下,會返回下述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);

?>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章