ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` php curl Content-Type: application/json' protected function json_post($url,$data=[]){ $data=json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // POST数据 curl_setopt($ch, CURLOPT_POST, 1); // 把post的变量加上 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data))); $output = curl_exec($ch); curl_close($ch); return $output; } ``` 微擎ihttp_get方法请求结果的封装 直接返回 content的内容 ``` /** * 统一请求函数 * @return JSON */ protected static function get_content($apiurl) { $result = ihttp_get($apiurl); if ($result['code'] != 200) { return error(-1, $result['content']); } $content = @json_decode($result['content'], true); if (!is_array($content)) { return error(-1, $result['content']); } if ($content['status'] != 0) { return error($content['status'], $content['message']); } return $content; } ```