今天应一个朋友请求,要求写个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.quxuehao.com/it/1080952.html
标签:插件,原创,代码,火车头,5118,提取 From: https://www.cnblogs.com/68xi/p/16942981.html