示例#1
0
 /**
  * 文本关键词查询事件
  *
  * @param string  $keyword     关键词
  * @param string  $result_type 输出返回结果类型: <br>
  *   'string'      : 一个纯字符串内容,默认<br>
  *   'arr_article' : 文章数组<br>
  *   'arr_goods'   : 商品数组<br><br>
  * @return string|array
  */
 public function onTextQuery($keyword, &$result_type = 'string')
 {
     if ('' == $keyword) {
         return '';
     }
     $result = '';
     $result_type = 'string';
     if (in_array($keyword, array('小蜜', '关于小蜜', '关于', '福小蜜'))) {
         $result = $this->about();
     } elseif (preg_match('/你|您/', $keyword) && preg_match('/是谁|干什么|做什么/', $keyword)) {
         $result = $this->about(2);
     } elseif (preg_match('/我/', $keyword) && preg_match('/是谁|干什么|做什么/', $keyword)) {
         $result = '你懂的!';
     } elseif (in_array($keyword, array('最新文章', '最新资讯', '文章', '资讯'))) {
         $result = $this->latestArticles();
         $result_type = 'arr_article';
     } elseif (preg_match('/百度|度娘/', $keyword)) {
         $result = '这是她的地址:<a href="http://www.baidu.com">www.baidu.com</a>';
     } elseif (preg_match('/错了|不喜欢|不好玩|不感兴趣|不爱|无用|干扰|骚扰/', $keyword)) {
         $result = '不好意思/::~';
     } elseif (preg_match('/喜欢|很好|感兴趣|大爱|太棒|真棒|棒极|哇塞|不错|太酷|忒酷|真酷/', $keyword)) {
         $result = '谢谢/::$';
     } elseif (preg_match('/无聊|干什么|什么干|做什么|什么做|什么好做|什么好干/', $keyword)) {
         $poems = ["终日昏昏醉梦间,\n忽闻春尽强登山。\n因过竹院逢僧话,\n偷得浮生半日闲。", "黄梅时节家家雨,\n青草池塘处处蛙。\n有约不来过夜半,\n闲敲棋子落灯花。", "无聊夜里无聊梦,\n心语无聊冷若冰。\n叹写无聊抒郁事,\n无聊目送月零丁。", "一别之后,\n两地相悬,\n只说是三四月,\n又谁知五六年。\n七弦琴无心弹,\n八行书不可传,\n九连环从中折断,\n十里长亭望眼欲穿,\n百思想,千系念,万般无奈把郎怨。\n万语千言说不完,百无聊赖十倚栏,\n重九登高看孤雁,\n八月中秋月圆人不圆,\n七月半烧香秉烛问苍天,\n 六月伏天人人摇扇我心寒,\n 五月石榴如火,偏遇阵阵冷雨浇花端;\n四月枇杷未黄,我欲对镜心意乱。\n急匆匆,三月桃花随水转;\n飘零零,二月风筝线儿断。", "智者乐山山如画,\n仁者乐水水无涯。\n从从容容一杯酒,\n平平淡淡一杯茶。\n\n细雨朦胧小石桥,\n春风荡漾小竹筏。\n夜无明月花独舞,\n腹有诗书气自华。", "浮名浮利,虚苦劳神。\n叹隙中驹,石中火,梦中身。\n几时归去,作个闲人。\n\n网事已成空,还如一梦中。\n相见争如不见,有情还是无情。\n今朝有酒今朝醉,管他对错是与非。"];
         $rand_idx = mt_rand(0, 100000);
         $rand_idx = $rand_idx % count($poems);
         $result = $poems[$rand_idx];
         $baidu_sou = $this->sou($keyword);
         $result .= "\n\n还不解聊?去调戏度娘吧:“度娘,<a href=\"{$baidu_sou}\">{$keyword}</a>”";
     } elseif (preg_match('/有什么/', $keyword)) {
         $result = Goods::getGoodsList('', 'latest');
         if (empty($result)) {
             return '';
         }
         $result_type = 'arr_goods';
     } elseif (preg_match('/商城/', $keyword)) {
         $result = "请访问: <a href=\"http://m.fxmgou.com/\">小蜜商城</a>";
     } elseif (preg_match('/订单/', $keyword)) {
         $result = "请访问: <a href=\"http://m.fxmgou.com/trade/order/record\">我的订单</a>";
     } elseif (preg_match('/收藏/', $keyword)) {
         $result = "请访问: <a href=\"http://m.fxmgou.com/user/collect\">我的收藏</a>";
     } elseif (preg_match('/反馈/', $keyword)) {
         $result = "请访问: <a href=\"http://m.fxmgou.com/user/feedback\">我要反馈</a>";
     } elseif (preg_match('/^http(s)?:\\/\\//i', $keyword)) {
         $result = "请访问: <a href=\"{$keyword}\">{$keyword}</a>";
     } elseif (in_array($keyword, array('?', '?', '阿', '啊', '在', '在?', '在?', '哈哈', '呵呵', '哈', '呵', '哼')) || is_numeric($keyword) || preg_match("!^/:!", $keyword) || preg_match("/(在吗|你好|您好|哈哈|呵呵|哈|呵|哼|hi|hello|hallo)/i", $keyword)) {
         $result = $this->defaultHello();
     } else {
         //查询数据库
         $result = Goods::search($keyword, 10);
         if (empty($result)) {
             return '';
         }
         $result_type = 'arr_goods';
     }
     return $result;
 }