|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
function set_openai(){
|
|
|
|
// {
|
|
|
|
// "messages": [
|
|
|
|
// {
|
|
|
|
// "role": "system",
|
|
|
|
// "content": "You are a helpful assistant."
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// "role": "user",
|
|
|
|
// "content": "宁波大学地址?"
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// "role": "assistant",
|
|
|
|
// "content": "宁波大学的地址是浙江省宁波市江北区风华路818号。"
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// "role": "user",
|
|
|
|
// "content": "占地面积是多少?"
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 发送http post请求
|
|
|
|
* @param type $url
|
|
|
|
* @param type $post_data
|
|
|
|
*/
|
|
|
|
function http_post($url, $post_data)
|
|
|
|
{
|
|
|
|
$header[] = "charset = UTF-8";
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$res = curl_exec($ch);
|
|
|
|
if (curl_errno($ch)) {
|
|
|
|
Log::write(print_r(curl_errno($ch),1),'debug---1');
|
|
|
|
}
|
|
|
|
curl_close($ch);
|
|
|
|
return json_decode($res, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 发送http get请求
|
|
|
|
* @param type $url
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
function http_get($url)
|
|
|
|
{
|
|
|
|
$header[] = "content-type: application/x-www-form-urlencoded;
|
|
|
|
charset = UTF-8";
|
|
|
|
$ch1 = curl_init();
|
|
|
|
$timeout = 5;
|
|
|
|
curl_setopt($ch1, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);
|
|
|
|
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
|
|
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
$access_txt = curl_exec($ch1);
|
|
|
|
curl_close($ch1);
|
|
|
|
return json_decode($access_txt, true);
|
|
|
|
} |
...
|
...
|
|