•Sina App Engine(以下简称SAE)是新浪研发中心于2009年8月开始内部开发,并在2009年11月3日正式推出第一个Alpha版本的国内首个公有云计算平台,SAE是新浪云计算战略的核心组成部分。
我们先申请一个账号:直接访问http://sae.sina.com.cn
注册成功后,我们就可以进入管理系统
选择创建SAE
这里选择PHP的,也可以选用其它语言哦
创建成功后,我们可以看见两个版本控制系统哦,因为我比较熟悉SVN,所以就下载了TortoiseSVN
提供下载官网和网盘:
官网:http://tortoisesvn.net/downloads.html
网盘:http://www.kuaipan.cn/file/id_8825968814858609.html
注意要创建一个版本号哦
然后选择上传代码包,提供微信接口代码
<?php
/**
* wechat php test
*/
//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
//valid signature , option
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
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;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";
if(!empty( $keyword ))
{
$msgType = "text";
$contentStr = "Welcome to wechat world!";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}else{
echo "Input something...";
}
}else {
echo "";
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;
}
}
}
?>
注意要采用专业的软件,设置编码为UTF-8,同时压缩为zip的文件,才可以上传哦,不用使用记事本哦
上传成功的话,点击编辑代码,是可以看到我们的代码的哦
打开那个链接:可以看到我们搭建的网页哦