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 Install
  4:  * 
  5:  * WP微信机器人安装准备
  6:  *
  7:  * @author      midoks
  8:  * @category    Install
  9:  * @package     WxRobot/Install
 10:  * @since       5.3.0
 11:  */
 12: 
 13: if ( ! defined( 'ABSPATH' ) ) {
 14:     exit;
 15: }
 16: 
 17: if (! class_exists('WxRobot_Install')) :
 18: 
 19: /**
 20:  * WxRobot_Install 安装类
 21:  */
 22: class WxRobot_Install{
 23: 
 24:     /**
 25:      * 表前缀
 26:      */
 27:     public static $table_prefix = 'midoks_';
 28: 
 29: 
 30:     /**
 31:      * 构造函数
 32:      *
 33:      * @return void
 34:      */
 35:     public function __construct(){
 36:         $this->create_options();
 37:         $this->create_tables();
 38:     }
 39: 
 40:     /**
 41:      * 初始化帮助信息
 42:      *
 43:      * @return string
 44:      */
 45:     public function weixin_init_help(){
 46:         $text = "提供的方式:\n?(提供帮助)\nn5(最新文章五篇)\nh5(热门文章五篇)\nr5(随机文章五篇)";
 47:         return $text;
 48:     }
 49: 
 50:     /**
 51:      * 保存基本配置信息
 52:      *
 53:      * @return void
 54:      */
 55:     public function create_options(){
 56: 
 57:         //订阅时,给用户的提示信息
 58:         $weixin_robot_options['subscribe'] = '欢迎订阅,回复?提供帮助信息';
 59:         
 60:         //文章最优处理
 61:         $weixin_robot_options['opt_pic_show'] = 'false';
 62:         $weixin_robot_options['opt_big_show'] = '';
 63:         $weixin_robot_options['opt_small_show'] = '';
 64: 
 65:         //测试模式
 66:         $weixin_robot_options['weixin_robot_debug'] = 'true';
 67:         //是否开启数据库记录,默认开启
 68:         $weixin_robot_options['weixin_robot_record'] = 'true';
 69:         //定义帮助的信息
 70:         $weixin_robot_options['weixin_robot_helper'] = $this->weixin_init_help();
 71:         //定义是否无此命令,回复帮助信息
 72:         $weixin_robot_options['weixin_robot_helper_is'] = 'false';
 73:         //推送今日文章
 74:         $weixin_robot_options['weixin_robot_push_today'] = '';
 75: 
 76:         //服务号配置
 77:         $weixin_robot_options['ai'] = '';
 78:         $weixin_robot_options['as'] = '';
 79: 
 80:         //TOKEN相关(URL验证)
 81:         $weixin_robot_options['token'] = 'midoks';
 82:         $weixin_robot_options['token_url'] = 'midoks';
 83:         
 84:         //token
 85:         $weixin_robot_options['weixin_robot_token'] = '';   
 86: 
 87:         add_option(WEIXIN_ROBOT_OPTIONS, $weixin_robot_options);
 88:     }
 89: 
 90:     /**
 91:      * 创建表
 92:      *
 93:      * @return void
 94:      */
 95:     public function create_tables(){
 96:         global $wpdb;
 97:         $wpdb->hide_errors();
 98:         require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
 99: 
100:         $wpdb->query(self::get_schema_weixin_robot());
101:         $wpdb->query(self::get_schema_weixin_robot_reply());
102:         $wpdb->query(self::get_schema_weixin_robot_menu());
103:         $wpdb->query(self::get_schema_weixin_robot_extends());
104:         
105: 
106:         //此方法未生效
107:         //dbDelta();
108:     }
109: 
110:     /**
111:      * 获取表属性
112:      */
113:     public static function get_schema_attr(){
114:         global $wpdb;
115:         $collate = '';
116:         if ( $wpdb->has_cap( 'collation' ) ) {
117:             if ( ! empty( $wpdb->charset ) ) {
118:                 $collate .= " DEFAULT CHARACTER SET $wpdb->charset";
119:             }
120:             if ( ! empty( $wpdb->collate ) ) {
121:                 $collate .= " COLLATE $wpdb->collate";
122:             }
123:         }
124:         return $collate;
125:     }
126: 
127:     /**
128:      * 获取创建微信通信的SQL
129:      *
130:      * @return sql
131:      */
132:     public static function get_schema_weixin_robot(){
133:         
134:         $prefix = self::$table_prefix;
135:         $collate = self::get_schema_attr();
136:         
137:         return "
138: create table if not exists {$prefix}weixin_robot (
139:     `id` bigint(20) not null auto_increment,
140:     `from` varchar(64) not null,
141:     `to` varchar(32) not null,
142:     `msgid` char(64) not null,
143:     `msgtype` varchar(10) not null,
144:     `createtime` varchar(13) not null,
145:     `content` varchar(100) not null, 
146:     `picurl` varchar(100) not null,
147:     `location_x` double(10,6) not null,
148:     `location_y` double(10,6) not null,
149:     `scale` double(10,6) not null,
150:     `label` varchar(255) not null,
151:     `title` text not null,
152:     `description` longtext not null,
153:     `url` varchar(255) not null,
154:     `event` varchar(255) not null,
155:     `eventkey` varchar(255) not null,
156:     `format` varchar(255) not null,
157:     `recognition` varchar(255) not null,
158:     `mediaid` varchar(255) not null,
159:     `thumbmediaid` varchar(255) not null,
160:     `response` varchar(255) not null,
161:     `response_time` double(10,6) not null,
162:     primary key(`id`)
163: ) $collate;
164:     ";
165:     }
166: 
167:     /**
168:      * 获取创建微信自定义回复的SQL
169:      *
170:      * @return sql
171:      */
172:     public static function get_schema_weixin_robot_reply(){
173:         
174:         $prefix = self::$table_prefix;
175:         $collate = self::get_schema_attr();
176:         
177:         return "
178: create table if not exists {$prefix}weixin_robot_reply (
179:     `id` bigint(20) not null auto_increment,
180:     `keyword` varchar(255) not null,
181:     `relpy` text not null,
182:     `status` char(64) not null,
183:     `time` datetime not null,
184:     `type` varchar(100) not null,
185:     `sort` int(10) not null default 0,
186:     primary key(`id`)
187: ) $collate;
188:     ";
189:     }
190: 
191:     /**
192:      * 获取创建微信菜单设置的SQL
193:      *
194:      * @return sql
195:      */
196:     public static function get_schema_weixin_robot_menu(){
197:         
198:         $prefix = self::$table_prefix;
199:         $collate = self::get_schema_attr();
200:         
201:         return "
202: create table if not exists {$prefix}weixin_robot_menu (
203:     `id` bigint(20) not null auto_increment,
204:     `menu_name` varchar(255) not null,
205:     `menu_type` varchar(100) not null,
206:     `menu_key` text not null,
207:     `menu_callback` varchar(180) not null,
208:     `menu_sort` int(10) not null default 0,
209:     `pid` int(10) not null,
210:     primary key(`id`)
211: ) $collate;
212:     ";
213:     }
214: 
215:     /**
216:      * 获取创建扩展的SQL
217:      *
218:      * @return sql
219:      */
220:     public static function get_schema_weixin_robot_extends(){
221:         
222:         $prefix = self::$table_prefix;
223:         $collate = self::get_schema_attr();
224:         
225:         return "
226: create table if not exists {$prefix}weixin_robot_extends (
227:     `id` bigint(20) not null auto_increment,
228:     `ext_name` varchar(180) not null,
229:     `ext_type` varchar(100) not null,
230:     `ext_sort` int(10) default 0,
231:     `ext_int` int not null,
232:     primary key(`id`),
233:     UNIQUE KEY `ext_name` (`ext_name`)
234: ) $collate;
235:     ";
236:     }
237: 
238: }
239: 
240: endif;
241: 
242: return new WxRobot_Install();
243: ?>
244: 
API documentation generated by ApiGen