Public platform Express Query function Usage example, public example
The example of this paper describes the use of Express query function of public platform. Share to everyone for your reference. Specific as follows:
How to use:
#查快递 (or three first-letter CKD) #快递编号 # Express Number
such as (Inquiry EMS number 1034616494006 Courier):
#ckd #15#1034616494006
Common Courier Number:
15ems,56 Shentong, 57 Shun Fung, 77 Yuantong,
80 Yun da, 87 Zhong Tong, 85 home emergency delivery, 62 daily
1. class.base.php File:
<?php/** * Public platform base class for Fshare * @author: Skiychan * @created: 2013.11.19 */class wechat{//pubic $token = ";/* Publi C function __construct ($token) {$this->token = $token;} *///Determine if from 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 0
%s
%s
%s
%s
"; if (!empty ($keyword)) {//When input text type if ($msgType = "text") {//$contentStr = $keyword. $fromUsername. $time; $preg = "/^\# ([\w\w]*?) \# ([\w\w]*?) \#(.*)/"; 0 is the function, 1 is the option, 2 is the remaining value//$preg = "/\# ([\w]+)/"; 0 is the function, 1 is the option, and 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]; Get the parameters of the Courier if (Strtolower ($fn _name) = = "Skiy") {$me = "I am the developer of this public account, the English name Skiy. \ n If you have any comments on this function and suggestions, welcome to contact me, \ n My qq is 1005043848\n is Forskiy, e-mail: \ndeveloper@zzzzy.com "; $CONTENTSTR = $me; }//Get the parameters of the Courier if ($fn _name== "Express" | | Strtolower ($fn _name) = = "Kuaidi") {$kdlist = '; How to 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; }//Host support Sqlite3 Way/* $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== "Check Express" | | Strtolower ($fn _name) = = "CKD") {$id = $newdata [1][1]; $num = $newdata [the]; $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 company Name $numinfo = "Courier:". $com. " \ n "." Number: ". $num." \ n "; $KD _url = "http://m.kuaidi100.com/query?type=". $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 $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 = "; Logistic reverse Details for ($i = $KD _total; $i >=0; $i-) {$shipinfo = $KD _shipinfo[$i] [' time ']. " \ n ". $KD _shipinfo[$i [' context ']." \ n "; $ship = $shipinfo. $ship; }//Order Logistics Details/*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 }}//To determine 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. index.php File:
<?php/** * * Public platform Message interface for Fshare (share info) * @author: Skiychan (Wechat:forskiy) * @created: 2013.11.19 * */include_ Once ' class.base.php ';d efine (' TOKEN ', ' Skiychan '); $wx = new Wechat ();//$wx->valid (); $wx->responsemsg ();
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/983998.html www.bkjia.com true http://www.bkjia.com/PHPjc/983998.html techarticle Public Platform Express query function usage examples, public examples This article describes the public platform Express query function usage. Share to everyone for your reference. Specific as follows: ...