PHP get数据 curl实现 申通快递查询
<?php/*** @param $url String* @param array $post* @param array $options* @return mixed at most json*/function curl_get($url, array $post = NULL, array $options = array()){$defaults
·
<meta charset="UTF-8"/> <!-- 让网页使用 UTF8 编码 -->
<?php
/**
* @param $url String
* @param array $post
* @param array $options
* @return mixed at most json
*/
function curl_get($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
/**
* @param string $postid String 快递单号
* @return mixed at most json
*/
function shentong($postid = "268323324324")
{
$post_data = array (
"type" => "shentong",
"postid" => $postid ,
"id" => "1",
"valicode" => "",
"temp" => "0.7771608149632812"
) ;
$url ='http://www.kuaidi100.com/query';
return curl_get($url,$post_data);
}
$ans = shentong("268323324324"
); //快递单号$final = json_decode($ans);//print_r($final);$message = $final["message"];//message 就是我们最终输出的信息echo "Message : ".$message;// 调用方法// $result = simi("你的数据");
很简单的get数据并且抓取==。表示没什么好解释的。
传递的参数就是一个简单的 快递单号。以后再写别的快递查询...
更多推荐

所有评论(0)