zoukankan      html  css  js  c++  java
  • UNIGUI接收普通消息和被动回复用户消息

    1. 接收普通消息和被动回复用户消息

    用户发送消息给公众号时(或某些特定的用户操作引发的事件推送时),会产生一个POST请求,开发者可以在响应包(Get)中返回特定XML结构,来对该消息进行响应(现支持回复文本、图片、图文、语音、视频、音乐)。严格来说,发送被动响应消息其实并不是一种接口,而是对微信服务器发过来消息的一次回复。

    假如服务器无法保证在五秒内处理并回复,必须做出下述回复,这样微信服务器才不会对此作任何处理,并且不会发起重试(这种情况下,可以使用客服消息接口进行异步回复),否则,将出现严重的错误提示。详见下面说明:

    1、直接回复success(推荐方式)

    2、直接回复空串(指字节长度为0的空字符串,而不是XML结构体中content字段的内容为空)

    一旦遇到以下情况,微信都会在公众号会话中,向用户下发系统提示“该公众号暂时无法提供服务,请稍后再试”:

    1、开发者在5秒内未回复任何内容

    2、开发者回复了异常数据,比如JSON数据等

    //unigui接收消息用UniGUIServerModuleHTTPDocument

    procedure TUniServerModule.UniGUIServerModuleHTTPDocument(

      const Document: string; const InParams: TStrings;

      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;

      var Handled: Boolean);

    var temp:TStringList;

        temps:string;

    begin

      if CheckSignature(ARequestInfo) then

      begin

         if  ARequestInfo.PostStream <> nil then

         begin

           temp:=TStringList.Create;

           temp.LoadFromStream(TMemoryStream(ARequestInfo.PostStream));

           temps := '<?xml version=''1.0'' encoding=''gb2312''?>' + temp.Text;

           temps := StringReplace(temps, '<![CDATA[', '', [rfReplaceAll, rfIgnoreCase]);

           temps := StringReplace(temps, ']]>', '', [rfReplaceAll, rfIgnoreCase]);

           CoInitialize(nil);

           try

             Handled := true;

             AResponseInfo.CharSet := 'UTF-8';

             AResponseInfo.ContentType := 'UTF-8';

             AResponseInfo.ContentType := 'text/html; charset=UTF-8';

             AResponseInfo.ContentText :=Analysis(temps);//回复用户消息,也可以直接返回:AResponseInfo.ContentText :=''

           finally

             CoUninitialize;

             temp.Free;

           end;

         end;

      end;

  • 相关阅读:
    操作系统:DOS
    袁氏-人物:袁淑
    移植linux-2.6.32.2到qq2440
    qq2440启动linux后出现错误提示request_module: runaway loop modprobe binfmt-464c
    qq2440启动linux后插入u盘出现usb 1-1: device descriptor read/64, error -110,usb 1-1: device not accepting address 8, error -110
    ubuntu14.04 64bit安装teamviewer
    vi 的使用
    添加了环境变量,然而交叉编译器还是无法运行的解决方案
    linux下route命令使用实战
    ubuntu14.04纯命令行下连接有线网和无线网
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/9380570.html
Copyright © 2011-2022 走看看