function weixin_robot_builtin_reply_page() { global $plugin_page, $wpdb; ?> <?php $weixin_builtin_replies = weixin_robot_get_builtin_replies(); ?> <?php if ($weixin_builtin_replies) { ?> <h3>插件或者扩展内置回复列表</h3> <table class="widefat" cellspacing="0"> <thead> <tr> <?php /*<th style="width:40px">ID</th>*/ ?> <th>关键字</th> <th>类型</th> <th>描述</th> <th>处理函数</th> </tr> </thead> <tbody> <?php $alternate = ''; ?> <?php foreach ($weixin_builtin_replies as $keyword => $weixin_builtin_reply) { $alternate = $alternate ? '' : 'alternate'; ?> <?php if ($weixin_builtin_reply['function'] != 'wpjam_weixin_emotions_reply') { ?> <tr class="<?php echo $alternate; ?> "> <td><?php echo $keyword; ?> </td> <td><?php if ($weixin_builtin_reply['type'] == 'full') { echo '完全匹配'; } else { echo '前缀匹配'; } ?> </td> <td><?php echo $weixin_builtin_reply['reply']; ?> </td> <td><?php echo $weixin_builtin_reply['function']; ?> </td> </tr> <?php } ?> <?php } ?> </tbody> </table> <?php } }
function weixin_robot_custom_keyword($false, $keyword) { global $wechatObj; if (empty($keyword) || strpos($keyword, '#') !== false) { echo ""; $wechatObj->set_response('need-manual'); return true; } elseif ($keyword == 'subscribe') { $weixin_openid = $wechatObj->get_fromUsername(); if ($weixin_openid) { $weixin_user = array('subscribe' => 1); weixin_robot_update_user($weixin_openid, $weixin_user); } } // 前缀匹配,只支持2个字 $prefix_keyword = mb_substr($keyword, 0, 2); $weixin_custom_keywords = weixin_robot_get_custom_keywords(); $weixin_custom_keywords_prefix = weixin_robot_get_custom_keywords('prefix'); if (isset($weixin_custom_keywords[$keyword])) { $weixin_custom_reply = $weixin_custom_keywords[$keyword]; } elseif (isset($weixin_custom_keywords_prefix[$prefix_keyword])) { $weixin_custom_reply = $weixin_custom_keywords_prefix[$prefix_keyword]; } else { $weixin_custom_reply = ''; } if ($weixin_custom_reply) { weixin_robot_custom_reply($weixin_custom_reply, $keyword); return true; } //内置回复 -- 完全匹配 $weixin_builtin_replies = weixin_robot_get_builtin_replies('full'); //内置回复 -- 前缀匹配 $weixin_builtin_replies_prefix = weixin_robot_get_builtin_replies('prefix'); if (isset($weixin_builtin_replies[$keyword])) { $weixin_reply_function = $weixin_builtin_replies[$keyword]['function']; } elseif (isset($weixin_builtin_replies_prefix[$prefix_keyword])) { $weixin_reply_function = $weixin_builtin_replies_prefix[$prefix_keyword]['function']; } if (isset($weixin_reply_function)) { call_user_func($weixin_reply_function, $keyword); return true; } if (weixin_robot_get_setting('weixin_disable_search')) { weixin_robot_not_found_reply($keyword); return true; } else { // 检测关键字是不是太长了 if (!weixin_robot_get_setting('weixin_3rd_search')) { $keyword_length = mb_strwidth(preg_replace('/[\\x00-\\x7F]/', '', $keyword), 'utf-8') + str_word_count($keyword) * 2; $weixin_keyword_allow_length = weixin_robot_get_setting('weixin_keyword_allow_length'); if ($keyword_length > $weixin_keyword_allow_length) { $weixin_keyword_too_long = weixin_robot_str_replace(weixin_robot_get_setting('weixin_keyword_too_long'), $wechatObj); if ($weixin_keyword_too_long) { echo sprintf($wechatObj->get_textTpl(), $weixin_keyword_too_long); } $wechatObj->set_response('too-long'); return true; } } } return $false; }