企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
1.向微信请求获取token ~~~ protected function settoken() { $appid = 'wxa5ed04228937e0fc'; $secret = 'a3938fdaeac026cce799bb21f9921248'; $ch = curl_init(); $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $output = curl_exec($ch); if ($output === false) { echo curl_error($ch); } else { $obj = json_decode($output, JSON_FORCE_OBJECT); $token = $obj['access_token']; Cache::set('token', $token, 7000); } curl_close($ch); } ~~~ 2.获取本地缓存token ~~~ protected function gettoken() { $token = Cache::get('token'); if (empty($token)) { $this->settoken(); $token = Cache::get('token'); } return $token; } ~~~