This repository was archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass.base.php
More file actions
executable file
·182 lines (144 loc) · 5.8 KB
/
Copy pathclass.base.php
File metadata and controls
executable file
·182 lines (144 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/**
* 公众平台基础类 For Fshare
* @author: Skiychan
* @created: 2013.11.19
* @modified: 2015.02.10
*/
class BaseClass
{
public $token = '';
public function __construct($token = NULL){
$this->token = $token;
}
//判断是否来自微信/易信服务器
public function valid(){
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
private $toUsername;
private $fromUsername;
private $createTime;
private $msgId;
private $msgType;
private $time;
private $content;
private $postStr;
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
$this->postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->toUsername = $this->postObj->ToUserName;
$this->fromUsername = $this->postObj->FromUserName;
$this->createTime = $this->postObj->CreateTime;
$this->msgId = $this->postObj->MsgId;
$this->msgType = $this->postObj->MsgType;
$this->time = time();
$resultStr = "error";
if (!empty($postStr)) {
$resultStr = $this->get_text();
}
echo $resultStr;
}
//接收到文本
public function get_text()
{
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
if ($this->msgType != "text") {
$content = "快递信息输入错误。";
} else {
$this->content = $this->postObj->Content;
$this->content = preg_replace("/(\s{2,})/", " ", $this->content);
$content_list = explode(" ", $this->content);
if (count($content_list) == 2) {
include_once "get_companies.php";
$company = new company();
$company_infos = $company::get_companies_info($content_list[0]);
//如果快递100不支持此快递则diy
if(count($company_infos) == 0) {
$is_diy = true;
$company::$companies = include_once 'fetch/add_companies.php';
$company_infos = $company::get_companies_info($content_list[0]);
}
//有此快递公司
if (isset($company_infos[0])) {
$num = $content_list[1];
$code = $company_infos[0]['code']; //获取英文代码
$com = $company_infos[0]['company']; //获取公司名称
$numinfo = "快递:" . $com . "\n" . "单号:" . $num . "\n";
if (!$is_diy) {
$kd_url = "http://m.kuaidi100.com/query?type=" . $code . "&postid=" . $num;
} else {
$kd_url = dirname('http://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]) . '/fetch/index.php?code=' . $code . "&postid=" . $num;
}
$json_getdata = file_get_contents($kd_url);
//$get_kdinfo = json_decode($json_getdata); //object
$get_kdinfo = json_decode($json_getdata, true); //array
//查询时间的显示
$nowtime = isset($get_kdinfo['updatetime']) ? $get_kdinfo['updatetime'] : date("Y-m-d H:i:s", time());
$last_t = "查询时间:\n" . $nowtime . "\n\n"; //查询时间
$kd_shipinfo = $get_kdinfo['data']; //快递数据数组
$kd_total = count($kd_shipinfo) - 1;
$ship = '';
$detail = "\n<a href='http://api.oupag.com/developer/kuaidi/getdata.php?code=" . $code . "&num=" . $num . "'>点击查看详情</a>";
//物流倒序详情
for ($i = $kd_total; $i >= 0; $i--) {
$shipinfo = $kd_shipinfo[$i]['time'] . "\n" . $kd_shipinfo[$i]['context'] . "\n";
$ship = $shipinfo . $ship;
}
//顺序物流详情
/*foreach ($kd_shipinfo as $v){
$shipinfo = $v['time']."\n".$v['context']."\n";
$ship = $shipinfo.$ship;
}
*/
$get_kdinfo = $numinfo . $last_t . "【物流详情】\n" . $ship;
if ($ship) {
$contentStr = $get_kdinfo;
} else {
//$contentStr = $numinfo . ">没有物流数据!" . $kd_url;
$contentStr = $numinfo . ">没有物流数据!";
}
$contentStr .= $detail;
} else { //无此快递公司
$contentStr = "无此快递公司记录.";
}
} else {
$contentStr = "格式错误,正确格式如下:\n快递公司名称 快递单号";
}
}
$resultStr = sprintf($textTpl,
$this->fromUsername,
$this->toUsername,
$this->time,
"text",
$contentStr);
return $resultStr;
}
//判断签名,返回bool
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
if ($tmpStr == $signature) {
return true;
} else {
return false;
}
}
}