完整的程序,屏蔽掉多图文部分是能用的
<?php
define("TOKEN","weixin");
$signature=$_GET['signature'];
$timestamp=$_GET['timestamp'];
$nonce=$_GET['nonce'];
$echostr=$_GET['echostr'];
$tmpArr=array(TOKEN,$timestamp,$nonce);
sort($tmpArr,SORT_STRING);
$tmpstr=implode($tmpArr);
$tmpstr=sha1($tmpstr);
if($tmpstr==$signature)
{
header('content-type:text');
echo $echostr;
//echo 为直接输出
}
else
{
echo "Error";
}
$postData=$HTTP_RAW_POST_DATA;
//echo "嗯呢1";
//2.将xml字符串转化成一个对象(处理xml数据包)
$xmlObj=simplexml_load_string($postData,"SimpleXMLElement",LIBXML_NOCDATA);
$touserName=$xmlObj->ToUserName;
//获取开发者微信号
$fromuserName=$xmlObj->FromUserName; //获取用户openid
$msgtype=$xmlObj->MsgType;
//消息的类型text
/*switch($msgtype)
{
//判断消息类型
case'text':*/
$content=trim($xmlObj->Content); //获取文本消息内容
// echo "嗯呢";
switch($content)
{
case'单图文':
$replyNewsMsg="<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
//news为图文消息意思
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<PicUrl><![CDATA[%s]]></PicUrl>
<Url><![CDATA[%s]></Url>
</item>
</Articles>
</xml>";
$title="是妹子吗";
$description="是就回复一下";
$picurl="http://jhbdeserves-img.stor.
$url="https://www.google.co.jp/search?q=%E5%A6%B9%E5%AD%90&safe=strict&biw=1366&bih=643&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjDq8nHjI_PAhUBnJQKHVTEDk8Q_AUIBigB#safe=strict&tbm=isch&q=%E6%9F%B3%E5%B2%A9";
echo sprintf($replyNewsMsg,$fromuserName,$touserName,time(),$title,$description,$picurl,$url);
break;
/*这里*****
case'多图文':
$newsArr=array(
array('Title'->"约吗?",
'Description'->"等你哦",
'PicUrl'->"http://jhbdeserves-img.stor.,
'Url'->"https://www.
)
array('Title'->"约吗?",
'Description'->"等你哦",
'PicUrl'->"http://jhbdeserves-img.stor.,
'Url'->"https://www.
)
);
foreach(
$newsArr as $item)
{
$itemtmpl="<item>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<PicUrl><![CDATA[%s]]></PicUrl>
<Url><![CDATA[%s]></Url>
</item>";
$itemstr .=sprintf($itemtmpl,$item['Title'],$item['Description'],$item['PicUrl'],$item['Url']);
}
$replyNewsMsg="<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
//news为图文消息意思
<ArticleCount>2</ArticleCount>
<Articles>".$itemstr."</Articles>
</xml>";
echo sprintf($replyNewsMsg,$fromuserName,$touserName,time());
break;
*/
default:
break;
}
?>