5118的偽原創代碼提取內容方法并附帶火車頭插件寫法
今天應一個朋友請求,要求寫個5118的偽原創插件,他的接口輸出的默認是json形式輸出,很不方便,要提取里面偽原創的結果,并附上代碼。
<?php
$host = "http://apis.5118.com";
$path = "/wyc/rewrite";
$method = "POST";
$apikey = "5118偽原創的key填入";
$headers = array();
array_push($headers, "Authorization:" . $apikey);
//根據API的要求,定義相對應的Content-Type
array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
$querys = "";
$bodys = "txt=喬布斯說過:每個人都應該學習給電腦編寫程序的技術,因為這一過程能夠教你如何去思考。不管是零基礎想學編程,還是已經進入編程工作想要提升自我的朋友,今天小編整理了五個學習編程的資源網站,讓你提升自己的能力。1、W3school這是一個免費學習編程語言的在線學習網站,里面的知識淺顯易懂,非常適合初學者。如果你對編程還不是很了解,那就可以試試這個網站。2、菜鳥教程這是一個專注于編程學習的網站,里面...
喬布斯說過:每個人都應該學習給電腦編寫程序的技術,因為這一過程能夠教你如何去思考。不管是零基礎想學編程,還是已經進入編程工作想要提升自我的朋友,今天小編整理了五個學習編程的資源網站,讓你提升自己的能力。";
$url = $host . $path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
$content=curl_exec($curl);
$num = strpos($content, "{\"errcode\"");
$result = substr($content,$num);
$arrs = json_decode($result,true);
$msgs = $arrs['data'];
echo $msgs;
?>
這樣就正確輸出偽原創的結果了,可以寫成火車頭插件形式,這樣內容偽原創更方便!
<?php
error_reporting(0);
header("Content-Type: text/html;charset=utf-8");
$relcontent=$LabelArray['內容'];
$host = "http://apis.5118.com";
$path = "/wyc/rewrite";
$method = "POST";
$apikey = "填入5118偽原創的key";
$headers = array();
array_push($headers, "Authorization:" . $apikey);
//根據API的要求,定義相對應的Content-Type
array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
$querys = "";
$bodys = "txt=".$relcontent;
$url = $host . $path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
$content=curl_exec($curl);
$num = strpos($content, "{\"errcode\"");
$result = substr($content,$num);
$arrs = json_decode($result,true);
$msgs = $arrs['data'];
$LabelArray['內容']=$msgs;
echo serialize($LabelArray);
文章轉自:http://www.zhiwuhao.cm 植物號

浙公網安備 33010602011771號