Aplicación Zhiwu: el programa PHP llama a la interfaz chatGPT, siempre que haya SK, se puede llamar normalmente en China después de la prueba

El código fuente de PHP es el siguiente. Después de la prueba, se puede llamar por completo. Si lo necesita, puede tomarlo. Si tiene alguna pregunta, no dude en hablar con los técnicos de Zhiwu para discutirla.

En el contenido de texto devuelto, \n representa la contraseña de nueva línea. Si desea mostrarla como HTML, reemplace \n con <br>

El siguiente código ha sido probado por mí mismo, puede ejecutarse normalmente y se pueden obtener los resultados de openAI

<?php
set_time_limit(0);
if (!empty($_GET['send']) && $_GET['send'] == 'yes') {
    $result = '';
    if (empty($_POST['appid'])) {
        $result = 'appid不能为空!';
    }
    if ($result == '' && empty($_POST['appid_key'])) {
        $result = '密钥不能为空!';
    }
    if ($result == '' && empty($_POST['title'])) {
        $result = '询问标题不能为空!';
    }
    if ($result == '') {
        $appid = trim($_POST['appid']);
        $appid_key = trim($_POST['appid_key']);
        $title = trim($_POST['title']);
        $t = time();
        $signStr = $appid . $title . $t . $appid_key;  // 把需要请求的参数串联起来,然后md5加密生成sign字段的数值      
        $sign = md5($signStr);
        $params = array();
        $params['appid'] = $appid;
        $params['appid_key'] = $appid_key;
        $params['title'] = $title;
        $params['t'] = $t;
        $params['sign'] = $sign;
        $paramsString = http_build_query($params);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
        curl_setopt($ch, CURLOPT_TIMEOUT, 300);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $paramsString);
        curl_setopt($ch, CURLOPT_URL, 'http://api.zhiwu55.net/v1/open_ai/');
        $response = curl_exec($ch);
        if ($response === FALSE) {
            $result = '请求失败了!';
        } else {
            $httpInfoArr = curl_getinfo($ch);
        }
        if ($result == '' && $httpInfoArr['http_code'] != 200) {
            $result = '请求失败!!错误代码:' . $httpInfoArr['http_code'];
        }
        if ($result == '' && stripos($response, 'hzw_error_') === false) { // 如果返回的内容含有hzw_error则为出错           
            $result = nl2br($response);
        } else {
            $result = '出错:' . str_ireplace('hzw_error_', '', $response);
        }
    }
}
?>
<!DOCTYPE html>
<html style="font-size:16px;line-height:28px">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="智伍应用,www.zhiwu55.com">
<meta name="author" content="www.zhiwu55.com">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover">
<title>ChatGPT接口演示(SDK)</title>
</head>
<body style="font-size:16px;line-height:28px">
<?php  if(!empty($result)) { ?>
<div style="background:#DDD;color:red;padding:8px;text-align:center;">
<h2><?php echo $_POST['title']; ?></h2>
<?php echo $result; ?>
</div>
<?php  } ?>
<div style="text-align:center;padding-top:32px;">
<a href="http://file.zhiwu55.com/common/apply_open_ai.jpg" target="_blank">如果您没有自己的账号ID和密码,请点击这儿微信扫码免费申请!</a><br><br>
</div>
<form action="?send=yes" method="post">
<table align="center" cellpadding="8">
  <tr>
    <td colspan="2">
      <ul>
        <li>无需你申请openAI官方的账号SK密钥,不用担心自己SK密钥被封杀</li>
        <li>这个文件是SDK演示,没有任何样式,供用于演示接口的调用,请查看源文件的调用实例代码</li>
        <li>切记,警告,请把账号ID和账号密码换成自己的,不要用这个演示账号</li>
        <li><a href="http://file.zhiwu55.com/common/apply_open_ai.jpg" target="_blank">微信扫码免费申请自己的专属账号ID和密码</a></li>
      </ul>
    </td>
  </tr>
  <tr><td style="text-align:right">演示账号ID:</td><td><input type="text" name="appid" size="64" value="823767debbb383e7977772937b3554c4b9c"></td></tr>
  <tr><td style="text-align:right">演示账号密码:</td><td><input type="text" name="appid_key" size="64" value="CLpNiucqvX6Mxhnw4vuOT3BlbkFJG678SSqm6joozrn3kYSV"></td></tr>
  <tr><td style="text-align:right">询问内容:</td><td><input type="text" name="title" size="64" value="如何保持健康的身体"></td></tr>
  <tr><td colspan="2" style="text-align:center"><input type="submit" value="确定" style="padding:8px 16px;" onClick="this.value='稍等,请求中……';this.disable=true"></td></tr>
</table>
</form>
</body>
</html>

Supongo que te gusta

Origin blog.csdn.net/myqq155120699/article/details/129067224
Recomendado
Clasificación