namespace XFEWorkflow.Plugins.WeCom.Native.Core;
///
/// An adapter for a separately verified WeCom native Hook or cache reader.
/// Implementations must not capture the screen or drive the client UI.
/// This interface does not implement or provide any WeCom memory offsets.
///
public interface IWeComTransport : IAsyncDisposable
{
// Getting metadata and constructing the adapter must not attach/inject/send.
ProviderInfo Info { get; }
ValueTask ConnectAsync(ClientTarget target, CancellationToken cancellationToken);
ValueTask> GetGroupsAsync(CancellationToken cancellationToken);
ValueTask> GetMembersAsync(string conversationId, CancellationToken cancellationToken);
// Establish a live baseline when called. Never label cache/history replay as live.
// All events must carry real, stable message IDs, original sender IDs and the
// native message kind. MergedForward must not be inferred from visible text.
// Cancellation must stop subscription; disconnection must terminate this stream.
IAsyncEnumerable WatchMessagesAsync(DateTimeOffset listenSinceUtc,
CancellationToken cancellationToken);
// Invoke the verified client's internal send path, with no automatic retry.
// Accepted means the native send operation was accepted, not server delivery.
// If the outcome is uncertain, return Unknown rather than retrying.
ValueTask SendTextAsync(TextReply reply, CancellationToken cancellationToken);
}
public interface IAttemptStore : IAsyncDisposable
{
// Must durably reserve before returning true. Includes failed/uncertain attempts.
ValueTask TryReserveAsync(AttemptKey key, CancellationToken cancellationToken);
}
public static class TransportValidation
{
public static void ValidateProvider(ProviderInfo info, string clientVersion)
{
if (string.IsNullOrWhiteSpace(info.Name) || info.SupportedVersions is null ||
!info.SupportedVersions.Contains(clientVersion, StringComparer.Ordinal))
throw new NotSupportedException($"接口未声明支持本机企业微信 {clientVersion},不能连接。");
if (info.ReceiveMethod is not (ReceiveMethod.MemoryHook or ReceiveMethod.LocalCache) ||
info.SendMethod != SendMethod.ClientInternalCall || !info.ProvidesLiveMessageIds)
throw new NotSupportedException("接口必须提供内存/缓存消息、真实消息 ID 和客户端内部发送能力。");
}
public static void ValidateSession(ClientSession session, string clientVersion)
{
if (!ReplySettings.ValidId(session.AccountId) || !ReplySettings.ValidId(session.SelfUserId))
throw new InvalidOperationException("接口没有返回有效的登录账号和自身成员 ID。");
if (!string.Equals(session.ClientVersion, clientVersion, StringComparison.Ordinal))
throw new NotSupportedException("接口返回的客户端版本与本机不一致,已停止连接。");
}
}