Exemplo n.º 1
0
 public function respond()
 {
     global $_W;
     //是否初次进入会话
     if (!$this->inContext) {
         $content = $this->message['content'];
         //记录搜索关键字
         $_SESSION['src'] = str_replace('附近', '', $content);
         if ('' == $_SESSION['src']) {
             return $this->respText('请正确发送您的请求:附近+‘搜索内容’,如附近饭店');
         }
         $this->beginContext();
         return $this->respText('点击下方的“+”,发送您的地理位置。然后我们会将您要的结果反馈给您的!');
     } else {
         $srckey = $_SESSION['src'];
         $msgtp = $this->message['type'];
         if ('location' == $msgtp) {
             $x = $this->message['location_x'];
             $y = $this->message['location_y'];
             $_SESSION['x'] = $x;
             $_SESSION['y'] = $y;
             $srcArr = catchEntitiesFromLocation($srckey, $x, $y, 2000);
             $array = json_decode($srcArr, true);
             $map = array();
             foreach ($srcArr as $key => $vo) {
                 $map[] = array('title' => $vo['title'], 'description' => $key, 'picurl' => $_W['siteroot'] . '/source/modules/fujin/template/homelogo.jpg', 'url' => $vo['url']);
             }
             //结束会话
             $this->endContext();
             return $this->respNews($map);
         } elseif ('text' == $msgtp) {
             $content = $this->message['content'];
             if (strpos($content, '附近') !== false) {
                 $_SESSION['src'] = str_replace('附近', '', $content);
                 $msg = '点击下方的“+”,发送您的地理位置。然后我们会将您要的结果反馈给您的!';
             } else {
                 $this->endContext();
                 $msg = '请正确发送您的要求!';
             }
             return $this->respText($msg);
         } else {
             $this->endContext();
             return $this->respText('请正确发送您的要求!');
         }
     }
 }
Exemplo n.º 2
0
 private function receiveText($object)
 {
     $keyword = trim($object->Content);
     $category = substr($keyword, 0, 6);
     $entity = trim(substr($keyword, 6, strlen($keyword)));
     switch ($category) {
         case "附近":
             include "location.php";
             $location = getLocation($object->FromUserName);
             if (is_array($location)) {
                 include "mapbaidu.php";
                 //$content = count($location);
                 $content = catchEntitiesFromLocation($entity, $location["locationX"], $location["locationY"], "5000");
             } else {
                 $content = $location;
             }
             break;
         default:
             $content = $object->FromUserName;
             break;
     }
     if (is_array($content)) {
         $result = $this->transmitNews($object, $content);
     } else {
         $result = $this->transmitText($object, $content);
     }
     return $result;
 }
Exemplo n.º 3
0
<?php

define("DEBUG_MODE", false);
$k = htmlspecialchars($_GET['keyword']);
$x = htmlspecialchars($_GET['x']);
$y = htmlspecialchars($_GET['y']);
//VAR_dump($_GET);
$searchArray = catchEntitiesFromLocation($k, $x, $y, 2000);
echo json_encode($searchArray);
// $searchArray = catchEntitiesFromLocation("gh_3c1a25652daa", "银行", 39.915, 116.404, 2000);
// var_dump( $searchArray);
function catchEntitiesFromLocation($entity, $x, $y, $radius)
{
    $mapObj = new baiduMapClient();
    $search = $mapObj->Place_search($entity, $x . "," . $y, $radius);
    $results = $search->results;
    for ($i = 0; $i < count($results); $i++) {
        $distance = getDistance_map($x, $y, $results[$i]->location->lat, $results[$i]->location->lng);
        $shopSortArrays[$distance] = array("Title" => $results[$i]->name . " 【距离你】" . $distance . "米 【地址】" . $results[$i]->address . (isset($results[$i]->telephone) ? " " . $results[$i]->telephone : ""), "Description" => "{$results[$i]->address}", "Url" => "{$results[$i]->detail_url}");
    }
    ksort($shopSortArrays);
    //排序
    $shopArray = array();
    foreach ($shopSortArrays as $key => $value) {
        $shopArray[] = array("title" => $value["Title"], "key" => $key, 'pic' => '', "url" => $value["Url"]);
        if (count($shopArray) > 9) {
            break;
        }
    }
    return $shopArray;
}