求助!使用php本地缓存微信access

[复制链接]
查看11 | 回复3 | 2021-1-27 06:47:13 | 显示全部楼层 |阅读模式
define('APPID','wx2xxxxx');
define('APPSECRET','xxxxxxxxxx');
$tokenFile='./tokenFile.txt';
$data=json_decode(file_get_contents($tokenFile));
if($data->expire_timeexpire_time){
$curl=curl_init();
$url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.APPID.'&secret='.APPSECRET;
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$res=curl_exec($curl);
curl_close($curl);
$access_token=json_decode($res)->access_token;
print_r($access_token);
if($access_token){
$data['expire_time']=time()+7000;
$data['access_token']=$access_token;
$fp=fopen($tokenFile,"w");
fwrite($fp,json_encode($data));
fclose($fp);
}
}else{
$access_token=$data->access_token;
}


这里是错误提示:
Warning:fopen(./tokenFile.txt)[function.fopen]:failedtoopenstream:Permissiondeniedintest.phponline20
Warning:chmod()[function.chmod]:Permissiondeniedintest.phponline21
Warning:fwrite()expectsparameter1toberesource,booleangivenintest.phponline23
Warning:fclose()expectsparameter1toberesource,booleangivenintest.phponline24
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:47:13 | 显示全部楼层
改变文件写入权限试试,或者直接将最新的access_token 存入数据库中,也方便调用。。。
回复

使用道具 举报

千问 | 2021-1-27 06:47:13 | 显示全部楼层
引用1楼laistar的回复:改变文件写入权限试试,或者直接将最新的access_token 存入数据库中,也方便调用。。。

第一次接触PHP啊,不知道怎么修改权限。我就查了一下那个问题是权限不足,所以跑来求助


回复

使用道具 举报

千问 | 2021-1-27 06:47:13 | 显示全部楼层
在linux上部署的吗?
chmod-R777需要写权限的文件夹路径
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行