微信企业机器人创建

This commit is contained in:
2026-07-26 08:16:56 +08:00
parent f053908acb
commit 34532dc9bf
26 changed files with 1963 additions and 4 deletions
@@ -0,0 +1,44 @@
import { Injectable } from '@nestjs/common';
import { RedisService } from '../../common/redis/redis.service';
const TTL_SECONDS = 30 * 60;
export type WecomUserVerifySession = {
phone: string;
/** 验证通过后可查看 */
verified: boolean;
pendingUserId?: string;
};
@Injectable()
export class WecomBotSessionService {
constructor(private readonly redis: RedisService) {}
private key(botKey: string, wecomUserId: string) {
return `dukang:wecom:session:${botKey}:${wecomUserId}`;
}
async get(botKey: string, wecomUserId: string): Promise<WecomUserVerifySession | null> {
return this.redis.getJson<WecomUserVerifySession>(this.key(botKey, wecomUserId));
}
async setPendingPhone(botKey: string, wecomUserId: string, phone: string) {
await this.redis.setJson(
this.key(botKey, wecomUserId),
{ phone, verified: false } satisfies WecomUserVerifySession,
TTL_SECONDS,
);
}
async markVerified(botKey: string, wecomUserId: string, phone: string, userId: string) {
await this.redis.setJson(
this.key(botKey, wecomUserId),
{ phone, verified: true, pendingUserId: userId } satisfies WecomUserVerifySession,
TTL_SECONDS,
);
}
async clear(botKey: string, wecomUserId: string) {
await this.redis.del(this.key(botKey, wecomUserId));
}
}