PHP 微信接口封装类_PHP教程

WBOY
풀어 주다: 2016-07-13 10:38:53
원래의
1125명이 탐색했습니다.

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; } } }   ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735072.htmlTechArticle?php/** * 微信公众平台接口PHP100封装功能类文件 * author * date 2013-4-9 PRC:E+8 23:03 */define(TOKEN, chuangenit);$wechatObj = new wechatCallbackapiTest();$wechatObj-...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!