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 Table Extends 
  4:  * 
  5:  * WP微信机器人 扩展表的相关功能
  6:  *
  7:  * @author      midoks
  8:  * @category    Table
  9:  * @package     WxRobot/Table
 10:  * @since       5.3.0
 11:  */
 12: 
 13: if ( ! defined( 'ABSPATH' ) ) {
 14:     exit;
 15: }
 16: 
 17: /**
 18:  *  WxRobot_Table_Records 微信通信记录模型
 19:  */
 20: class WxRobot_Table_Records{
 21: 
 22:     /**
 23:      * 表前缀
 24:      */
 25:     public $table_prefix = 'midoks_';
 26: 
 27:     /**
 28:      * Table Extends Instance
 29:      */
 30:     public static $_instance = null;
 31:     
 32: 
 33:     /**
 34:      * WxRobot 扩展表类实例化
 35:      * 
 36:      * @return WxRobot_Table_Extends - Table Extends instance
 37:      */
 38:     public static function instance(){
 39:         if( is_null (self::$_instance)){
 40:             self::$_instance = new self();
 41:         }
 42:         return self::$_instance;
 43:     }
 44: 
 45:     /**
 46:      * 获取记录表名
 47:      *
 48:      * @return string
 49:      */
 50:     private function get_table_name(){
 51:         return $this->table_prefix.'weixin_robot';
 52:     }
 53: 
 54:     /**
 55:      * 获取菜单表名
 56:      *
 57:      * @return string
 58:      */
 59:     private function get_table_name_menu(){
 60:         return $this->table_prefix.'weixin_robot_menu';
 61:     }
 62: 
 63:     /**
 64:      * 插入记录数据
 65:      *
 66:      * return bool
 67:      */
 68:     public function insert($from, $to, $msgid, $msgtype, $createtime, $content, $picurl, $location_x, $location_y,
 69:         $scale, $label, $title, $description, $url, $event,$eventkey,$format, $recognition, $mediaid,$thumbmediaid, $response, $response_time){
 70:         
 71:         global $wpdb;
 72:         $table_name = $this->get_table_name();
 73:         
 74:         $sql = "INSERT INTO `{$table_name}` (`id`, `from`, `to`, `msgid`, `msgtype`, `createtime`, `content`, `picurl`, `location_x`, `location_y`, `scale`, `label`, `title`, `description`, `url`, `event`, `eventkey`, `format`,`recognition`,`mediaid`, `thumbmediaid`, `response`, `response_time`) VALUES(null,'{$from}','{$to}','{$msgid}', '{$msgtype}','{$createtime}', '{$content}','{$picurl}','{$location_x}', '{$location_y}','{$scale}', '{$label}', '{$title}','{$description}', '{$url}', '{$event}','{$eventkey}','{$format}', '{$recognition}', '{$mediaid}','{$thumbmediaid}', '{$response}', '{$response_time}')";
 75:         return $wpdb->query($sql);
 76:     }
 77: 
 78:     /**
 79:      * 获取消息类型的总数
 80:      */
 81:     public function weixin_get_msgtype_count($text = 'text'){
 82:         global $wpdb;
 83:         $table_name = $this->get_table_name();
 84:         $sql = 'select count(`id`) as count from `'.$table_name."` where `msgtype`='{$text}'";
 85:         $result = $wpdb->get_results($sql);
 86:         return $result[0]->count;
 87:     }
 88: 
 89:     /**
 90:      * 获取记录总数
 91:      *
 92:      * @return int
 93:      */
 94:     public function weixin_get_count(){
 95:         global $wpdb;
 96:         $table_name = $this->get_table_name();
 97:         $sql = "select count(id) as count from `{$table_name}`";
 98:         $data = $wpdb->get_results($sql);
 99:         return $data[0]->count;
100:     }
101: 
102:     /**
103:      * 微信数据获取
104:      * 
105:      * @param uint $page_no 第几页数据
106:      * @param uint $num 每页显示的数据
107:      * @return array
108:      */
109:     public function weixin_get_data($page_no = 1, $num = 20){
110:         global $wpdb;
111:         $table_name = $this->get_table_name();
112: 
113:         if($page_no < 1){
114:             $page_no = 1;
115:         }
116:         $start = ($page_no-1)*$num;
117:         $sql = "select `id`,`from`,`to`,`msgtype`,`createtime`,`content`,`picurl`,`location_x`,`location_y`, `scale`, `label`, `title`,"
118:             ."`description`,`url`,`event`, `eventkey`,`format`,`recognition`,`mediaid`,`thumbmediaid`,`response`, `response_time`"
119:             ." from `{$table_name}` order by `id` desc limit {$start},{$num}";
120:         $data  = $wpdb->get_results($sql);
121:         $newData = array();
122:         foreach($data as $k=>$v){
123:             $arr = array();
124:             $arr['id'] = $v->id;
125:             $arr['from'] = $v->from;
126:             $arr['to'] = $v->to;
127:             $arr['msgtype'] = $v->msgtype;
128: 
129:             //暂时显示文本消息
130:             switch($v->msgtype){
131:                 case 'text':$arr['content'] = $v->content;break;
132:                 default:$arr['content'] = $v->content;
133:             }
134: 
135:             //菜单点击事件
136:             if('CLICK' == $v->event){
137:                 $data = $this->select_menu_key($v->eventkey);
138:                 if($data){
139:                     $arr['content'] = '菜单:'.$data;
140:                 }else{
141:                     $arr['content'] = '菜单:已经不存在';
142:                 }
143:             }else if('subscribe' == $v->event){//订阅事件
144:                 $arr['content'] = '订阅事件';
145:             }else if('unsubscribe' == $v->event){//取消订阅事件
146:                 $arr['content'] = '取消订阅事件';
147:             }else if('LOCATION' == $v->event){
148:                 $arr['content'] = '地理位置上报告事件';
149:             }else if('location' == $v->msgtype){
150:                 $arr['content'] = '地理位置上报告事件';
151:             }else if('voice' == $v->msgtype){
152:                 $arr['content'] = '语音事件';
153:             }
154: 
155:             $arr['createtime'] = date('Y-m-d H:i:s', $v->createtime);
156:             $arr['response'] = $v->response;
157:             $arr['response_time'] = $v->response_time;
158:             $newData[] = $arr;
159:         }
160:         return $newData;
161:     }
162: 
163:     /**
164:      * 通过菜单key,获取菜单名字
165:      */
166:     public function select_menu_key($key){
167: 
168:         global $wpdb;
169:         $table_name = $this->get_table_name_menu();
170: 
171:         $sql = "select `id`,`menu_name`, `menu_type`, `menu_key`, `menu_callback`, `pid`"
172:             ." from `{$table_name}` where `menu_key`='{$key}' limit 1";
173:         $data  = $wpdb->get_results($sql);
174:         if(empty($data)){
175:             return false;
176:         }else{
177:             return $data[0]->menu_name;
178:         }   
179:         return false;
180:     }
181: 
182:     
183: 
184:     
185: 
186: }
187: ?>
188: 
API documentation generated by ApiGen