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);
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 共2条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

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