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 Admin
  4:  * 
  5:  * WP微信机器人后台菜单 - 插件功能介绍
  6:  *
  7:  * @author      midoks
  8:  * @category    Admin
  9:  * @package     WxRobot/Admin
 10:  * @since       5.3.0
 11:  */
 12: 
 13: if ( ! defined( 'ABSPATH' ) ) {
 14:     exit;
 15: }
 16: 
 17: /**
 18:  *  WxRobot_Admin_Menu_Reply 关键子回复类
 19:  */
 20: class WxRobot_Admin_Menu_Reply{
 21: 
 22:     /**
 23:      *  初始化钩子和过滤
 24:      *
 25:      *  @reutrn void
 26:      */
 27:     public function init(){
 28:         add_action('init', array($this, 'relpy_ajax'), 9);
 29:         add_action('admin_head', array(&$this, 'weixin_robot_reply_js'), 9);
 30:     }
 31: 
 32:     /**
 33:      * 加载需要的js
 34:      *
 35:      * @return void
 36:      */
 37:     public function weixin_robot_reply_js(){
 38:         $url = WEIXIN_ROBOT_URL;
 39:         //使用ichatjs开源项目 http://www.ichartjs.com/
 40:         if(!empty($_GET['page']) && 'weixin-robot-setting-keyword-relpy' == $_GET['page']){
 41:             echo '<link type="text/css" rel="stylesheet" href="'.$url.'/assets/css/hover.css" />';
 42:             echo '<script type="text/javascript" src="'.$url.'/assets/js/weixin_robot_setting_keyword_relpy.js"></script>';
 43:         }
 44:     
 45:     }
 46: 
 47:     /**
 48:      * Ajax设置关键字
 49:      *
 50:      * @return json
 51:      */
 52:     public function relpy_ajax(){
 53:         if(!empty($_POST['page']) && $_POST['page'] == 'weixin_robot_setting_keyword_relpy'){
 54:             if($_POST['method'] == 'update'){
 55:                 echo($this->relpy_ajax_update());
 56:             }
 57:         }
 58:     }
 59: 
 60:     /**
 61:      * Ajax更新关键字数据
 62:      *
 63:      * @return string
 64:      */
 65:     public function relpy_ajax_update(){
 66:         $id = $_POST['id'];
 67:         $keyword = $_POST['keyword'];
 68:         $reply = strip_tags($_POST['reply']);
 69:         $type = $_POST['type'];
 70:         $res = WxRobot_Table_Reply::instance()->change_reply($id, $keyword, $reply, $type);
 71:         if($res){
 72:             return 'ok';
 73:         }else{
 74:             return 'fail';
 75:         }
 76:     }
 77: 
 78:     /**
 79:      * 菜单初始化
 80:      *
 81:      * @return void
 82:      */
 83:     public function menu(){
 84:         add_submenu_page('weixin-robot',
 85:             'weixin-robot', 
 86:             '微信机器人回复',
 87:             'manage_options',
 88:             'weixin-robot-setting-keyword-relpy',
 89:             array($this, 'setting_keyword_relpy'));
 90:     }
 91: 
 92:     /**
 93:      * 提交添加内容
 94:      *
 95:      * @return void
 96:      */
 97:     public function reply_post(){
 98:         if(isset($_POST['submit_key'])){
 99:             switch($_POST['submit_key']){
100:             case '启用':
101:                 $id = $_POST['id'];
102:                 $data = WxRobot_Table_Reply::instance()->change_relpy_status($id, '1');
103:                 wx_notice_msg('启用成功!!!');
104:                 break;
105:             case '禁用':
106:                 $id = $_POST['id'];
107:                 $data = WxRobot_Table_Reply::instance()->change_relpy_status($id, '0');
108:                 wx_notice_msg('禁用成功!!!');
109:                 break;
110:             case '删除':
111:                 $id = $_POST['id'];
112:                 $data = WxRobot_Table_Reply::instance()->delete_relpy_id($id);
113:                 wx_notice_msg('删除成功!!!');
114:                 break;
115:             case '提交数据':
116:                 $type = $_POST['option']['check'];
117:                 $key = $_POST['option']['key'];
118:                 $relpy = $_POST['option']['word'];
119: 
120:                 if(empty($type) || empty($key) || empty($relpy)){
121:                     wx_notice_msg('信息不能为空!!!');
122:                 }else{
123:                     $result = WxRobot_Table_Reply::instance()->insert_relpy($key, $relpy, $status=1, $type);
124:                     wx_notice_msg('设置成功!!!');
125:                 }
126:                 
127:                 if(!$result){
128:                     wx_notice_msg('设置失败!!!');
129:                 }   
130:                 break;
131:             }   
132:         }
133:     }
134: 
135: 
136:     /**
137:      * 设置关键字回复页
138:      *
139:      * @return void
140:      */
141:     public function setting_keyword_relpy(){
142:         
143:         $this->reply_post();
144:     
145:         echo    '<div class="wrap"><h2>微信机器人关键字自定义回复设置</h2></div>',
146:                 '<div class="wrap"><div class="metabox-holder">',
147:                 '<div class="postbox">',
148:                 '<table class="form-table" style="width:700px;border:2px;border-color:#21759b;">';
149:     
150:         $trTpl = "<tr class='wp_weixin_robot_table_head_tr'>
151:             <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
152:             <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
153:             <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
154:             <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;' scope='col'>%s</td>
155:             <td class='wp_weixin_robot_table_head_td' style='text-align:center;color:#21759b;width:160px' scope='col'>%s</td></tr>";
156:         $tableHeadTpl = sprintf($trTpl, '序号ID', '关键字', '回复内容','类型', '操作');
157:         echo $tableHeadTpl;
158:         
159:         $data = WxRobot_Table_Reply::instance()->weixin_get_relpy_data();
160:         if($data){
161:             foreach($data as $k=>$v){
162:                 $trTpl = "<tr>
163:                 <td style='text-align:center;' scope='col'>{$v['id']}</td>
164:                 <td style='text-align:center;' scope='col'>{$v['keyword']}</td>
165:                 <td style='text-align:center;' scope='col'>{$v['relpy']}</td>
166:                 <td style='text-align:center;' scope='col'>{$v['type']}</td>
167:                 <td style='width:200px;text-align:center;' scope='col'>";
168: 
169:                 $trTpl .= '<input type="hidden" name="id" value="'.$v['id'].'" />';
170:                 $trTpl .= '<input name="submit_key" class="button" type="submit"  value="';
171:                 if($v['status']){
172:                     $trTpl .= '禁用';
173:                 }else{
174:                     $trTpl .= '启用';
175:                 }
176:                 $trTpl .= '" />';
177:                 $trTpl .=" | ";
178:                 $trTpl .= '<input name="submit_key" class="button" type="submit" value="删除" />';
179:                 $trTpl .= '|<span class="weixin_robot_mv button wobble-to-top-right">修改</span>';
180: 
181:                 $trTpl .= "</td></tr>";
182:                 echo '<form  method="POST">';
183:                 echo  $trTpl;
184:                 echo '</form>';
185:             }
186:         }else{
187:             echo '<tr>',
188:                 '<td class="wp_weixin_robot_table_head_td" style="color:#21759b;width:100px;text-align:center;" scope="col" colspan="4">没有设置keyword</td>',
189:                 '</tr>';
190:         }
191: 
192:         echo '</table>';
193: 
194:         echo '</div></div>';
195:         echo '<div><div>';
196:         echo '<form  method="POST">';
197:         echo '<table class="form-table">';
198:         echo '<tr><td></td></tr>';
199:         //数据开启数据记录
200:         echo '<tr  valign="top"><th scope="row">类型选择</th>';
201:         echo '<td>';
202:         echo '<select name="option[check]" id="method" />';
203:         
204:         echo '<option value="text" selected="selected">文本回复</option>';
205:         echo '<option value="id">图文ID回复</option>';
206:         echo '<option value="music">音乐回复</option>';
207:         echo '</select><p></p>';
208: 
209:         echo '<td></tr>',
210:             //keyword
211:             '<tr valign="top"><th scope="row">关键字</th>',
212:             '<td><textarea name="option[key]" style="width:350px;height:50px;" class="regular-text code"></textarea><br /></td></tr>',
213:             //replay
214:             '<tr valign="top"><th scope="row">回复信息</th>',
215:             '<td><textarea name="option[word]" style="width:350px;height:50px;" class="regular-text code"></textarea><br />',
216:             '<p>如果选择"图文ID"选项,应该填写文章ID: 1,4,8(图文最多显示10个信息)</p>',
217:             '<p>如果选择"文本回复"选项,可以是使用today(今日发布),n(1-10)最新信息, ',
218:             'h(1-10)热门信息, r(1-10)随机信息, ?(帮助信息)等内置命令!!!</p>',
219:             '<p>如果选择音乐回复,则填写如下格式:</p>',
220:             '<p style="color:red;">音乐名称|音乐描述|音乐地址</p>',
221:             '<p>不满足上面的话,则会返回文本信息</p>',
222:             '</td></tr>',
223:             '<input type="hidden" name="weixin_robot_keyword_relpy" value="true" /></table>',
224:             '<p style="margin-left:20px;" class="submit">',
225:             '<input name="submit_key" type="submit" class="button-primary" value="提交数据" />',
226:             '</p></form></div></div></div>';
227: 
228:         do_action('wx_admin_reply');
229: 
230:         do_action('weixin_midoks_push');
231:     }
232: 
233:     
234: }
235: ?>
236: 
API documentation generated by ApiGen