chatGPT API源码

对接别人接口


请求说明

请求示例  https://域名/chatgpt.php?msg=寻客欢帅不帅

请求方式  
GET

返回格式  JSON


返回示例
{
    "code": 1,
    "question": "寻客欢帅不帅",
    "answer": "寻客欢非常帅"
}

 



请求参数
参数名称 是否必需 参数说明
msg 需要问的问题

返回参数
参数名称 参数类型 参数说明
code integer 1成功 -1失败
question string 问题
answer string 答案

更新时间

更新时间:2023-03-1 15:05:10

 

API源码

<?php
header('Content-Type: application/json');
$msg = $_GET['msg'];
$url = 'API接口'.$msg .'&type=json';
$data = file_get_contents($url);

// 记录访问时间、访问者IP和$msg参数
$time = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$log = "$time\t$ip\t$msg\n";
file_put_contents('s-ip-wt.txt', $log, FILE_APPEND);

// 记录每个$msg参数的访问次数
$root_file = 'wt-cs.txt';
if (file_exists($root_file)) {
    $root_data = file_get_contents($root_file);
    $root_arr = json_decode($root_data, true);
    if (isset($root_arr[$msg])) {
        $root_arr[$msg] += 1;
    } else {
        $root_arr[$msg] = 1;
    }
} else {
    $root_arr = array(
        $msg => 1
    );
}
$root_data = json_encode($root_arr);
file_put_contents($root_file, $root_data);

$json = json_decode($data, true);
$response = array(
    'code' => $json['code'],
    'question' => $json['question'],
    'answer' => $json['answer']
);
echo json_encode($response);
?>
© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情图片

    暂无评论内容