例子,微信公共账号之php开发接口。
复制代码代码示例:
<?php
define("TOKEN","你的TOKEN");
class wechatCallBackApi{
//public $signature; //加密签名
//public $timestamp; //时间戳
//public $nonce; //随机数
//public $echostr; //随机字符串,返回标志
public $fromUserName; //发信人ID
public $toUserName; //收信人ID(本公共号)
public $keyWords; //文本信息
public $msgId; //消息ID
public $welcomeMsg; //欢迎消息
public $msgType; //消息类型
public $event; //事件名
public $mediaId; //语音消息媒体id,可以调用多媒体文件下载接口拉取该媒体
public $format; //语音格式:amr
public $recognition; //语音识别结果
public function __construct(){
$this->welcomeMsg="HELLO,欢迎订阅!";
//$this->main(); /
}
//回复文本信息方法
public function resTextMsg($tu,$fu,$textContent){
//文本消息模板
$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"; //消息类型
$time = time(); //时间戳
$resServerStr = sprintf($textTpl,$tu,$fu,$time,$msgType,$textContent); //替换模板里的内容
return $resServerStr;
}
//回复图文
public function resTextPicMax($tu,$fu,$itemNum,$totalItemStr){
//图片模板
$picTpl = "<xml>
<ToUserName><![Cdata[%s]]></ToUserName>
<FromUserName><![Cdata[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![Cdata[%s]]></MsgType>
<ArticleCount>%s</ArticleCount>
<Articles>"
.$totalItemStr.
"</Articles>
</xml>";
$msgType = "news"; //消息类型
$time = time(); //时间戳
$resServerStr = sprintf($picTpl,$this->fromUserName,$this->toUserName,$time,$msgType,$itemNum); //替换模板里的内容
return $resServerStr;
}
//图文模板处理
public function textPicMaxTmp($title,$des,$picUrl,$jumpUrl){
//图文消息条目模板
$itemTpl="
<item>
<Title><![Cdata[%s]]></Title>
<Description><![Cdata[%s]]></Description>
<PicUrl><![Cdata[%s]]></PicUrl>
<Url><![Cdata[%s]]></Url>
</item>
";
$resItemStr = sprintf($itemTpl,$title,$des,$picUrl,$jumpUrl); //替换模板里的内容
return $resItemStr;
}
//接下来就是你自己定义的各种方法
}
乐发网超市批发网提供超市货源信息,超市采购进货渠道。超市进货网提供成都食品批发,日用百货批发信息、微信淘宝网店超市采购信息和超市加盟信息.打造国内超市采购商与批发市场供应厂商搭建网上批发市场平台,是全国批发市场行业中电子商务权威性网站。
本文来源: 微信公共账号之php开发接口示例