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

    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;

  • 相关阅读:
    二维数组重复合并 并计算
    处理formdata传递的json数据
    thinkphp lock 锁 的使用和例子
    docker 更新后 和wsl2直接集成
    ubuntu apt 换阿里镜像源
    使用phpstorm将本地代码实时自动同步到远程服务器
    notepad++ markdown主题
    【Git】pull遇到错误:error: Your local changes to the following files would be overwritten by merge:
    hyperf 安装扩展 protobuf
    bt[宝塔]安装redis
  • 原文地址:https://www.cnblogs.com/westsoft/p/9724010.html
Copyright © 2011-2022 走看看