微信开发二之关键字回复

来源:互联网 发布:照片说话软件 编辑:程序博客网 时间:2024/05/01 08:02

1、(文字消息)

switch ($keyword){case '1':$contentStr = "您输入为1:联系";break;case '2':$contentStr = "您输入为2:加群";break;case '3':$contentStr = "您输入为3:订购";break;default:$contentStr = "请输入1、2、3获取信息";break;}              $msgType = "text";                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                echo $resultStr;

2、(图片消息)。

case '4':$msgType = "image";$textTpl="<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><Image><MediaId><![CDATA[%s]]></MediaId></Image></xml>";$contentStr = "x8HdTwMILc3NYW1maYVR9QwKt7bDtQ2y4VfcQ5zlbIJQWpSqS1fYGX_jJhTjco2m";break;default:$contentStr = "请输入1、2、3获取信息";break;}                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                echo $resultStr;

3、(图文消息)。

case '5':$msgType = "news";$title="PHP知识共享主题";$desc="PHP知识共享主题的简介";$url="http://www.qsnbd.top";$picurl="http://www.qsnbd.top/phpandshare.jpg";$textTpl="<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><ArticleCount>1</ArticleCount><Articles><item><Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description><PicUrl><![CDATA[%s]]></PicUrl><Url><![CDATA[%s]]></Url></item></Articles></xml>";$resultStr2 = sprintf($textTpl, $fromUsername, $toUsername, $time,$msgType, $title, $desc,$picurl,$url);echo $resultStr2;exit;break;

4、多图文消息。

$msgType = "news";$newsArr=array(array('title'=>'PHP知识共享主题','desc'=>'PHP知识共享主题的简介','picurl'=>'http://www.xxx.com/phpandshare.jpg','url'=>'http://www.xxx.com',),array('title'=>'PHP知识共享主题2','desc'=>'PHP知识共享主题的简介2','picurl'=>'http://www.xxx.com/phpandshare.jpg','url'=>'http://www.xxx.com',),array('title'=>'PHP知识共享主题3','desc'=>'PHP知识共享主题的简介3','picurl'=>'http://www.xxx.com/phpandshare.jpg','url'=>'http://www.xxx.com',),);$str="";foreach ($newsArr as $val){$str.="<item>                                            <Title><![CDATA[{$val['title']}]]></Title>                                            <Description><![CDATA[{$val['desc']}]]></Description>                                            <PicUrl><![CDATA[{$val['picurl']}]]></PicUrl>                                            <Url><![CDATA[{$val['url']}]]></Url>                                        </item>";}$textTpl="<xml>                                        <ToUserName><![CDATA[%s]]></ToUserName>                                        <FromUserName><![CDATA[%s]]></FromUserName>                                        <CreateTime>%s</CreateTime>                                        <MsgType><![CDATA[%s]]></MsgType>                                        <ArticleCount>%s</ArticleCount>                                        <Articles>                                        %s                                        </Articles>                                        </xml>                                        ";$tot=count($newsArr);$resultStr2 = sprintf($textTpl, $fromUsername, $toUsername, $time,$msgType,$tot,$str);echo $resultStr2;exit;


0 0
原创粉丝点击