PHP实现api转接

        自己在用的一个api转接程序,可以将别人的api转接成自己的api,非常好用。

<?php
function curlget($url,$method='get',$data=null){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1000);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($method=='post'){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
}
$result = curl_exec($ch);
curl_close($ch);
if(!$result){
//curl 出现错误
return false;
}
return $result;
}
$postdata = $_REQUEST;
$res = @curlget($url,"post",$postdata);
echo($res);
<?php
function curlget($url,$method='get',$data=null){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1000);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($method=='post'){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
}
$result = curl_exec($ch);
curl_close($ch);
if(!$result){
//curl 出现错误
return false;
}
return $result;
}
$postdata = $_REQUEST;
$res = @curlget($url,"post",$postdata);
echo($res);
<?php function curlget($url,$method='get',$data=null){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1000); curl_setopt($ch, CURLOPT_TIMEOUT, 500); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if($method=='post'){ curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); } $result = curl_exec($ch); curl_close($ch); if(!$result){ //curl 出现错误 return false; } return $result; } $postdata = $_REQUEST; $res = @curlget($url,"post",$postdata); echo($res);
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
Love begins with a smile, grows with a kiss and ends with a tear.
爱,起于微笑,浓于亲吻,逝于泪水
评论 共2条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复
      • KEKC的头像-KEKC博客KEKC徽章-人气大使-KEKC博客等级-LV6-KEKC博客作者0