大二学了一下PHP cURL,做了几个demo。
1、代码如下:
index.php
<html>
<head>
<title>快递查询</title>
<meta charset="utf-8">
<meta name="description" content="快递查询">
<style type="text/css">
*{margin: 0;padding: 0;border: 0;}
body{background-color: rgb(240,240,240);font-family: Microsoft YaHei;}
p{padding-bottom: 10px;}
.p_input{width: 100%;height: 50px;outline: 0;padding-left: 50px;font-family: Microsoft YaHei;font-size: 16px;}
.p_sub{width: 100%;height: 50px;font-family: Microsoft YaHei;background-color: rgb(90,215,0);color: #fff;font-size: 16px;}
.result_p{width: 95%;padding-left: 5%;height: 60px;display: block;line-height: 60px;background-color: #f8f8f8;}
.result_p0{
width: 95%;
height: 40px;
display: block;
padding-left: 5%;
line-height: 40px;
font-size: 14px;
background-color: #fff;
transition: background-color .5s ease;
}
.result_p1{
width: 95%;
height: 60px;
display: block;
padding-left: 5%;
line-height: 32px;
font-size: 14px;
background-color: #f8f8f8;
transition: background-color .5s ease;
}
.result_s{font-size: 12px;text-align: center;margin-top: 20px;}
</style>
</head>
<body>
<form method="post">
<p><input class="p_input" name="kuaidi" type="number" placeholder="请输入单号" maxlength="30" value=""></p>
<p><input id='show-toast' class="p_sub" name="submit" type="submit" value="查询" οnclick="return form_onsubmit(this.form)"/></p>
</form>
<script type="text/javascript">
function form_onsubmit(obj){
if(obj.kuaidi.value == "") {
alert("亲~请输入单号");
return false;
}
else{
// $(document).on("click", "#show-toast", function() {
// $.toast("操作成功", function() {
// console.log('close');
// });
// })
return true;
}
}
</script>
<!-- <script>
$(function() {
FastClick.attach(document.body);
});
</script> -->
</body>
</html>
<?php
error_reporting(0);
if(isset($_POST['submit'])){
include 'search.php';
$k = new kuaidi_query($_POST['kuaidi']);
$res = $k->kuaidi_query_number();
// var_dump($res);
if ($res['message']=='ok') {
$res01 = $res['data'];
echo("<p class='result_p'>快递单号:$_POST[kuaidi]</p>");
foreach ($res01 as $key => $value) {
// var_dump ($key);
$res02 = $value;
echo("<p class='result_p0'>$res02[time]</p>");
echo("<p class='result_p1'>$res02[context]</p>");
}
echo ("<p class='result_s'>以上数据来之快递100、快递查询网</p>");
}
else {
// echo $jsondata['msg'];
echo<<<begin2
<br/>
<p align="center">抱歉,您输入的快递单号有误或者服务器繁忙!</p>
begin2;
}
}
?>
<p align="center" style="font-size: 12px;margin-top: 20px;">by 赛亚王子_Vegeta</p>
search.php
<?php
/**
* kuaidi_query
*/
class kuaidi_query
{
private $kuaidi;
private $get_data;
public function __construct($get_data)
{
$this->kuaidi = $get_data;
}
public function object_array($array)
{
if(is_object($array))
{
$array = (array)$array;
}
if(is_array($array))
{
foreach($array as $key=>$value)
{
$array[$key] = $this->object_array($value);
}
}
return $array;
}
public function kuaidi_query_number(){
$kuaidi = $_POST['kuaidi'];
$company = file_get_contents("http://m.kuaidi100.com/autonumber/auto?num=".$kuaidi);
preg_match_all('/"(.*?)"/',$company,$match);
$company = $match[1][1];
$company = file_get_contents("http://m.kuaidi100.com/query?type=".$company."&postid=".$kuaidi."&id=1&valicode=");
$c= json_decode($company);
$array = $this->object_array($c);
return $array;
}
}
?>
2、效果截图
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/151242.html