1.文本接口
说明:如果用户发送过来的XML数据中,MsgType节点为'text'就代表用户发送的是文本消息。
接口开发步骤:
1>在接收是,接收MsgType节点
// 接收用户消息类型
$msgType = $postObj->MsgType;
2>在接收消息是对$MsgType进行判断
if ($msgType == 'text') {
# code...
// 判断用户发送关键词是否为空
if(!empty( $keyword ))
{
// 回复类型 如果为text 代表文本
$msgType = "text";
// 回复内容
$contentStr = "你发送的是文本消息!";
// 格式化字符串
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
// 把XML返回给手机端
echo $resultStr;
}
2.图片消息接口
编写代码如下 不在写了 其他的类似