php localtion,indexlocaltion.php

/*

方倍工作室

CopyRight 2013 All Rights Reserved

*/

define("TOKEN", "weixin");

$wechatObj = new wechatCallbackapiTest();

if (!isset($_GET['echostr'])) {

$wechatObj->responseMsg();

}else{

$wechatObj->valid();

}

class wechatCallbackapiTest

{

public function valid()

{

$echoStr = $_GET["echostr"];

if($this->checkSignature()){

echo $echoStr;

exit;

}

}

private function checkSignature()

{

$signature = $_GET["signature"];

$timestamp = $_GET["timestamp"];

$nonce = $_GET["nonce"];

$token = TOKEN;

$tmpArr = array($token, $timestamp, $nonce);

sort($tmpArr);

$tmpStr = implode($tmpArr);

$tmpStr = sha1($tmpStr);

if($tmpStr == $signature){

return true;

}else{

return false;

}

}

public function responseMsg()

{

$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

if (!empty($postStr)){

$this->logger("R ".$postStr);

$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

$RX_TYPE = trim($postObj->MsgType);

switch ($RX_TYPE)

{

case "event":

$result = $this->receiveEvent($postObj);

break;

case "text":

$result = $this->receiveText($postObj);

break;

case "location":

$result = $this->receiveLocation($postObj);

break;

}

$this->logger("T ".$result);

echo $result;

}else {

echo "";

exit;

}

}

private function receiveEvent($object)

{

$content = "";

switch ($object->Event)

{

case "subscribe":

$content = "欢迎关注方倍工作室 ";

break;

case "unsubscribe":

$content = "取消关注";

break;

}

$result = $this->transmitText($object, $content);

return $result;

}

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;

}

/*

* 接收位置消息

*/

private function receiveLocation($object)

{

include("location.php");

$content = setLocation($object->FromUserName,(string)$object->Location_X, (string)$object->Location_Y);

$result = $this->transmitText($object, $content);

return $result;

}

private function transmitText($object, $content)

{

$textTpl = "

%s

";

$result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content);

return $result;

}

private function transmitNews($object, $arr_item)

{

if(!is_array($arr_item))

return;

$itemTpl = "

";

$item_str = "";

foreach ($arr_item as $item)

$item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);

$newsTpl = "

%s

%s

$item_str

";

$result = sprintf($newsTpl, $object->FromUserName, $object->ToUserName, time(), count($arr_item));

return $result;

}

private function logger($log_content)

{

if(isset($_SERVER['HTTP_BAE_ENV_APPID'])){ //BAE

require_once "BaeLog.class.php";

$logger = BaeLog::getInstance();

$logger ->logDebug($log_content);

}else if(isset($_SERVER['HTTP_APPNAME'])){ //SAE

sae_set_display_errors(false);

sae_debug($log_content);

sae_set_display_errors(true);

}else if($_SERVER['REMOTE_ADDR'] != "127.0.0.1"){ //LOCAL

$max_size = 10000;

$log_filename = "log.xml";

if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}

file_put_contents($log_filename, date('H:i:s')." ".$log_content."\r\n", FILE_APPEND);

}

}

}

?>

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值