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;
$type = $postObj->MsgType;
$customrevent = $postObj->Event;
$latitude  = $postObj->Location_X;
$longitude = $postObj->Location_Y;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content>%s</Content>
<FuncFlag>0</FuncFlag>
</xml>";      

require_once ('BaeMemcache.class.php');//首先开启百度bae缓存,大小任意,10M即可
$mem=new BaeMemcache;//实例化
if($keyword=="天气"){
$mem->set($fromUsername."key",$fromUsername."天气",$flag=0,$expire=60);//设置缓存变量$$fromUsername."key",60s后过期
  
$contentStr="请输入地区,如北京进行天气情况查询";
}
else{
$struser=$mem->get($fromUsername."key");//获取缓存值
  

if ($struser==$fromUsername."天气"){//判断是否同一用户发送以及是否发送过天气
$weatherurl="http://api.map.baidu.com/telematics/v2/weather?location={$keyword}&ak=1a3cde429f38434f1811a75e1a90310c";
$apistr=file_get_contents($weatherurl);
$apiobj=simplexml_load_string($apistr);
$placeobj=$apiobj->currentCity;//读取城市
$todayobj=$apiobj->results->result[0]->date;//读取星期
$weatherobj=$apiobj->results->result[0]->weather;//读取天气
$windobj=$apiobj->results->result[0]->wind;//读取风力
$temobj=$apiobj->results->result[0]->temperature;//读取温度
$contentStr = "{$placeobj}{$todayobj}天气{$weatherobj},风力{$windobj},温度{$temobj}";
if ($contentStr=="天气,风力,温度")
{$contentStr="你输入的地区有误";}
}else{
$contentStr="请先输入天气";
}
}				               
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time,$contentStr);
echo $resultStr;
  
    }

	}	
示例#2
0
function sp_set_dynamic_config($data)
{
    if (sp_is_sae()) {
        $kv = new SaeKV();
        $ret = $kv->init();
        $configs = $kv->get("THINKCMF_DYNAMIC_CONFIG");
        $configs = empty($configs) ? array() : unserialize($configs);
        $configs = array_merge($configs, $data);
        $result = $kv->set('THINKCMF_DYNAMIC_CONFIG', serialize($configs));
    } elseif (defined('IS_BAE') && IS_BAE) {
        $bae_mc = new BaeMemcache();
        $configs = $bae_mc->get("THINKCMF_DYNAMIC_CONFIG");
        $configs = empty($configs) ? array() : unserialize($configs);
        $configs = array_merge($configs, $data);
        $result = $bae_mc->set("THINKCMF_DYNAMIC_CONFIG", serialize($configs), MEMCACHE_COMPRESSED, 0);
    } else {
        $config_file = "./data/conf/config.php";
        if (file_exists($config_file)) {
            $configs = (include $config_file);
        } else {
            $configs = array();
        }
        $configs = array_merge($configs, $data);
        $result = file_put_contents($config_file, "<?php\treturn " . var_export($configs, true) . ";?>");
    }
    sp_clear_cache();
    return $result;
}
示例#3
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;
$type = $postObj->MsgType;
$customrevent = $postObj->Event;
$latitude  = $postObj->Location_X;
$longitude = $postObj->Location_Y;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content>%s</Content>
<FuncFlag>0</FuncFlag>
</xml>";      

require_once ('BaeMemcache.class.php');//首先开启百度bae缓存,大小任意,10M即可
$mem=new BaeMemcache;//实例化

				if ($keyword=="秒杀")
				 {
				 $timeint=strtotime("2013-07-06 21:00:00")-time();
				  if($timeint>0)
				    {
					$contentStr = "对不起,秒杀还没开始,2013年7月6日21点开始";
				    }
				  else
				  {
					$struser=$mem->get($fromUsername."key");//获取缓存值	
								 
						 if ($struser=="2")
						 {
						 $contentStr = "你已经秒杀过了!";
						 }
						 else
						 {
						 $mem->set($fromUsername."key","2",$flag=0,$expire=0);//设置缓存变量$fromUsername.key
						$prize=$mem->get(prize);//获取缓存	
						$type=gettype($prize);
						if ($type=="boolean")
						   {$prize=2;}//第一个人秒杀时设置奖品个数
						$prize=intval($prize);//转为整型	
							if ($prize>0)
							 {
							 $contentStr = "恭喜你秒杀成功,凭此条微信到本店换取礼品";
							 $prize--;//奖品减一
							 $mem->set(prize,$prize,$flag=0,$expire=0);//更新缓存
							  }
							else
							{
							$contentStr = "很遗憾,你没有秒杀成功,下次再来吧!";
							}
						}//72	
				    }//64
					}//57
				$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time,  $contentStr);
               echo $resultStr;
    }

	}	
示例#4
0
<?php

$bae_mc = new BaeMemcache();
$runtime_config = $bae_mc->get("XIAOCAOCMS_DYNAMIC_CONFIG");
$runtime_config = $runtime_config ? unserialize($runtime_config) : array();
//BAE下固定mysql配置
$bae = array('DB_TYPE' => 'mysql', 'DB_DEPLOY_TYPE' => 1, 'DB_RW_SEPARATE' => true, 'DB_HOST' => HTTP_BAE_ENV_ADDR_SQL_IP, 'DB_NAME' => '', 'DB_USER' => HTTP_BAE_ENV_AK, 'DB_PWD' => HTTP_BAE_ENV_SK, 'DB_PORT' => HTTP_BAE_ENV_ADDR_SQL_PORT, 'TMPL_PARSE_STRING' => array('__UPLOAD__' => file_domain('data') . '/upload/'));
return array_merge($bae, $runtime_config);
示例#5
0
 static function queueGet($name)
 {
     if (isset(self::$_cache[$name])) {
         return self::$_cache[$name];
     }
     $h = new BaeMemcache();
     $r = $h->get($name);
     if (false === $r) {
         return false;
     }
     self::$_cache[$name] = $r;
     return $r;
 }
