Usage example of express delivery query function on WeChat public platform

Source: Internet
Author: User
Tags preg
This article mainly introduces the usage of the express delivery query function on the public platform, and analyzes the related techniques and specific usage of the public platform for express delivery query, which is of great practical value, if you need it, refer to the example in this article to describe the usage of the express delivery query function on the public platform. Share it with you for your reference. The details are as follows:

Usage:

# Querying express delivery (or three first letters of ckd) # express delivery number # express delivery ticket number
For example, query the express delivery with the EMS ticket number 1034616494006 ):
# Ckd #15 #1034616494006
Common express number:

15EMS, 56 Shentong, 57 SF, 77 Yuantong,
80 Yunda, 87 Zhongtong, 85 home delivery, 62 days

1. class. base. php file:

<? Php/*** basic public platform class For Fshare * @ author: Skiychan * @ created: 2013.11.19 */class Wechat {// public $ token = ''; /* public function _ construct ($ token) {$ this-> token = $ token;} * // Determine whether the server/* public function valid () {$ echoStr = $ _ GET ["echostr"]; if ($ this-> checkSignature () {echo $ echoStr; exit ;}} */public function responseMsg () {$ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; if (! Empty ($ postStr) {$ postObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ fromUsername = $ postObj-> FromUserName; $ toUsername = $ postObj-> ToUserName; $ keyword = trim ($ postObj-> Content); $ time = time (); $ textTpl ="
       
  %s
        
  %s
        
  
   
% S
        
  %s
        
  %s
        
  
   
0
        
 "; If (! Empty ($ keyword) {// when the input text type is if ($ msgType = "text") {// $ contentStr = $ keyword. $ fromUsername. $ time; // $ preg = "/^ \ # ([\ W \ w] *?) # ([\ W \ w] *?) \#(. *)/"; // 0 indicates the function, 1 indicates the option, and 2 indicates the remaining value. // $ preg ="/\ # ([\ w] + )/"; // 0 indicates the function, and 1 indicates the option, 2 is the remaining value $ preg = "/\ # ([\ w \ d \ x {4e00}-\ x {9fa5}] +)/u "; // 0 is the function, 1 is the option, and 2 is the remaining value preg_match_all ($ preg, $ keyword, $ newdata); $ fn_name = $ newdata [1] [0]; // Obtain the express delivery parameter if (strtolower ($ fn_name) = "skiy") {$ me = "I am the developer of this public account, and the English name is Skiy. \ N if you have any comments and suggestions on this function, please contact me, \ n my QQ is 1005043848 \ n is forskiy, mail: \ ndeveloper@zzzzy.com "; $ contentStr = $ me ;} // Obtain the courier parameter if ($ fn_name = "courier" | strtolower ($ fn_name) = "kuaidi") {$ kdlist = ''; // enable PDO to connect to sqlite $ db = new PDO ("sqlite: somedata/data. dat "); $ results = $ db-> query ('select * FROM kuaidi')-> fetchAll (); foreach ($ results as $ key => $ row) {// var_dump ($ row); // $ list_one = $ row ['id']. "". $ row ['code']. "". $ row ['Company']. "\ n"; $ list_one = $ row ['id']. ''. $ row ['Company']. "\ n"; $ kdlist = $ kdlist. $ list_one;} // The host supports sqlite3/* $ db = new SQLite3 ("somedata/data. dat "); $ results = $ db-> query ('select * FROM kuaidi'); while ($ row = $ results-> fetchArray ()) {// var_dump ($ row); $ list_one = $ row ['id']. "". $ row ['code']. "". $ row ['Company']. "\ n \ r"; $ kdlist = $ kdlist. $ list_one;} */$ contentStr = $ kdlist;} if ($ fn_name = "" | strtolower ($ fn_name) = "ckd ") {$ id = $ newdata [1] [1]; $ num = $ newdata [1] [2]; $ db = new PDO ("sqlite: somedata/data. dat "); $ results = $ db-> query ('select code, company FROM kuaidi WHERE id = '. $ id)-> fetchAll (); $ code = $ results [0] ['code']; // get the English code $ com = $ results [0] ['Company']; // get the company name $ numinfo = "Courier :". $ com. "\ n ". "Ticket No :". $ num. "\ n"; $ kd_url =" http://m.kuaidi100.com/query?type= ". $ 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 = ''; // logistics Reverse order details for ($ I = $ kd_total; $ I >=0; $ I --) {$ shipinfo = $ kd_shipinfo [$ I] ['Ti Me ']. "\ 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! ";}}$ ResultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr); echo $ resultStr ;} else {echo "Input something... ";}} else {echo" You have no enter something... "; exit ;}// determine the signature and 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. index. php file:

<? Php/***** public platform Message Interface For Fshare (share information) * @ author: Skiychan (Wechat: forskiy) * @ created: 2013.11.19 **/include_once 'class. base. php '; define ('token', 'skiychan'); $ wx = new Wechat (); // $ wx-> valid (); $ wx-> responseMsg ();

I hope this article will help you with php programming.

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.