- //回复文本
- function responseTextMsg($funcFlag = 0,$content){
- $postStr = $GLOBALS["HTTP_RAW_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();
- $text = "
- ".$fromUsername."
- ".$toUsername."
- ".$time."
- text
- ".$content."
- ".$funcFlag."
- "; //格式化回复文本
- echo $text;
- }
- return 0;
- }
- //回复图文
- function responseNewsMsg($funcFlag = 0,$contentArray){
- $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
- if (!empty($postStr)){
- $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- $fromUsername = $postObj->FromUserName;
- $toUsername = $postObj->ToUserName;
- $time = time();
- $articleCount = count($contentArray);
- $news = "";
- $news .= "
- ".$fromUsername."
- ".$toUsername."
- ".$time."
- news
- ".$articleCount."
- ";
- $i = 0;
- while($i < $articleCount){
- $news .= "
- ". $contentArray[$i]["description"]."
- ". $contentArray[$i]["picUrl"]."
- ". (count($contentArray[$i]) == 4 ? $contentArray[$i]["url"]:OpenSite)."
- ";
- $i++;
- }
- $news .= "
- ".$funcFlag."
- ";
- echo $news;
- }
- return 0;
- }
以后每次回复图文消息就可以直接构造数组发送了,例:
- $arrayCon = array(array("title"=>"图文消息标题1",
- "description"=>"图文消息描述1",
- "picUrl"=>"图片链接1","url"=>"点击图文消息跳转链接1"),
array("title"=>"图文消息标题2", - "description"=>"图文消息描述2",
- "picUrl"=>"图片链接2",
- "url"=>"点击图文消息跳转链接2"));
- responseNewsMsg(0,$arrayCon);