示例#6
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;
$type = $postObj->MsgType;
$customrevent = $postObj->Event;
$latitude  = $postObj->Location_X;
$longitude = $postObj->Location_Y;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content>%s</Content>
<FuncFlag>0</FuncFlag>
</xml>";      

require_once ('BaeMemcache.class.php');//首先开启百度bae缓存,大小任意,10M即可
$mem=new BaeMemcache;//实例化
$struser=$mem->get($fromUsername."key");//获取缓存值
 if (empty($struser))
 {
	if($keyword=="2"){
	$mem->set($fromUsername."key",$fromUsername."2",$flag=0,$expire=0);//设置缓存变量$$fromUsername."key"
	  
	$contentStr="开始和小黄鸡对话#退出";
	}//55
elseif($keyword=="1"){
$jokeurl="http://api.94qing.com/?type=joke&msg=";//笑话API
                $contentStr=file_get_contents($jokeurl);
				$contentStr = str_replace("\n","",$contentStr);}

		else{
		$contentStr="输入1看笑话,2和小黄鸡聊天";
		}
   }//54

else{
 if ($keyword=="#")
   {$contentStr="已退出聊天,输入1看笑话,2和小黄鸡聊天";
  $struser=$mem->delete($fromUsername."key");//删除缓存
   }
 else{
   if ($struser==$fromUsername."2"){//判断是否同一用户发送以及是否发送小黄鸡
     $simurl="http://sandbox.api.simsimi.com/request.p?key=966ee8bb-dc33-48ec-9006-ae45e11a4151&lc=ch&text='{$keyword}'";//小黄鸡地址
                $simstr=file_get_contents($simurl);//读入文件
				$simjson=json_decode($simstr);//json解析
     			$contentStr = $simjson->response;//读取小黄鸡回复内容
    
               }//76
			   }//75
}//70


  
 

				               
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time,$contentStr);
echo $resultStr;
  
    }

	}	
示例#7
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;
$type = $postObj->MsgType;
$customrevent = $postObj->Event;
$latitude  = $postObj->Location_X;
$longitude = $postObj->Location_Y;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";             
require_once ('BaeMemcache.class.php');//首先开启百度bae缓
$mem=new BaeMemcache;//实例化
$dbname = 'SnXAHxsmUPuRqZkaWnjF';
$host = getenv('HTTP_BAE_ENV_ADDR_SQL_IP');
$port = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT');
$user = getenv('HTTP_BAE_ENV_AK');
$pwd = getenv('HTTP_BAE_ENV_SK');
$link = @mysql_connect("{$host}:{$port}",$user,$pwd,true);
if(!$link) {
die("Connect Server Failed: " . mysql_error($link));
}
if(!mysql_select_db($dbname,$link)) {
die("Select Database Failed: " . mysql_error($link));
}
if ($keyword=="笑话")
{//80

$sql = "SELECT * FROM `BD` WHERE  `user` =  '{$fromUsername}' ";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
$name= $rs['user'];
if($name==$fromUsername)
{				
$jokeurl="http://api.94qing.com/?type=joke&msg=";//笑话API
$contentStr=file_get_contents($jokeurl);
$contentStr = str_replace("\n","",$contentStr);
}//读入文件						
else
{$contentStr="请先绑定qq,输入qq号进行绑定。";

$mem->set($fromUsername."key","qq",$flag=0,$expire=0);//设置缓存变
}			
}//51		
else{
$struser=$mem->get($fromUsername."key");//获取缓存值

if($struser=="qq")
{
$sql = "SELECT * FROM `BD` WHERE  `qq` =  '{$keyword}' ";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
$qq= $rs['qq'];

if($qq==$keyword)
{$contentStr="绑定成功。";
$sql="UPDATE `BD` SET `user`='{$fromUsername}' WHERE `qq` =  '{$keyword}'";
mysql_query($sql);
$struser=$mem->delete($fromUsername."key");//删除缓存
}
else
{$contentStr="qq号错误,和管理员联系。";}
}//84
else {$contentStr="未绑定qq,无法操作,输入qq号";}

}//81		
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $contentStr);
echo $resultStr;



}
}
示例#8
0
<?php

require_once './BaeMemcache.class.php';
/*Cache配置信息,可查询Cache详情页*/
$cacheid = 'xxx';
$host = 'cache.duapp.com';
$port = '20243';
$user = '******';
$pwd = 'xxx';
$mem = new BaeMemcache($cacheid, $host . ': ' . $port, $user, $pwd);
$mem->set("key", "value");
if (!empty($mem)) {
    echo $mem->get("key");
} else {
    echo "error";
}
示例#9
0
<?php

$bae_mc = new BaeMemcache();
$runtime_config = $bae_mc->get("THINKCMF_DYNAMIC_CONFIG");
$runtime_config = $runtime_config ? unserialize($runtime_config) : array();
//BAE下固定mysql配置
$bae = array('DB_TYPE' => 'mysql', 'DB_DEPLOY_TYPE' => 1, 'DB_RW_SEPARATE' => true, 'DB_HOST' => HTTP_BAE_ENV_ADDR_SQL_IP, 'DB_NAME' => '', 'DB_USER' => HTTP_BAE_ENV_AK, 'DB_PWD' => HTTP_BAE_ENV_SK, 'DB_PORT' => HTTP_BAE_ENV_ADDR_SQL_PORT, 'TMPL_PARSE_STRING' => array('__UPLOAD__' => file_domain('data') . '/upload/'));
return array_merge($bae, $runtime_config);