- <?phpset_time_limit(0);function translate($url,$text){$data = array("info"=>$text);$ch = curl_init();sleep(1);curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_AUTOREFERER, 1);curl_setopt($ch, CURLOPT_MAXREDIRS, 4);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_USERAGENT, "HCT");curl_setopt($ch, CURLOPT_TIMEOUT, 15);$output = curl_exec($ch);curl_close($ch);return $output;}function mbStrSplit ($string, $len=101000) { $start = 0; $strlen = mb_strlen($string); while ($strlen) { $array[] = mb_substr($string,$start,$len,"utf8"); $string = mb_substr($string, $len, $strlen,"utf8"); $strlen = mb_strlen($string); } return $array;}$neirong=$LabelArray['内容']?$LabelArray['内容']:"写篇夏天的作文";$neirong='根据"'.mb_substr($neirong, 0, 100, 'utf-8').'"写篇美文或散文或作文且不少于2000字的文章';$neirong=strip_tags($neirong);$neirong=preg_replace('/\s/', '', $neirong);$api_url="https://api.openai-proxy.com/v1/chat/completions";//此处为反向代理openai的接口地址,防止国内无法请求。$apiKey="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";//此处为openai的接口地址(请修改您自己的openai上面的key值)$model="gpt-3.5-turbo-0613";$randIp=randIp();$DAILIIp=substr($randIp[0],10);$post_fields = ['model' => $model,'top_p' => 1,'temperature' =>0.7,'max_tokens' =>3500, 'messages' => [],];$post_fields['messages'][] = ['role' => 'user', 'content' =>$neirong];$headers = ['Accept: application/json','Content-Type: application/json','CLIENT-IP:'.$DAILIIp,'X-FORWARDED-FOR:'.$DAILIIp,'Authorization: Bearer ' . $apiKey];$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $api_url);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Snapchat/10.77.5.59 (like Safari/604.1)');curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);$response = curl_exec($ch);$response_data = json_decode($response, true);if(isset($response_data['choices'][0]['message']['content'] ) ) {$info0=str_replace( "\\n", "\n", $response_data['choices'][0]['message']['content'] );$info=str_replace( "\n", "<br />", $info0);} if(isset( $response_data['error']['message'] ) ) { $content2 = " 时间:".date("Y-m-d H:i:s")." | 代理IP:".$DAILIIp." \n";$content2 .= "问题:".$neirong."\n\n错误提示:".$response_data['error']['message']."--------------------\n\n\n";$myfile = fopen("error.log", "a") or die("Writing file failed.");fwrite($myfile, $content2);}if($LabelArray['PageType']=="Save"){if(empty($info)){$LabelArray['内容']=$LabelArray['内容']; }else{$LabelArray['内容']=$info;}}$ky=$LabelArray['标题'];$ky=mb_substr($ky, 0, 15, 'utf-8');$url='https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&wd='.$ky.'&cb=jQuery110203931061074913418_1641900386657&_=1641900386676'; //api网址$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_TIMEOUT,10);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);$output=curl_exec($ch);$output=str_replace('jQuery110203931061074913418_1641900386657(','',$output);$output=str_replace(')','',$output);$output= json_decode($output,1); if($LabelArray['PageType']=='Save'){if(empty($output['g'][3]['q'])){}else{$LabelArray['标题']=$LabelArray['标题'].'('.$output['g'][3]['q'].')';}}if(isset($LabelArray['内容'])){ $count = substr_count($LabelArray['内容'],'</p>'); $j = 0;$num = floor($count / 2); $tem_num = 0;for($i = 0; $i < $count; $i++){$j = strpos($LabelArray['内容'], '</p>', $j);if($i == 0){$LabelArray['内容'] = substr($LabelArray['内容'], 0, $j) . ('') . substr($LabelArray['内容'], $j); $j = strpos($LabelArray['内容'], '</p>', $j);}else if($i == ($num)){$LabelArray['内容'] = substr($LabelArray['内容'], 0, $j) . ('') . substr($LabelArray['内容'], $j); $j = strpos($LabelArray['内容'], '</p>', $j);}else if($i == ($count-1)){$LabelArray['内容'] = substr($LabelArray['内容'], 0, $j) . ('') . substr($LabelArray['内容'], $j); }$j = ($j+1);}}//此函数提供了英国的IP地址function randIP(){$ip_long = array(array('35127296', '35651583'), //2.24.0.0- 2.31.255.255array('39845888', '40370175'), //2.96.0.0-2.103.255.255array('41418752', '41943039'), //2.120.0.0-2.127.255.255array('47710208', '48234495'), //2.216.0.0-2.223.255.255array('88018944', '88020991'), //5.63.16.0-5.63.23.255array('419430400', '436207615'), //25.0.0.0-25.255.255.255array('524288000', '528482303'), //31.64.0.0-31.127.255.255array('3654025216', '3654287359'), //217.204.0.0-217.207.255.255array('3652190208', '3652321279'), //217.176.0.0-217.177.255.255array('3650912256', '3650945023'), //217.156.128.0-217.156.255.255);$rand_key = mt_rand(0, 9);$ip= long2ip(mt_rand($ip_long[$rand_key][0], $ip_long[$rand_key][1]));$headers['CLIENT-IP'] = $ip; $headers['X-FORWARDED-FOR'] = $ip; $headerArr = array(); foreach( $headers as $n => $v ) { $headerArr[] = $n .':' . $v; }return $headerArr; }echo serialize($LabelArray);
复制代码 |