PHP micro-letter Interface Encapsulation Class (PHP100)

Source: Internet
Author: User
Tags array exit cdata interface json valid

 

<?php/**   * Micro-trust public Platform Interface PHP100 Package function class file   * Author php100.com   Zhang Enmin   * Date 2013-4-9 prc:e+8 23:03-&NB Sp * Linkme QQ925939 chuangen.com   *   define ("TOKEN", "Chuangenit"); $WECHATOBJ = new Wechatcallbackapitest (); $WECHATOBJ->weixin_run (); Execute receiver method   class Wechatcallbackapitest {   private $fromUsername;    private $toUsername; &nbs P  private $times;    private $keyword;            public function Weixin_run () {      $this->responsemsg (); $arr [ ]=array ("Creation grace is very reliable, PHP100 is also good!") "," AA "," Http://www.chuangen.com/pic/hj/s_4.png "," http://www.chuangen.com "); $arr []=array is very reliable, PHP100 is also good! "," AA "," Http://www.chuangen.com/pic/hj/s_4.png "," http://www.chuangen.com "); $arr []=array is very reliable, PHP100 is also good! "," AA "," Http://www.chuangen.com/pic/hj/s_4.png "," http://www.chuangen.com "); $this->fun_xml ("News", $arr, Array (2,0));     }           function T ($n){   include ("t_api.php")     $c _name= $t _api[$n]     $json =file_get_contents ("http:// M.weather.com.cn/data/101110310.html ");    return Json_decode ($json);  }             Public Function valid ()     {        $EC Hostr = $_get["Echostr"];          //valid signature, option         if ($this->checksignature ()) {         echo $echoStr;         exit;        }     {      public Function responsemsg ()     {$POSTSTR = $GLOBALS ["Http_raw_post_data"]; if (!empty ($POSTSTR)) {              $POSTOBJ = simplexml_load_string ($postStr, ' simple XmlElement ', libxml_nocdata);                 $this->fromusername = $POSTOBJ->fromusername;                $this->tousername = $POSTOBJ->tousername;                 $this->keyword = Trim ($postObj->content); $this->times = time ();        }else {      echo "This a file for Weixin api!";       & nbsp Exit        }    / /micro Envelope loading class,//type:text text type, news type//text,array (content), array (ID)//ne Ws,array (title, Introduction, Picture, HYPERLINK),... Less than 10), array (number, ID)   Private Function Fun_xml ($type, $value _arr, $o _arr=array (0)) { //=================xml header============   $con = "<xml> <tousername><! [cdata[{$this->fromusername}]]></tousername> <fromusername><! [cdata[{$this->tousername}]]></fromusername> <createtime>{$this->times}</createtime> <msgtype><! [cdata[{$type}]]></msgtype> ";        //=================type content============  switch ($type) {     case "text":    $con. = "<content><![ cdata[{$value _arr[0]}]]></content> <funcflag>{$o _arr}</funcflag> ";   break;   Case "News":    $con. = "<articlecount>{$o _arr[0]}</articlecount> <Articles>"; foreach ($value _arr as $id => $v) {if ($id >= $o _arr[0]) break; number of arrays not exceeding set         &NBSP ; $con. = "<item> <title><! [cdata[{$v [0]}]]></title>  <description><! [cdata[{$v [1]}]]></description> <picurl><! [cdata[{$v [2]}]]></picurl> <url><! [cdata[{$v [3]}]]></url> </item> "; $con. = "</Articles> <funcflag>{$o _arr[1]}</funcflag>";   break;   &NBSP}//end switch  //=================end return============  echo $con. " </xml> "; }       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;} }  ?>

Related Article

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.