ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的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; } ~~~