예제 #1
0
 public static function instance($service, $key = null)
 {
     if (!isset(self::$_instances[$service])) {
         if (!in_array($service, self::$_services)) {
             throw new InvalidArgumentException('Service: ' . $service . ' not exists!');
         }
         self::$_instances[$service] = new static($service);
     }
     self::$_key = $key;
     return self::$_instances[$service];
 }
예제 #2
0
<?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");
예제 #3
0
파일: query.php 프로젝트: amlun/geocoding
<?php

require 'workflow.php';
require 'functions.php';
require 'BaiduMapClient.php';
isset($argv[1]) && ($query = trim($argv[1]));
$workflow = new Workflows();
$baidu_map_api_key = $workflow->read(BaiduMapClient::APIKEY);
$place_client = BaiduMapClient::instance('geocoder', $baidu_map_api_key);
// 'EBfee57431c42ec5925b2e9e32c5313b'
try {
    if (is_geo($query)) {
        $params['location'] = $query;
    } else {
        $params['address'] = $query;
    }
    $result = $place_client->default($params);
    if (!$result || $result['status'] != 0) {
        $workflow->result($result['status'], '找不到地址!', $result['message'], '找不到相应的地址,请重试!', 'icon/baidu.png');
    } else {
        $result = $result['result'];
        if (isset($result['business']) && $result['formatted_address'] && isset($result['addressComponent'])) {
            $workflow->result($query, $result['business'], $result['formatted_address'], $query, 'icon/baidu.png');
            foreach ($result['addressComponent'] as $key => $value) {
                if (empty($value)) {
                    continue;
                }
                $workflow->result($key . ':' . $value, $value, $value, $key, 'icon/baidu.png');
            }
        } elseif (isset($result['location'])) {
            $latlng = $result['location']['lat'] . ',' . $result['location']['lng'];
예제 #4
0
 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;
     }
 }