Yixin/WeChat public platform-PHP source code

Source: Internet
Author: User
Check express delivery on Yixin public platform

To use this method, edit the following content and send it to the public platform:
For example, query the express delivery with the ticket No. APELAX1040039963
Ecms APELAX1040039963 or Yike (Yike full) APELAX1040039963 [there must be a space between the express delivery company name and express delivery number]

Note: This project uses the kuaidi100 API;
In addition, the Elasticsearch Express used by Amazon in the United States is a self-written collection,

1. [File]Class. base. php
 Token = $ token;} // determines whether the server is from the 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_str Ing ($ 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;} // receives the public function get_text () {$ textTpl ="
 
  %s
  
  %s
  
  
   
% S
  
  %s
  
  %s
  
 "; If ($ this-> msgType! = "Text") {$ content = "incorrect express delivery information. ";}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]); // if Courier 100 does not support this Courier, 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]);} $ num = $ content_list [1]; $ code = $ company_infos [0] ['code']; // Obtain the English code $ com = $ company_infos [0] ['Company']; // Get company name $ numinfo = "Courier :". $ com. "\ n ". "Ticket No :". $ 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 = response ($ kd_url); // $ get_kdinfo = json_decode ($ json_getdata); // object $ get_kdinfo = json_decode ($ json_getdata, true ); // array $ last_t = "query Time: \ n ". $ get_kdinfo ['updatetime']. "\ n"; // query time $ kd_shipinfo = $ get_kdinfo ['data']; // Express data array $ kd_total = count ($ kd_shipinfo)-1; $ ship = ''; $ detail =" \ n Click to view details "; // logistics Reverse order details for ($ I = $ kd_total; $ I> = 0; $ I --) {$ shipinfo = $ kd_shipinfo [$ I] ['Time']. "\ n ". $ kd_shipinfo [$ I] ['context']. "\ n"; $ ship = $ shipinfo. $ ship;} // details of ordered logistics/* foreach ($ kd_shipinfo as $ v) {$ shipinfo = $ v ['Time']. "\ n ". $ v ['context']. "\ n"; $ ship = $ shipinfo. $ ship;} */$ get_kdinfo = $ numinfo. $ last_t. "[logistics details] \ n ". $ ship; if ($ ship) {$ contentStr = $ get_kdinfo;} else {$ contentStr = $ numinfo. "> no logistics data! ". $ Kd_url;} $ contentStr. = $ detail;} else {$ contentStr = "format error. the correct format is as follows: \ n express delivery company name express waybill no." ;}}$ resultStr = sprintf ($ textTpl, $ this-> fromUsername, $ this-> toUsername, $ this-> time, "text", $ contentStr); return $ resultStr;} // judge the signature, return 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 ;}}}


2. [File]Get_companies.php
 Get_companies ();}/** return array companies infos */public static function get_companies () {return include_once self: $ file_name ;} /** get the company name through encoding * @ param string $ code encoding * return string company name */public static function get_company_name ($ code) {foreach (self :: $ companies as $ keys =>$ values) {if ($ values ['code'] ==$ code) {return $ values ['Company'] ;}} return ;} /** get encoding by company name * $ param string $ name Company name * return string encoding */public static function get_company_code ($ name) {foreach (self :: $ companies as $ keys =>$ values) {if ($ values ['name'] ==$ name) {return $ values ['code'] ;}} return ;} /** complete encoding obtained by courier company name or code fuzzy search all * $ param string $ input company name * return array encoding and company name */public static function get_companies_info ($ input) {$ lists = array (); foreach (self: $ companies as $ keys => $ values) {if (mb_stristr ($ values ['Company'], $ input )) {unset ($ values ['id']); $ lists [] = $ values ;}} // if the value cannot be obtained by name, use the key name if (count ($ lists) = 0) {foreach (self: $ companies as $ keys => $ values) {if (mb_stristr ($ values ['code'], $ input) {unset ($ values ['id']); $ lists [] = $ values ;}}} return $ lists;}/** get the encoding and company name directly without type * @ param string encoding or company name * return array encoding and company name */public static function get_company_info ($ input) {foreach (self ::$ companies as $ keys = >$ values) {if (in_array ($ input, $ values) {unset ($ values ["id"]); return $ values ;}} return ;}}


3. [File]Ecms. php
 * @ Created: 1/6/15 21:15 * @ modified: * // lang = {cn/en} // https://www.php1.cn/// $ lang = "cn "; $ postid = isset ($ _ GET ['postid'])? $ _ GET ['postid']: 0; $ kd_url = "https://www.ecmsglobal.com/oms/showtracking? Trackingno = {$ postid} & lang = {$ lang} "; $ page_info = file_get_contents ($ kd_url); // $ page_info = file_get_contents (" a.html "); $ page_dom ="
 ". $ Page_info; $ xmldoc = new DOMDocument (); @ $ xmldoc-> loadHTML ($ page_dom); $ xmldoc-> normalizeDocument (); $ page_xml = new Domxpath ($ xmldoc ); $ event_date = $ page_xml-> query ('// p [@ class = "order"] // ul // p [@ class = "column event_date"]'); $ event_where = $ page_xml-> query ('// p [@ class = "order"] // ul // p [@ class = "column event_where"]'); $ event_desc = $ page_xml-> query ('// p [@ class = "order"] // ul // p [@ class = "column event_desc"]'); $ thisinfo = array (); $ add_infos = array (); foreach ($ event_date as $ keys = >$ values) {$ location = $ event_where-> item ($ keys) -> textContent; $ context = $ event_desc-> item ($ keys)-> textContent; $ thisinfo [] = array ('time' => $ values-> textContent, 'location' => $ location, 'context' => $ location. ", \ n ". $ context,);} if (count ($ thisinfo)> 0) {$ add_infos = array ('message' => "OK", 'Nu '=> $ postid, 'companytype' => "ecms", 'ischeck' => "1", 'com' => "ecms", 'updatetime' => $ event_date-> item (0) -> textContent, 'status' => "200", 'codenumber' => $ postid, 'data' => $ thisinfo);} return $ add_infos;


4. [Image]Sc1.png

5. [Image]Sc2.png

6. [Image]Sc3.png

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.