在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
<?php define("appid", "你的appid"); define("appsecret", "你的appsecret"); //获取access_token,每7000s重新获取 function getAccessToken() { $tokenFile = "./access_token.txt"; $data = json_decode(file_get_contents($tokenFile)); if ($data->expire_time < time() || !$data->expire_time) { $appid = appid; $appsecret = appsecret; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $res = json_decode(file_get_contents($url)); $access_token = $res->access_token; if($access_token) { $data_new['expire_time'] = time() + 7000; $data_new['access_token'] = $access_token; file_put_contents($tokenFile, json_encode($data_new)); } }else{ $access_token = $data->access_token; } return $access_token; } // var_dump(getAccessToken()); ?> 亲测可用,也许会遇到读写权限问题。 |
2022-08-30
2022-08-17
2022-11-06
2022-08-18
2022-07-18
请发表评论