<?
$appId = '';
$authorizer_appid = $_REQUEST['authorizer_appid'];
$authorizer_access_token_name = Server::getProject().'_'.$authorizer_appid.'_authorizer_access_token';
$authorizer_refresh_token_name = Server::getProject().'_'.$authorizer_appid.'_authorizer_refresh_token';
$authorizer_refresh_token = Redis::get($authorizer_refresh_token_name);
$left_time = Redis::ttl($authorizer_access_token_name);
if($left_time >= 60){
$authorizer_access_token = Redis::get($authorizer_access_token_name);
}else{
$component_access_token_name = Server::getProject() . '_' . 'component_access_token';
$component_access_token = Redis::get($component_access_token_name);
$url = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=$component_access_token";
$param['component_appid'] = $appId;
$param['authorizer_appid'] = $authorizer_appid;
$param['authorizer_refresh_token'] = $authorizer_refresh_token;
$json_param = json_encode($param);
$authorization_info = HttpRequest::http_post($url, $json_param);
Log::put("authorization_info", $authorization_info);
$authorization_info_array = json_decode($authorization_info,true);
$authorizer_access_token = $authorization_info_array['authorizer_access_token'];
$authorizer_expires_in = $authorization_info_array['expires_in'];
$authorizer_refresh_token = $authorization_info_array['authorizer_refresh_token'];
Redis::set($authorizer_access_token_name,$authorizer_access_token,$authorizer_expires_in);
Redis::set($authorizer_refresh_token_name,$authorizer_refresh_token);
}
$R = new stdClass();
$R->authorizer_access_token = $authorizer_access_token;
HttpResponse::exitJSON(0, "获取接口调用密令成功~!",$R);
微信第三方平台(获取调用凭证)
最新推荐文章于 2023-12-25 16:26:01 发布