博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信开发学习(二)
阅读量:6856 次
发布时间:2019-06-26

本文共 2435 字,大约阅读时间需要 8 分钟。

学习发送微信的消息类型。

当发送消息时,同时会附加的参数有,signature,timestamp,nonce, 以及消息的XML数据包。

数据包格式,类似:

<xml>

  <ToUserName><![CDATA[tousername]]></ToUserName>

    <FromUserName><![CDATA[fromusername]]></FromUserName>

    <CreateTime><!CDATA[createtime]]</CreateTime>

  <MsgType><!CDATA[type]]</MsgType>

<Content><!CDATA[content]]</Content>

<MsgId>xxxxxx</MsgId>

</xml>

 

收到原始数据的代码:

$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

将原始数据转变为对象:

$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

 

1. 文本消息

    

<xml>

  <ToUserName><![CDATA[tousername]]></ToUserName>

    <FromUserName><![CDATA[fromusername]]></FromUserName>

    <CreateTime><!CDATA[createtime]]</CreateTime>

  <MsgType><!CDATA[text]]</MsgType>

<Content><!CDATA[content]]</Content>

<MsgId>xxxxxx</MsgId>

</xml>

 

2. 图片消息

<xml>

  <ToUserName><![CDATA[tousername]]></ToUserName>

    <FromUserName><![CDATA[fromusername]]></FromUserName>

    <CreateTime><!CDATA[createtime]]</CreateTime>

  <MsgType><!CDATA[image]]</MsgType>

<PicUrl><!CDATA[http://xxxxxx]]</PicUrl>

<MsgId>xxxxxx</MsgId>

<MediaId><![CDATA[xxxxxx]]></MediaId>

</xml>

3. 语音消息

<xml>

  <ToUserName><![CDATA[tousername]]></ToUserName>

    <FromUserName><![CDATA[fromusername]]></FromUserName>

    <CreateTime><!CDATA[createtime]]</CreateTime>

  <MsgType><!CDATA[voice]]</MsgType>

 <MediaId><![CDATA[xxxxxx]]></MediaId>

 <Format><![CDATA[amr]]></Format>

<MsgId>xxxxxx</MsgId>

<Recognition><![CDATA[]]></Recognition>

</xml>

 

4.视频消息

<xml>

  <ToUserName><![CDATA[tousername]]></ToUserName>

    <FromUserName><![CDATA[fromusername]]></FromUserName>

    <CreateTime><!CDATA[createtime]]</CreateTime>

  <MsgType><!CDATA[video]]</MsgType>

 <MediaId><![CDATA[xxxxxx]]></MediaId>

<ThumbMediaId><![CDATA[xxxx]]></ThumbMediaId>

<MsgId>xxxxxx</MsgId>

</xml>

 

5.地理位置消息

<xml>

  <ToUserName><![CDATA[tousername]]></ToUserName>

    <FromUserName><![CDATA[fromusername]]></FromUserName>

    <CreateTime><!CDATA[createtime]]</CreateTime>

   <MsgType><!CDATA[location]]</MsgType>

 <Location_X>xxxxx</Location_X>

<Location_Y>xxxx<Location_Y>

<Scale>xx</Scale>

<Label><![CDATA[xxxxxx]]></Label>

<MsgId>xxxxxx</MsgId>

</xml>

 

6.连接消息

<xml>

  <ToUserName><![CDATA[tousername]]></ToUserName>

    <FromUserName><![CDATA[fromusername]]></FromUserName>

    <CreateTime><!CDATA[createtime]]</CreateTime>

  <MsgType><!CDATA[link]]</MsgType>

 <Title><![CDATA[xxxxxx]]></Title>

<Description><![CDATA[xxxx]]></Description>

<Url><![CDATA[xxxx]]></Url>

<MsgId>xxxxxx</MsgId>

</xml>

转载于:https://www.cnblogs.com/ahMay/p/5151273.html

你可能感兴趣的文章
Linux下架设rsync服务器
查看>>
Struts2教程8:拦截器概述
查看>>
windows 屏幕坐标 窗口坐标 客户区坐标 逻辑坐标 设备坐标之间的关系及转换
查看>>
在Foreda8上试安装Apchehttpd-2.4.6.tar.gz
查看>>
基于S3C2410的VIVI移植
查看>>
Entity Framwork one to one problem
查看>>
[转] Attach、Detach和DeleteObject
查看>>
[转] C# 获取程序运行目录
查看>>
【OpenCV学习】极坐标变换
查看>>
[Android Pro] InputStream.skip方法的思考
查看>>
判断页面加载
查看>>
8年前,《西班牙,我为你哭泣。》
查看>>
SVN:服务器资源删掉,本地添加时和删掉的名字同名出现One or more files are in a conflicted state....
查看>>
MySQL数据库遭到攻击篡改---使用备份和binlog进行数据恢复
查看>>
如何在Java中定义常量(Constant)
查看>>
Windows 8实用窍门系列:8.Windows 8 中Slider控件和ToggleSwitch控件
查看>>
在IIS 7.0中架设网站,并用VS2005来调试Web项目
查看>>
白话学习MVC(七)Action的执行一
查看>>
javaweb学习总结(四)——Http协议
查看>>
GridView实战二:使用ObjectDataSource数据源控件
查看>>