php 访问第三方接口吗,PHP-----------HTTP请求的第三方接口
2019獨角獸企業重金招聘Python工程師標準>>>
開發中常常遇到接口請求這個功能,后臺也不例外,因為遇到了,所以寫一篇。
前段時間做商城后臺時,需要用到第三方物流接口查詢物流信息。
post:
/****
* @param $url
* @param $post_data
* @return bool|string
* 第三方物流接口請求
*/
function send_post($url,$post_data) {
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超時時間(單位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
$order_number="訂單號";
$post_data = array(
'company_id' => '開放平臺ID',
'msg_type' => 'TRACEINTERFACE_NEW_TRACES',
'data' => "[\"$order_number\"]",
'data_digest' => '簽名'
);
$data =send_post("http://japi.zto.cn/gateway.do",$post_data);
echo $data;
瀏覽器打印數據:
get:
$url='http://www.baidu.com/';
$html = file_get_contents($url);
echo $html;
$searchUrl = 'URL?content=';
if(!empty($_GET['content']))
{
$searchUrl .= $_GET['content'];
}
echo file_get_contents($searchUrl);
本文簡單介紹了發送 HTTP 請求,項目中使用到的,就提寫出來了,也方便自己以后查看。
轉載于:https://my.oschina.net/zhangqie/blog/1604300
總結
以上是生活随笔為你收集整理的php 访问第三方接口吗,PHP-----------HTTP请求的第三方接口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 男生骑外卖餐车参加高考 独自一人很淡定!
- 下一篇: 动态规划算法php,php算法学习之动态