unit MiddleWare.DingTalk; interface uses MVCFramework.Logger, MVCFramework, MVCFramework.Commons; type TDingTalkFilterMiddleware = class(TInterfacedObject, IMVCMiddleware) private function IsDingTalkPath(const Path: string): Boolean; public procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean); procedure OnAfterRouting(Context: TWebContext; const AHandled: Boolean); procedure OnBeforeControllerAction(Context: TWebContext; const AControllerQualifiedClassName: string; const AActionName: string; var AHandled: Boolean); procedure OnAfterControllerAction(Context: TWebContext; const AControllerQualifiedClassName: string; const AActionName: string; const AHandled: Boolean); end; implementation uses System.SysUtils; function TDingTalkFilterMiddleware.IsDingTalkPath(const Path: string): Boolean; const BASE_PATH = '/dingtalk'; var PathLen, BaseLen: Integer; begin Result := False; BaseLen := Length(BASE_PATH); PathLen := Length(Path); if PathLen < BaseLen then Exit; // 不区分大小写的比较 if not SameText(Copy(Path, 1, BaseLen), BASE_PATH) then Exit; // 检查是否精确匹配或子路径 Result := (PathLen = BaseLen) or (Path[BaseLen + 1] = '/'); end; procedure TDingTalkFilterMiddleware.OnAfterControllerAction(Context: TWebContext; const AControllerQualifiedClassName, AActionName: string; const AHandled: Boolean); begin end; procedure TDingTalkFilterMiddleware.OnAfterRouting(Context: TWebContext; const AHandled: Boolean); begin end; procedure TDingTalkFilterMiddleware.OnBeforeControllerAction(Context: TWebContext; const AControllerQualifiedClassName, AActionName: string; var AHandled: Boolean); begin end; procedure TDingTalkFilterMiddleware.OnBeforeRouting(Context: TWebContext; var Handled: Boolean); begin // 钉钉路由处理逻辑 if IsDingTalkPath(Context.Request.PathInfo) then begin LogD('IS /dingtalk'); Handled := True; end; end; end.

中年大叔学Delphi
浙公网安备 33010602011771号