微信第三方平台(获取调用凭证)

<?
$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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值