Created
January 15, 2014 13:07
-
-
Save ety001/8435870 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*------------------------------------------------- | |
| index.php [ 微信公众平台接口 ] | |
+-------------------------------------------------- | |
| Author: LinYunpeng <QQ:50663950> | |
+------------------------------------------------*/ | |
$wechatObj = new wechat(); | |
$wechatObj->responseMsg(); | |
class wechat { | |
public function responseMsg() { | |
//---------- 接 收 数 据 ---------- // | |
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //获取POST数据 | |
//用SimpleXML解析POST过来的XML数据 | |
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); | |
$fromUsername = $postObj->FromUserName; //获取发送方帐号(OpenID) | |
$toUsername = $postObj->ToUserName; //获取接收方账号 | |
$keyword = trim($postObj->Content); //获取消息内容 | |
$time = time(); //获取当前时间戳 | |
//判断$keyword中是否含有关键字cj | |
if(判断方法用正则表达式匹配){ | |
//没有cj,把$postStr这个变量post到http://wxapi.v5kf.com/public/weixin?site_id=10794 | |
/*这里自己想办法完善post代码*/ | |
//不要忘记return | |
return; | |
} | |
//下面是有cj的情况 | |
/*从$keyword中获取出学号和密码,并查成绩,把成绩处理成字符串存入一个变量,即最后要返回的内容,$contentStr.*/ | |
//---------- 返 回 数 据 ---------- // | |
//返回消息模板 | |
$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>"; | |
$msgType = "text"; //消息类型 | |
//格式化消息模板 | |
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); | |
echo $resultStr; //输出结果 | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment