Overview

Packages

  • None
  • WxRobot
    • Admin
    • Cmd
    • CoreFunctions
    • Exends
    • Install
    • Table
    • Uninstall
    • WxSDK

Classes

  • ErrorCode
  • PKCS7Encoder
  • Prpcrypt
  • SHA1
  • Weixin_BaseCore
  • WeiXin_SDK
  • Weixin_Template
  • WXBizMsgCrypt
  • WxRobot_Admin
  • WxRobot_Admin_Menu_Extends
  • WxRobot_Admin_Menu_Instro
  • WxRobot_Admin_Menu_Menu
  • WxRobot_Admin_Menu_Records
  • WxRobot_Admin_Menu_Reply
  • WxRobot_Admin_Menu_Setting
  • WxRobot_Admin_Menu_Statistics
  • WxRobot_Cmd
  • WxRobot_Cmd_Event
  • WxRobot_Cmd_Event_User
  • WxRobot_Cmd_Text
  • WxRobot_Extends
  • WxRobot_Install
  • WxRobot_Robot
  • WxRobot_SDK
  • WxRobot_Table_Extends
  • WxRobot_Table_Menu
  • WxRobot_Table_Records
  • WxRobot_Table_Reply
  • WxRobot_Uninstall
  • WxRobot_Wp
  • XMLParse

Functions

  • wx_admin_log
  • wx_is_xml
  • wx_notice_msg
  • wx_parse_xml
  • wx_random_big_pic
  • wx_random_small_pic
  • wx_request_array
  • wx_request_decode
  • wx_request_is_encode
  • wx_request_xml
  • wx_send_encode
  • Overview
  • Package
  • Class
 1: <?php
 2: /**
 3:  * WxRobot 入口类
 4:  * 
 5:  * @author      Midoks
 6:  * @category    WxRobot
 7:  * @package     WxRobot/Cmd
 8:  * @since       5.3.0
 9:  */
10: 
11: class WxRobot_Robot{
12: 
13:     /**
14:      * WxRobot_Robot Instance
15:      */
16:     public static $_instance = null;
17: 
18:     /**
19:      * 构造函数
20:      */
21:     public function __construct(){
22:         include_once('class-wx-functions.php');
23:         include_once('class-wx-cmd.php');
24:     }
25: 
26:     /**
27:      * WxRobot 入口类实例化
28:      * 
29:      * @return WxRobot_Robot instance
30:      */
31:     public static function instance(){
32:         if( is_null (self::$_instance)){
33:             self::$_instance = new self();
34:         }
35:         return self::$_instance;
36:     }
37: 
38:     /**
39:      * 机器人功能验证和返回信息
40:      * 
41:      * @return void
42:      */
43:     public function valid(){
44:         if(isset($_GET['debug'])){
45:             header('Content-type: text/html;charset=utf-8');
46:             $this->responseMsg();
47:         }else{
48:             if($this->checkSignature()){
49:                 $echoStr = (isset($_GET['echostr']))?$_GET['echostr']:'';
50:                 if(!empty($echoStr)){
51:                     echo $echoStr;
52:                 }else{
53:                     $this->responseMsg();
54:                 }
55:             }else{
56:                 //echo '验证未通过!!!';
57:                 $this->responseMsg();
58:             }
59:         }
60:     }
61: 
62:     /**
63:      * 验证消息真实性
64:      *
65:      * @return bool
66:      */
67:     private function checkSignature(){
68:         $signature = $_GET['signature'];
69:         $timestamp = $_GET['timestamp'];
70:         $nonce = $_GET['nonce'];
71: 
72:         $token = WEIXIN_TOKEN;
73:         $tmpArr = array($token, $timestamp, $nonce);
74:         sort($tmpArr, SORT_STRING);
75:         $tmpStr = implode( $tmpArr );
76:         $tmpStr = sha1( $tmpStr );
77:       
78:         if($tmpStr == $signature){
79:             return true;
80:         }else{
81:             return false;
82:         }
83:     }
84: 
85:     /**
86:      *  返回响应信息
87:      *
88:      *  @return xml
89:      */
90:     public function responseMsg(){
91:         echo WxRobot_Cmd::instance()->cmd();exit;
92:     }   
93: 
94: }
95: ?>
96: 
API documentation generated by ApiGen