zoukankan      html  css  js  c++  java
  • 微信开发学习(二)

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

    当发送消息时,同时会附加的参数有,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>

  • 相关阅读:
    有向图的十字链表存储表示 以及相关操作(包括增加弧、删除弧、删除顶点等)
    数据结构学习笔记—图---图的连通性、顶点间的路径
    解决Vue父路由进入子路由选中样式消失的问题
    解决vue页面刷新,数据丢失
    解决PHP接收不到axios的POST的传参方式
    rem理解及应用【笔记】
    JS基础(学习笔记)
    css中的小技巧
    css中文单行、多行超出省略号和英文换行(学习笔记)
    关于JS(原生js+jq)中获取、设置或者删除元素属性和获取元素值
  • 原文地址:https://www.cnblogs.com/ahMay/p/5151273.html
Copyright © 2011-2022 走看看