微信接口消息接口指南
屯昌中立科技 | 2018-01-26 23:29:29 | 阅读:46266
公众平台消息接口为开发者提供了一种新的消息处理方式。申请消息接口点击申请,填写网址url和token,其中token可由开发者可以任意填写,用作生成签名。网址接入公众平台用户提交信息后,微信服务器将发送GET请求到填写的URL上,并且带上四个参数:参数描述signature微信加密签名timestamp时间戳nonce随机数echostr随机字符串开发者通过检验signature对请求进行校验(下面有校验方式)。若确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效,否则接入失败。signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。加密/校验流程:1.将token、timestamp、nonce三个参数进行字典序排序2.将三个参数字符串拼接成一个字符串进行sha1加密3.开发者获得加密后的字符串可与signature对比,标识该请求来源于微信消息推送当普通微信用户向公众账号发消息时,微信服务器将POST该消息到填写的URL上。结构如下:文本消息<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName><![CDATA[fromUser]]></FromUserName><CreateTime>1348831860</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[thisisatest]]></Content><MsgId>1234567890123456</MsgId></xml>参数描述ToUserName开发者微信号FromUserName发送方帐号(一个OpenID)CreateTime消息创建时间(整型)MsgTypetextContent文本消息内容MsgId消息id,64位整型图片消息<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName><![CDATA[fromUser]]></FromUserName><CreateTime>1348831860</CreateTime><MsgType><![CDATA[image]]></MsgType><icUrl><![CDATA[thisisaurl]]></PicUrl><MsgId>1234567890123456</MsgId></xml>参数描述ToUserName开发者微信号FromUserName发送方帐号(一个OpenID)CreateTime消息创建时间(整型)MsgTypeimagePicUrl图片链接MsgId消息id,64位整型地理位置消息<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName><![CDATA[fromUser]]></FromUserName><CreateTime>1351776360</CreateTime><MsgType><![CDATA[location]]></MsgType><Location_X>23.134521</Location_X><Location_Y>113.358803</Location_Y><Scale>20</Scale><Label><![CDATA[位置信息]]></Label><MsgId>1234567890123456</MsgId></xml>参数描述ToUserName开发者微信号FromUserName发送方帐号(一个OpenID)CreateTime消息创建时间(整型)MsgTypelocationLocation_X地理位置纬度Location_Y地理位置经度Scale地图缩放大小Label地理位置信息MsgId消息id,64位整型链接消息<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName><![CDATA[fromUser]]></FromUserName><CreateTime>1351776360</CreateTime><MsgType><![CDATA[link]]></MsgType><Title><![CDATA[公众平台官网链接]]></Title><Description><![CDATA[公众平台官网链接]]></Description><Url><![CDATA[url]]></Url><MsgId>1234567890123456</MsgId></xml>参数描述ToUserName接收方微信号FromUserName发送方微信号,若为普通用户,则是一个OpenIDCreateTime消息创建时间MsgType消息类型,linkTitle消息标题Description消息描述Url消息链接MsgId消息id,64位整型事件推送事件推送只支持微信4.5版本,目前开启自定义菜单接口事件推送、关注与取消关注事件推送。其余功能即将开放,敬请期待。<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName><![CDATA[FromUser]]></FromUserName><CreateTime>123456789</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[EVENT]]></Event><EventKey><![CDATA[EVENTKEY]]></EventKey></xml>参数描述ToUserName接收方微信号FromUserName发送方微信号,若为普通用户,则是一个OpenIDCreateTime消息创建时间MsgType消息类型,eventEvent事件类型,subscribe(订阅)、unsubscribe(取消订阅)、CLICK(自定义菜单点击事件)EventKey事件KEY值,与自定义菜单接口中KEY值对应