<?php require_once __DIR__ . "/BaiduMapClient.php"; $api_key = "0e4fde2b4acbc043abdb68df511359ae"; // initialize client object $api = new BaiduMapClient($api_key); $api->place_search("百度大厦", "39.915,116.404", "2000"); $api->geocoder_address("百度大厦"); $api->geocoder_location("39.915,116.404,39.975,116.414");
public function responseMsg() { //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data if (!empty($postStr)) { $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $msgType = $postObj->MsgType; if ($msgType == "text") { $keyword = trim($postObj->Content); $time = time(); $textTpl = "<xml>\n\t\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t\t\t</xml>"; if (!empty($keyword)) { $api_key = "SEwcXuDQE7ZcGM0Fxz2B02zb"; // initialize client object $api = new BaiduTranslateClient($api_key); $result = $api->translate($keyword, "auto", "auto"); $contentStr = "Translation Failed!"; if (!empty($result->trans_result)) { if (count($result->trans_result) > 0) { $contentStr = $result->trans_result[0]->dst; } } $msgType = "text"; //$contentStr = "Hi, I'm Mars Robot! 有何贵干? 你可以发送位置,试试看。"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } else { echo "Input something..."; } } else { if ($msgType == "location") { $location_x = $postObj->Location_X; $location_y = $postObj->Location_Y; $scale = $postObj->Scale; $label = $postObj->Label; $time = time(); $textTpl = "<xml>\n\t\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t\t\t</xml>"; $api_key = "0e4fde2b4acbc043abdb68df511359ae"; // initialize client object $api = new BaiduMapClient($api_key); $result = $api->geocoder_location($location_x . "," . $location_y); if (!empty($result)) { $msgType = "text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $label . $result); echo $resultStr; } } else { if ($msgType == "image") { $url = $postObj->PicUrl; $time = time(); $api_key = "e336859e1099669c6662a3ca76c590b8"; $api_secret = "HcMo_lQFQ4RZ1qrijxjjnzoHeNjxMc18"; // initialize client object $api = new FacePPClient($api_key, $api_secret); $person_name = md5(time() . rand()); //$file_name = $this->getFileByWget($url, $person_name . ".jpg"); $ret = $this->downloadImage($url, "/home/clasix/sites/weixin/images/" . $person_name); if (!$ret) { $textTpl = "<xml>\n\t\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t\t\t</xml>"; $msgType = "text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, "File Download Failed!"); echo $resultStr; } else { // // do search by url_img $group = "sample_group"; $face_ids = array(); detect($api, $person_name, $face_ids); $result = recognize($api, $person_name, $group); if (!empty($result)) { $textTpl = "<xml>\n\t\t\t\t\t\t\t\t\t <ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t\t\t\t <FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t\t\t\t <CreateTime>%s</CreateTime>\n\t\t\t\t\t\t\t\t\t <MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t\t\t\t <Content><![CDATA[]]></Content>\n\t\t\t\t\t\t\t\t\t <ArticleCount>1</ArticleCount>\n\t\t\t\t\t\t\t\t\t <Articles>\n\t\t\t\t\t\t\t\t\t <item>\n\t\t\t\t\t\t\t\t\t <Title><![CDATA[Similar Pic]]></Title>\n\t\t\t\t\t\t\t\t\t <Description><![CDATA[nothing]]></Description>\n\t\t\t\t\t\t\t\t\t <PicUrl><![CDATA[%s]]></PicUrl>\n\t\t\t\t\t\t\t\t\t <Url><![CDATA[%s]]></Url>\n\t\t\t\t\t\t\t\t\t </item>\n\t\t\t\t\t\t\t\t\t </Articles>\n\t\t\t\t\t\t\t\t\t <FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t\t\t\t </xml>"; $msgType = "news"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, getWeiXinUrl($result), getWeiXinUrl($result)); echo $resultStr; } else { $textTpl = "<xml>\n\t\t\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t\t\t\t</xml>"; $msgType = "text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, "No Similar Pictures"); echo $resultStr; } // do train job $api->group_add_person($person_name, $group); train($api, $group); } } else { echo ""; exit; } } } } else { echo ""; exit; } }