function switchFunc(WeChat $object, $keyword) { $matches = explode("@", $keyword); $key = $matches[0]; $value = $matches[1]; switch ($key) { case "翻译": $content = wm_translate($value); $object->sendText($content); break; case "天气": $content = wm_weather($value); if (!is_array($content)) { $object->sendText($content); } else { foreach ($content as $v) { $object->addNews($v['title'], "", "", $v['pic']); } $object->sendNews(); } break; case "搜索": $articles = query("", $value); if (empty($articles)) { $object->sendText("没有找到相关文章"); } else { foreach ($articles as $v) { $object->addNews($v['0'], $v['1'], $v['2'], $v['3']); } $object->sendNews(); } break; default: $object->addNews(WM_ERROR_MESSAGE, "", "", ""); $object->addNews(WM_MESSAGE, "", "", ""); $object->sendNews(); break; } }