search
Homephp教程php手册PHP 微信接口封装类

PHP 微信接口封装类

Jun 13, 2016 am 09:43 AM
datephpFunctionencapsulationplatformWeChatinterfacedocumentkind

weixin_run(); //执行接收器方法   class wechatCallbackapiTest {    private $fromUsername;    private $toUsername;    private $times;    private $keyword;            public function weixin_run(){      $this->responseMsg(); $arr[]=array("很靠谱,不错!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.baidu.com"); $arr[]=array("很靠谱,不错!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.baidu.com"); $arr[]=array("很靠谱,不错!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.baidu.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()     {         $echoStr = $_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, 'SimpleXMLElement', 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!";          exit;         }     }   //微信封装类, //type: text 文本类型, news 图文类型 //text,array(内容),array(ID) //news,array(array(标题,介绍,图片,超链接),...小于10条),array(条数,ID)   private function fun_xml($type,$value_arr,$o_arr=array(0)){  //=================xml header============  $con=" fromUsername}]]> toUsername}]]> {$this->times} ";         //=================type content============  switch($type){      case "text" :   $con.=" {$o_arr}";   break;   case "news" :   $con.="{$o_arr[0]} "; foreach($value_arr as $id=>$v){ if($id>=$o_arr[0]) break; else null; //判断数组数不超过设置数          $con.="   "; } $con.=" {$o_arr[1]}";   break;    } //end switch   //=================end return============  echo $con.""; }       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; } } }   ?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools