示例#1
0
 /**
  * 处理文本消息
  * 
  * @param SimpleXMLElement $postObj
  * @param boolean          $is_voice
  * @return response msg string
  */
 private function dealTextMsg($postObj, $is_voice = FALSE)
 {
     $fromUserName = $postObj->FromUserName;
     $toUserName = $postObj->ToUserName;
     $keyword = trim($postObj->Content);
     $openid = $fromUserName;
     $reqtime = intval($postObj->CreateTime);
     trace_debug('weixin_reply_' . ($is_voice ? 'voice' : 'text'), $keyword);
     $responseText = '';
     $queryResult = $this->helper->onTextQuery($keyword, $result_type);
     if (empty($queryResult)) {
         //没查找到任何可回复的信息
         $baidu_sou = $this->helper->sou($keyword);
         $contentText = "抱歉,没有找到你想要的东西!小蜜帮你<a href=\"{$baidu_sou}\">度娘一下</a>吧/::P";
         $responseText = self::packMsg(self::MSG_TYPE_TEXT, $fromUserName, $toUserName, array('content' => $contentText));
     } else {
         if ('string' == $result_type) {
             //一般文本
             $responseText = self::packMsg(self::MSG_TYPE_TEXT, $fromUserName, $toUserName, array('content' => $queryResult));
         } elseif ('arr_article' == $result_type) {
             //最新文章
             $item = '';
             foreach ($queryResult as $news) {
                 $extra = array();
                 $extra['title'] = $news['title'];
                 $extra['description'] = $news['digest'];
                 $extra['picUrl'] = $this->siteUrl . $news['thumb_media_url'];
                 $extra['url'] = $news['url'];
                 $item .= self::packMsg(self::MSG_TYPE_NEWS_ITEM, '', '', $extra);
             }
             $responseText = self::packMsg(self::MSG_TYPE_NEWS, $fromUserName, $toUserName, array('articleCount' => count($queryResult), 'articles' => $item));
         } elseif ('arr_goods' == $result_type) {
             //匹配搜索的商品
             $item = '';
             foreach ($queryResult as $goods) {
                 $extra = array();
                 $extra['title'] = $goods['goods_name'];
                 $extra['description'] = $goods['goods_name'];
                 $extra['picUrl'] = preg_match('/^http:\\/\\//', $goods['goods_thumb']) ? $goods['goods_thumb'] : Goods::goods_picurl($goods['goods_thumb']);
                 $extra['url'] = Goods::goods_url($goods['goods_id'], TRUE);
                 $item .= self::packMsg(self::MSG_TYPE_NEWS_ITEM, '', '', $extra);
             }
             $responseText = self::packMsg(self::MSG_TYPE_NEWS, $fromUserName, $toUserName, array('articleCount' => count($queryResult), 'articles' => $item));
         }
     }
     return $responseText;
 }