feat: 短信调试日志、Tawk 客服、手机号校验放宽与 Docker 文档
API - 短信发码/验码/创蓝全链路结构化日志(手机号脱敏) - 新增 SMS_DEBUG_LOG_CODE,联调时可输出验证码与 sessionId(对应创蓝批次号) - 注册成功、短信找回密码成功写入审计相关日志 - 放宽手机号归一化:移除区号白名单与 10~15 位长度限制 Player - 公告走马灯滚动周期调整为 35 秒 - 在线客服接入 Tawk.to(tawk.html),登录用户透传昵称/头像/ID - 三语补充 support.connecting 文案 部署与文档 - docker-compose 与 .env.docker.example 增加 SMS_DEBUG_LOG_CODE - 新增 docs/短信调试与日志说明.md、docs/docker 镜像构建导出脚本与说明 - Docker 部署指南补充镜像构建文档链接 - .gitignore 忽略 thebet365-images.tar 与 docker-build.log Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,3 +26,5 @@ CHUANGLAN_CONNECT_TIMEOUT_MS=10000
|
|||||||
CHUANGLAN_READ_TIMEOUT_MS=10000
|
CHUANGLAN_READ_TIMEOUT_MS=10000
|
||||||
SMS_CODE_TTL_SECONDS=300
|
SMS_CODE_TTL_SECONDS=300
|
||||||
SMS_RATE_LIMIT_SECONDS=60
|
SMS_RATE_LIMIT_SECONDS=60
|
||||||
|
# 联调时在 .env.docker 设为 true,日志会输出验证码与 sessionId(对应创蓝批次号);上线前改回 false
|
||||||
|
SMS_DEBUG_LOG_CODE=false
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,6 +2,8 @@ node_modules/
|
|||||||
dist/
|
dist/
|
||||||
.pnpm-store/
|
.pnpm-store/
|
||||||
release/
|
release/
|
||||||
|
docker-build.log
|
||||||
|
thebet365-images.tar
|
||||||
.claude/
|
.claude/
|
||||||
*.log
|
*.log
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { Decimal } from '@prisma/client/runtime/library';
|
import { Decimal } from '@prisma/client/runtime/library';
|
||||||
import { appForbidden, appUnauthorized, appBadRequest, appNotFound } from '../../shared/common/app-error';
|
import { appForbidden, appUnauthorized, appBadRequest, appNotFound } from '../../shared/common/app-error';
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
@@ -11,6 +11,7 @@ import { InvitesService } from './invites.service';
|
|||||||
import { SmsService } from './sms/sms.service';
|
import { SmsService } from './sms/sms.service';
|
||||||
import { AuditService } from '../operations/audit/audit.service';
|
import { AuditService } from '../operations/audit/audit.service';
|
||||||
import { normalizePhone, resolvePlayerLoginCandidates, stripLocalPhoneDigits } from './sms/phone.util';
|
import { normalizePhone, resolvePlayerLoginCandidates, stripLocalPhoneDigits } from './sms/phone.util';
|
||||||
|
import { maskPhoneForLog } from './sms/sms-log.util';
|
||||||
|
|
||||||
const MAX_LOGIN_FAILS = 5;
|
const MAX_LOGIN_FAILS = 5;
|
||||||
const LOCK_DURATION_MS = 15 * 60 * 1000;
|
const LOCK_DURATION_MS = 15 * 60 * 1000;
|
||||||
@@ -24,6 +25,8 @@ export interface JwtPayload {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
|
private readonly logger = new Logger(AuthService.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private prisma: PrismaService,
|
private prisma: PrismaService,
|
||||||
private jwt: JwtService,
|
private jwt: JwtService,
|
||||||
@@ -313,6 +316,8 @@ export class AuthService {
|
|||||||
return created;
|
return created;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.logger.log(`Player registered username=${username} phone=${maskPhoneForLog(phone)}`);
|
||||||
|
|
||||||
return this.login(username, data.password, 'player');
|
return this.login(username, data.password, 'player');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,6 +430,10 @@ export class AuthService {
|
|||||||
ipAddress: data.ipAddress,
|
ipAddress: data.ipAddress,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.logger.log(
|
||||||
|
`Password reset by phone userId=${player.id.toString()} phone=${maskPhoneForLog(normalizePhone(data.countryCode, data.phone))} ip=${data.ipAddress ?? 'n/a'}`,
|
||||||
|
);
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { generateChuanglanSign } from './sign';
|
import { generateChuanglanSign } from './sign';
|
||||||
import { loadChuanglanConfig } from './config';
|
import { loadChuanglanConfig } from './config';
|
||||||
import type { ChuanglanSendResponse, SmsSendResult } from '../sms.types';
|
import type { ChuanglanSendResponse, SmsSendResult } from '../sms.types';
|
||||||
|
import { maskPhoneForLog, shortSessionId } from '../sms-log.util';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ChuanglanClient {
|
export class ChuanglanClient {
|
||||||
|
private readonly logger = new Logger(ChuanglanClient.name);
|
||||||
private readonly cfg;
|
private readonly cfg;
|
||||||
|
|
||||||
constructor(config: ConfigService) {
|
constructor(config: ConfigService) {
|
||||||
@@ -14,6 +16,10 @@ export class ChuanglanClient {
|
|||||||
|
|
||||||
async sendSms(mobile: string, msg: string, uid?: string): Promise<SmsSendResult> {
|
async sendSms(mobile: string, msg: string, uid?: string): Promise<SmsSendResult> {
|
||||||
const nonce = String(Date.now());
|
const nonce = String(Date.now());
|
||||||
|
const maskedMobile = maskPhoneForLog(mobile);
|
||||||
|
const session = uid ? shortSessionId(uid) : 'n/a';
|
||||||
|
|
||||||
|
this.logger.log(`Chuanglan request mobile=${maskedMobile} session=${session}`);
|
||||||
|
|
||||||
const body: Record<string, string> = {
|
const body: Record<string, string> = {
|
||||||
account: this.cfg.account,
|
account: this.cfg.account,
|
||||||
@@ -42,6 +48,9 @@ export class ChuanglanClient {
|
|||||||
const data = (await res.json()) as ChuanglanSendResponse;
|
const data = (await res.json()) as ChuanglanSendResponse;
|
||||||
|
|
||||||
if (data.code === '0') {
|
if (data.code === '0') {
|
||||||
|
this.logger.log(
|
||||||
|
`Chuanglan success mobile=${maskedMobile} session=${session} messageId=${data.data?.messageId ?? 'n/a'}`,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
code: data.code,
|
code: data.code,
|
||||||
@@ -50,9 +59,15 @@ export class ChuanglanClient {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.warn(
|
||||||
|
`Chuanglan rejected mobile=${maskedMobile} session=${session} code=${data.code} message=${data.message ?? 'n/a'}`,
|
||||||
|
);
|
||||||
return { success: false, code: data.code, message: data.message };
|
return { success: false, code: data.code, message: data.message };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = err instanceof Error ? err.message : 'Unknown error';
|
const message = err instanceof Error ? err.message : 'Unknown error';
|
||||||
|
this.logger.error(
|
||||||
|
`Chuanglan HTTP error mobile=${maskedMobile} session=${session} error=${message}`,
|
||||||
|
);
|
||||||
return { success: false, code: 'HTTP_ERROR', message };
|
return { success: false, code: 'HTTP_ERROR', message };
|
||||||
} finally {
|
} finally {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export interface ChuanglanConfig {
|
|||||||
export interface SmsBusinessConfig {
|
export interface SmsBusinessConfig {
|
||||||
codeTtlSeconds: number;
|
codeTtlSeconds: number;
|
||||||
rateLimitSeconds: number;
|
rateLimitSeconds: number;
|
||||||
|
/** 为 true 时在日志输出验证码与完整 sessionId(仅联调,生产务必关闭) */
|
||||||
|
debugLogCode: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadChuanglanConfig(config: ConfigService): ChuanglanConfig {
|
export function loadChuanglanConfig(config: ConfigService): ChuanglanConfig {
|
||||||
@@ -29,8 +31,10 @@ export function loadChuanglanConfig(config: ConfigService): ChuanglanConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function loadSmsBusinessConfig(config: ConfigService): SmsBusinessConfig {
|
export function loadSmsBusinessConfig(config: ConfigService): SmsBusinessConfig {
|
||||||
|
const debugRaw = config.get<string>('SMS_DEBUG_LOG_CODE', 'false');
|
||||||
return {
|
return {
|
||||||
codeTtlSeconds: Number(config.get('SMS_CODE_TTL_SECONDS', 300)),
|
codeTtlSeconds: Number(config.get('SMS_CODE_TTL_SECONDS', 300)),
|
||||||
rateLimitSeconds: Number(config.get('SMS_RATE_LIMIT_SECONDS', 60)),
|
rateLimitSeconds: Number(config.get('SMS_RATE_LIMIT_SECONDS', 60)),
|
||||||
|
debugLogCode: debugRaw === 'true' || debugRaw === '1',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,14 @@
|
|||||||
import { appBadRequest } from '../../../shared/common/app-error';
|
import { appBadRequest } from '../../../shared/common/app-error';
|
||||||
import { isSupportedPhoneDial } from '@thebet365/shared';
|
|
||||||
|
|
||||||
/** 归一化为创蓝格式:国家区号 + 本地号码(纯数字,无 +) */
|
/** 归一化为创蓝格式:国家区号 + 本地号码(纯数字,无 +) */
|
||||||
export function normalizePhone(countryDial: string, localInput: string): string {
|
export function normalizePhone(countryDial: string, localInput: string): string {
|
||||||
const dial = countryDial.replace(/\D/g, '');
|
const dial = countryDial.replace(/\D/g, '');
|
||||||
let local = stripLocalPhoneDigits(localInput);
|
const local = stripLocalPhoneDigits(localInput);
|
||||||
|
|
||||||
if (!dial || !local) {
|
if (!dial || !local) {
|
||||||
throw appBadRequest('PHONE_REQUIRED');
|
throw appBadRequest('PHONE_REQUIRED');
|
||||||
}
|
}
|
||||||
if (!isSupportedPhoneDial(dial)) {
|
return `${dial}${local}`;
|
||||||
throw appBadRequest('PHONE_COUNTRY_UNSUPPORTED');
|
|
||||||
}
|
|
||||||
|
|
||||||
const combined = `${dial}${local}`;
|
|
||||||
if (combined.length < 10 || combined.length > 15) {
|
|
||||||
throw appBadRequest('PHONE_INVALID');
|
|
||||||
}
|
|
||||||
return combined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 提取本地号码(纯数字,去掉前导 0) */
|
/** 提取本地号码(纯数字,去掉前导 0) */
|
||||||
@@ -48,7 +39,7 @@ export function resolvePlayerLoginUsername(
|
|||||||
digits = digits.replace(/^0+/, '');
|
digits = digits.replace(/^0+/, '');
|
||||||
}
|
}
|
||||||
// 已输入含区号完整号码时,不再重复拼接
|
// 已输入含区号完整号码时,不再重复拼接
|
||||||
if (dial && digits.startsWith(dial) && digits.length >= 10) {
|
if (dial && digits.startsWith(dial)) {
|
||||||
return digits;
|
return digits;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -59,7 +50,7 @@ export function resolvePlayerLoginUsername(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const digits = trimmed.replace(/\D/g, '');
|
const digits = trimmed.replace(/\D/g, '');
|
||||||
if (digits.length >= 10) return digits;
|
if (digits.length > 0) return digits;
|
||||||
|
|
||||||
return trimmed;
|
return trimmed;
|
||||||
}
|
}
|
||||||
@@ -81,9 +72,5 @@ export function resolvePlayerLoginCandidates(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const digits = trimmed.replace(/\D/g, '');
|
const digits = trimmed.replace(/\D/g, '');
|
||||||
if (digits.length >= 10) {
|
return [digits.length > 0 ? digits : trimmed];
|
||||||
return [digits];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [digits];
|
|
||||||
}
|
}
|
||||||
|
|||||||
13
apps/api/src/domains/identity/sms/sms-log.util.ts
Normal file
13
apps/api/src/domains/identity/sms/sms-log.util.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/** 日志用:仅保留末 4 位数字,不写完整手机号 */
|
||||||
|
export function maskPhoneForLog(phone: string): string {
|
||||||
|
const digits = phone.replace(/\D/g, '');
|
||||||
|
if (digits.length <= 4) return '****';
|
||||||
|
return `****${digits.slice(-4)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 日志用:缩短 sessionId,便于关联同一次发码/验码 */
|
||||||
|
export function shortSessionId(sessionId: string): string {
|
||||||
|
const trimmed = sessionId.trim();
|
||||||
|
if (trimmed.length <= 8) return trimmed;
|
||||||
|
return `${trimmed.slice(0, 8)}…`;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { randomUUID } from 'node:crypto';
|
import { randomUUID } from 'node:crypto';
|
||||||
import { normalizeLocale } from '@thebet365/shared';
|
import { normalizeLocale } from '@thebet365/shared';
|
||||||
@@ -12,6 +12,7 @@ import { generateSixDigitCode } from './code';
|
|||||||
import { normalizePhone, stripLocalPhoneDigits } from './phone.util';
|
import { normalizePhone, stripLocalPhoneDigits } from './phone.util';
|
||||||
import { renderResetPasswordSms, renderVerifySms } from './templates';
|
import { renderResetPasswordSms, renderVerifySms } from './templates';
|
||||||
import type { SmsLang, SmsPurpose } from './sms.types';
|
import type { SmsLang, SmsPurpose } from './sms.types';
|
||||||
|
import { maskPhoneForLog, shortSessionId } from './sms-log.util';
|
||||||
|
|
||||||
const codeKey = (sessionId: string) => `sms:code:${sessionId}`;
|
const codeKey = (sessionId: string) => `sms:code:${sessionId}`;
|
||||||
const phoneRateKey = (phone: string) => `sms:rate:phone:${phone}`;
|
const phoneRateKey = (phone: string) => `sms:rate:phone:${phone}`;
|
||||||
@@ -26,6 +27,7 @@ function mapLocaleToSmsLang(locale?: string): SmsLang {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SmsService {
|
export class SmsService {
|
||||||
|
private readonly logger = new Logger(SmsService.name);
|
||||||
private readonly smsCfg;
|
private readonly smsCfg;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -47,9 +49,14 @@ export class SmsService {
|
|||||||
}): Promise<{ sessionId: string }> {
|
}): Promise<{ sessionId: string }> {
|
||||||
const purpose: SmsPurpose = params.purpose ?? 'register';
|
const purpose: SmsPurpose = params.purpose ?? 'register';
|
||||||
const phone = normalizePhone(params.countryCode, params.phone);
|
const phone = normalizePhone(params.countryCode, params.phone);
|
||||||
|
const maskedPhone = maskPhoneForLog(phone);
|
||||||
|
|
||||||
|
this.logger.log(
|
||||||
|
`SMS send request purpose=${purpose} phone=${maskedPhone} ip=${params.clientIp}`,
|
||||||
|
);
|
||||||
|
|
||||||
if (purpose === 'reset_password') {
|
if (purpose === 'reset_password') {
|
||||||
await this.assertPlayerCanResetPassword(params.countryCode, params.phone);
|
await this.assertPlayerCanResetPassword(params.countryCode, params.phone, maskedPhone);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [phoneLimited, ipLimited] = await Promise.all([
|
const [phoneLimited, ipLimited] = await Promise.all([
|
||||||
@@ -57,6 +64,9 @@ export class SmsService {
|
|||||||
this.redis.exists(ipRateKey(params.clientIp)),
|
this.redis.exists(ipRateKey(params.clientIp)),
|
||||||
]);
|
]);
|
||||||
if (phoneLimited || ipLimited) {
|
if (phoneLimited || ipLimited) {
|
||||||
|
this.logger.warn(
|
||||||
|
`SMS rate limited purpose=${purpose} phone=${maskedPhone} ip=${params.clientIp} phoneLimited=${phoneLimited} ipLimited=${ipLimited}`,
|
||||||
|
);
|
||||||
throw appTooManyRequests('SMS_RATE_LIMIT');
|
throw appTooManyRequests('SMS_RATE_LIMIT');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +78,17 @@ export class SmsService {
|
|||||||
? renderResetPasswordSms(lang, code)
|
? renderResetPasswordSms(lang, code)
|
||||||
: renderVerifySms(lang, code);
|
: renderVerifySms(lang, code);
|
||||||
|
|
||||||
|
if (this.smsCfg.debugLogCode) {
|
||||||
|
this.logger.warn(
|
||||||
|
`[SMS_DEBUG] purpose=${purpose} phone=${phone} sessionId=${sessionId} code=${code} content=${msg}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const result = await this.chuanglan.sendSms(phone, msg, sessionId);
|
const result = await this.chuanglan.sendSms(phone, msg, sessionId);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
|
this.logger.error(
|
||||||
|
`SMS send failed purpose=${purpose} phone=${maskedPhone} session=${shortSessionId(sessionId)} providerCode=${result.code} providerMessage=${result.message}`,
|
||||||
|
);
|
||||||
throw appBadRequest('SMS_SEND_FAILED');
|
throw appBadRequest('SMS_SEND_FAILED');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +102,10 @@ export class SmsService {
|
|||||||
this.redis.set(ipRateKey(params.clientIp), '1', this.smsCfg.rateLimitSeconds),
|
this.redis.set(ipRateKey(params.clientIp), '1', this.smsCfg.rateLimitSeconds),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
this.logger.log(
|
||||||
|
`SMS sent purpose=${purpose} phone=${maskedPhone} session=${shortSessionId(sessionId)} messageId=${result.messageId ?? 'n/a'}`,
|
||||||
|
);
|
||||||
|
|
||||||
return { sessionId };
|
return { sessionId };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,26 +117,50 @@ export class SmsService {
|
|||||||
expectedPurpose?: SmsPurpose;
|
expectedPurpose?: SmsPurpose;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const phone = normalizePhone(params.countryCode, params.phone);
|
const phone = normalizePhone(params.countryCode, params.phone);
|
||||||
|
const maskedPhone = maskPhoneForLog(phone);
|
||||||
|
const expectedPurpose = params.expectedPurpose ?? 'register';
|
||||||
|
const session = shortSessionId(params.sessionId);
|
||||||
|
|
||||||
|
this.logger.log(
|
||||||
|
`SMS verify request purpose=${expectedPurpose} phone=${maskedPhone} session=${session}`,
|
||||||
|
);
|
||||||
|
|
||||||
const raw = await this.redis.get(codeKey(params.sessionId));
|
const raw = await this.redis.get(codeKey(params.sessionId));
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
|
this.logger.warn(
|
||||||
|
`SMS verify failed reason=expired purpose=${expectedPurpose} phone=${maskedPhone} session=${session}`,
|
||||||
|
);
|
||||||
throw appBadRequest('SMS_CODE_EXPIRED');
|
throw appBadRequest('SMS_CODE_EXPIRED');
|
||||||
}
|
}
|
||||||
|
|
||||||
const cached = JSON.parse(raw) as { phone: string; code: string; purpose?: SmsPurpose };
|
const cached = JSON.parse(raw) as { phone: string; code: string; purpose?: SmsPurpose };
|
||||||
const cachedPurpose: SmsPurpose = cached.purpose ?? 'register';
|
const cachedPurpose: SmsPurpose = cached.purpose ?? 'register';
|
||||||
const expectedPurpose = params.expectedPurpose ?? 'register';
|
|
||||||
|
|
||||||
if (cachedPurpose !== expectedPurpose) {
|
if (cachedPurpose !== expectedPurpose) {
|
||||||
|
this.logger.warn(
|
||||||
|
`SMS verify failed reason=purpose_mismatch expected=${expectedPurpose} cached=${cachedPurpose} phone=${maskedPhone} session=${session}`,
|
||||||
|
);
|
||||||
throw appBadRequest('SMS_CODE_INVALID');
|
throw appBadRequest('SMS_CODE_INVALID');
|
||||||
}
|
}
|
||||||
if (cached.phone !== phone || cached.code !== params.code.trim()) {
|
if (cached.phone !== phone || cached.code !== params.code.trim()) {
|
||||||
|
this.logger.warn(
|
||||||
|
`SMS verify failed reason=invalid_code purpose=${expectedPurpose} phone=${maskedPhone} session=${session}`,
|
||||||
|
);
|
||||||
throw appBadRequest('SMS_CODE_INVALID');
|
throw appBadRequest('SMS_CODE_INVALID');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.redis.del(codeKey(params.sessionId));
|
await this.redis.del(codeKey(params.sessionId));
|
||||||
|
|
||||||
|
this.logger.log(
|
||||||
|
`SMS verify success purpose=${expectedPurpose} phone=${maskedPhone} session=${session}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async assertPlayerCanResetPassword(countryCode: string, phone: string): Promise<void> {
|
private async assertPlayerCanResetPassword(
|
||||||
|
countryCode: string,
|
||||||
|
phone: string,
|
||||||
|
maskedPhone: string,
|
||||||
|
): Promise<void> {
|
||||||
const dial = countryCode.replace(/\D/g, '');
|
const dial = countryCode.replace(/\D/g, '');
|
||||||
const phoneLocal = stripLocalPhoneDigits(phone);
|
const phoneLocal = stripLocalPhoneDigits(phone);
|
||||||
|
|
||||||
@@ -127,14 +174,19 @@ export class SmsService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!pref) {
|
if (!pref) {
|
||||||
|
this.logger.warn(`SMS reset_password blocked reason=phone_not_registered phone=${maskedPhone}`);
|
||||||
throw appBadRequest('PHONE_NOT_REGISTERED');
|
throw appBadRequest('PHONE_NOT_REGISTERED');
|
||||||
}
|
}
|
||||||
if (pref.user.status === 'DISABLED') {
|
if (pref.user.status === 'DISABLED') {
|
||||||
|
this.logger.warn(`SMS reset_password blocked reason=account_disabled phone=${maskedPhone}`);
|
||||||
throw appForbidden('ACCOUNT_DISABLED');
|
throw appForbidden('ACCOUNT_DISABLED');
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = await this.systemConfig.getPlayerAccountSettings();
|
const settings = await this.systemConfig.getPlayerAccountSettings();
|
||||||
if (!settings.allowPasswordChange) {
|
if (!settings.allowPasswordChange) {
|
||||||
|
this.logger.warn(
|
||||||
|
`SMS reset_password blocked reason=password_change_disabled phone=${maskedPhone}`,
|
||||||
|
);
|
||||||
throw appForbidden('PASSWORD_CHANGE_DISABLED');
|
throw appForbidden('PASSWORD_CHANGE_DISABLED');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ const text = computed(() => {
|
|||||||
.marquee-track {
|
.marquee-track {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: max-content;
|
width: max-content;
|
||||||
animation: marquee-scroll 22s linear infinite;
|
animation: marquee-scroll 35s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
.marquee-text {
|
.marquee-text {
|
||||||
|
|||||||
@@ -1,19 +1,39 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { CUSTOMER_SERVICE_URL } from '../config/customerService';
|
import { buildCustomerServiceUrl } from '../config/customerService';
|
||||||
|
import { useAuthStore } from '../stores/auth';
|
||||||
|
import { usePlayerProfile } from '../composables/usePlayerProfile';
|
||||||
|
|
||||||
const props = defineProps<{ modelValue: boolean }>();
|
const props = defineProps<{ modelValue: boolean }>();
|
||||||
const emit = defineEmits<{ 'update:modelValue': [boolean] }>();
|
const emit = defineEmits<{ 'update:modelValue': [boolean] }>();
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const auth = useAuthStore();
|
||||||
|
const { profileRaw, avatarUrl } = usePlayerProfile();
|
||||||
|
|
||||||
const visible = computed({
|
const visible = computed({
|
||||||
get: () => props.modelValue,
|
get: () => props.modelValue,
|
||||||
set: (v) => emit('update:modelValue', v),
|
set: (v) => emit('update:modelValue', v),
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasUrl = computed(() => Boolean(CUSTOMER_SERVICE_URL));
|
const iframeSrc = computed(() => {
|
||||||
|
const visitor = auth.user
|
||||||
|
? {
|
||||||
|
name:
|
||||||
|
profileRaw.value?.username ||
|
||||||
|
profileRaw.value?.preferences?.phone ||
|
||||||
|
auth.user.username ||
|
||||||
|
'',
|
||||||
|
avatar: avatarUrl.value
|
||||||
|
? new URL(avatarUrl.value, window.location.origin).href
|
||||||
|
: '',
|
||||||
|
id: String(profileRaw.value?.id ?? auth.user.id ?? ''),
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return buildCustomerServiceUrl(t('support.connecting'), visitor);
|
||||||
|
});
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
visible.value = false;
|
visible.value = false;
|
||||||
@@ -34,13 +54,13 @@ function close() {
|
|||||||
|
|
||||||
<div class="cs-body">
|
<div class="cs-body">
|
||||||
<iframe
|
<iframe
|
||||||
v-if="hasUrl"
|
v-if="visible"
|
||||||
|
:key="iframeSrc"
|
||||||
class="cs-frame"
|
class="cs-frame"
|
||||||
:src="CUSTOMER_SERVICE_URL"
|
:src="iframeSrc"
|
||||||
:title="t('support.title')"
|
:title="t('support.title')"
|
||||||
allow="clipboard-read; clipboard-write"
|
allow="microphone; camera; clipboard-read; clipboard-write"
|
||||||
/>
|
/>
|
||||||
<p v-else class="cs-empty">{{ t('support.url_pending') }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
/** 客服 iframe 地址,可通过环境变量 VITE_CUSTOMER_SERVICE_URL 覆盖 */
|
/** 客服 iframe 基址,可通过 VITE_CUSTOMER_SERVICE_URL 覆盖(如外部客服页) */
|
||||||
export const CUSTOMER_SERVICE_URL =
|
export const CUSTOMER_SERVICE_BASE =
|
||||||
(import.meta.env.VITE_CUSTOMER_SERVICE_URL as string | undefined)?.trim() || '';
|
(import.meta.env.VITE_CUSTOMER_SERVICE_URL as string | undefined)?.trim() || '/tawk.html';
|
||||||
|
|
||||||
|
export type TawkVisitor = {
|
||||||
|
name?: string;
|
||||||
|
avatar?: string;
|
||||||
|
id?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function buildCustomerServiceUrl(
|
||||||
|
loadingText: string,
|
||||||
|
visitor?: TawkVisitor | null,
|
||||||
|
): string {
|
||||||
|
const params = new URLSearchParams({ loadingText });
|
||||||
|
|
||||||
|
if (visitor) {
|
||||||
|
if (visitor.name) params.set('name', visitor.name);
|
||||||
|
if (visitor.avatar) params.set('avatar', visitor.avatar);
|
||||||
|
if (visitor.id) params.set('id', visitor.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const separator = CUSTOMER_SERVICE_BASE.includes('?') ? '&' : '?';
|
||||||
|
return `${CUSTOMER_SERVICE_BASE}${separator}${params.toString()}`;
|
||||||
|
}
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ export default {
|
|||||||
title: 'Customer Support',
|
title: 'Customer Support',
|
||||||
open: 'Open customer support',
|
open: 'Open customer support',
|
||||||
close: 'Close',
|
close: 'Close',
|
||||||
|
connecting: 'Connecting to support...',
|
||||||
url_pending: 'Support URL is not configured yet.',
|
url_pending: 'Support URL is not configured yet.',
|
||||||
},
|
},
|
||||||
wallet: {
|
wallet: {
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ export default {
|
|||||||
title: 'Khidmat Pelanggan',
|
title: 'Khidmat Pelanggan',
|
||||||
open: 'Buka khidmat pelanggan',
|
open: 'Buka khidmat pelanggan',
|
||||||
close: 'Tutup',
|
close: 'Tutup',
|
||||||
|
connecting: 'Menyambung ke khidmat pelanggan...',
|
||||||
url_pending: 'Pautan khidmat pelanggan belum dikonfigurasi.',
|
url_pending: 'Pautan khidmat pelanggan belum dikonfigurasi.',
|
||||||
},
|
},
|
||||||
wallet: {
|
wallet: {
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ export default {
|
|||||||
title: '在线客服',
|
title: '在线客服',
|
||||||
open: '打开在线客服',
|
open: '打开在线客服',
|
||||||
close: '关闭',
|
close: '关闭',
|
||||||
|
connecting: '正在连接客服...',
|
||||||
url_pending: '客服链接暂未配置,请联系管理员。',
|
url_pending: '客服链接暂未配置,请联系管理员。',
|
||||||
},
|
},
|
||||||
wallet: {
|
wallet: {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ services:
|
|||||||
CHUANGLAN_READ_TIMEOUT_MS: ${CHUANGLAN_READ_TIMEOUT_MS:-10000}
|
CHUANGLAN_READ_TIMEOUT_MS: ${CHUANGLAN_READ_TIMEOUT_MS:-10000}
|
||||||
SMS_CODE_TTL_SECONDS: ${SMS_CODE_TTL_SECONDS:-300}
|
SMS_CODE_TTL_SECONDS: ${SMS_CODE_TTL_SECONDS:-300}
|
||||||
SMS_RATE_LIMIT_SECONDS: ${SMS_RATE_LIMIT_SECONDS:-60}
|
SMS_RATE_LIMIT_SECONDS: ${SMS_RATE_LIMIT_SECONDS:-60}
|
||||||
|
SMS_DEBUG_LOG_CODE: ${SMS_DEBUG_LOG_CODE:-false}
|
||||||
volumes:
|
volumes:
|
||||||
- uploads_data:/app/uploads
|
- uploads_data:/app/uploads
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
@@ -187,6 +187,8 @@ docker exec thebet365-postgres pg_dump -U thebet365 thebet365 > backup.sql
|
|||||||
|
|
||||||
**推荐:先删旧代码再解压新 zip**(避免 `packages/shared/public/球员` 等中文目录残留导致 Vite 构建失败)。
|
**推荐:先删旧代码再解压新 zip**(避免 `packages/shared/public/球员` 等中文目录残留导致 Vite 构建失败)。
|
||||||
|
|
||||||
|
本地构建并导出镜像的详细步骤见:[docker/镜像构建与导出.md](./docker/镜像构建与导出.md)(脚本位于 `docs/docker/build-and-export-images.ps1` / `build-and-export-images.sh`)。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /www/wwwroot
|
cd /www/wwwroot
|
||||||
mv thebet365 thebet365.bak.$(date +%Y%m%d) # 备份旧目录(保留 .env.docker)
|
mv thebet365 thebet365.bak.$(date +%Y%m%d) # 备份旧目录(保留 .env.docker)
|
||||||
|
|||||||
65
docs/docker/build-and-export-images.ps1
Normal file
65
docs/docker/build-and-export-images.ps1
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
# 构建 api / player / admin 生产镜像并导出为 tar
|
||||||
|
# 用法(在项目根目录或本目录执行均可):
|
||||||
|
# .\docs\docker\build-and-export-images.ps1
|
||||||
|
# .\build-and-export-images.ps1 -UseCache
|
||||||
|
# .\build-and-export-images.ps1 -ExportOnly
|
||||||
|
|
||||||
|
param(
|
||||||
|
[switch]$UseCache,
|
||||||
|
[switch]$ExportOnly,
|
||||||
|
[string]$Output = "thebet365-images.tar"
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$Root = (Resolve-Path (Join-Path $PSScriptRoot "../..")).Path
|
||||||
|
Set-Location $Root
|
||||||
|
|
||||||
|
$ComposeFile = "docker-compose.prod.yml"
|
||||||
|
$EnvFile = ".env.docker"
|
||||||
|
$Services = @("api", "player", "admin")
|
||||||
|
|
||||||
|
if (-not (Test-Path $ComposeFile)) {
|
||||||
|
throw "未找到 $ComposeFile(当前目录: $Root)"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $EnvFile)) {
|
||||||
|
if (Test-Path ".env.docker.example") {
|
||||||
|
Write-Warning "未找到 .env.docker,使用 .env.docker.example(生产请复制并修改密钥)"
|
||||||
|
$EnvFile = ".env.docker.example"
|
||||||
|
} else {
|
||||||
|
throw "未找到 .env.docker 或 .env.docker.example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $ExportOnly) {
|
||||||
|
Write-Host "==> 构建镜像: $($Services -join ', ')"
|
||||||
|
$buildArgs = @(
|
||||||
|
"compose", "-f", $ComposeFile, "--env-file", $EnvFile, "build"
|
||||||
|
)
|
||||||
|
if (-not $UseCache) {
|
||||||
|
$buildArgs += "--no-cache"
|
||||||
|
}
|
||||||
|
$buildArgs += $Services
|
||||||
|
& docker @buildArgs
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "docker build 失败,退出码 $LASTEXITCODE" }
|
||||||
|
}
|
||||||
|
|
||||||
|
$OutputPath = if ([System.IO.Path]::IsPathRooted($Output)) { $Output } else { Join-Path $Root $Output }
|
||||||
|
|
||||||
|
Write-Host "==> 导出镜像 -> $OutputPath"
|
||||||
|
& docker save `
|
||||||
|
thebet365-api:latest `
|
||||||
|
thebet365-player:latest `
|
||||||
|
thebet365-admin:latest `
|
||||||
|
-o $OutputPath
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "docker save 失败,退出码 $LASTEXITCODE" }
|
||||||
|
|
||||||
|
$sizeMb = [math]::Round((Get-Item $OutputPath).Length / 1MB, 2)
|
||||||
|
Write-Host "完成: $OutputPath (${sizeMb} MB)"
|
||||||
|
|
||||||
|
Write-Host @"
|
||||||
|
|
||||||
|
服务器加载:
|
||||||
|
docker load -i thebet365-images.tar
|
||||||
|
docker compose -f docker-compose.prod.yml --env-file .env.docker up -d
|
||||||
|
"@
|
||||||
95
docs/docker/build-and-export-images.sh
Normal file
95
docs/docker/build-and-export-images.sh
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# 构建 api / player / admin 生产镜像并导出为 tar
|
||||||
|
# 用法:
|
||||||
|
# ./docs/docker/build-and-export-images.sh
|
||||||
|
# ./build-and-export-images.sh --use-cache
|
||||||
|
# ./build-and-export-images.sh --export-only
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||||
|
cd "$ROOT"
|
||||||
|
|
||||||
|
COMPOSE_FILE="docker-compose.prod.yml"
|
||||||
|
ENV_FILE=".env.docker"
|
||||||
|
OUTPUT="thebet365-images.tar"
|
||||||
|
SERVICES=(api player admin)
|
||||||
|
NO_CACHE=1
|
||||||
|
EXPORT_ONLY=0
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<'EOF'
|
||||||
|
用法: docs/docker/build-and-export-images.sh [选项]
|
||||||
|
|
||||||
|
选项:
|
||||||
|
--use-cache 构建时使用 Docker 缓存(默认 --no-cache)
|
||||||
|
--export-only 跳过构建,仅导出已有 latest 镜像
|
||||||
|
--output PATH 导出文件路径(默认项目根目录 thebet365-images.tar)
|
||||||
|
-h, --help 显示帮助
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--use-cache) NO_CACHE=0; shift ;;
|
||||||
|
--export-only) EXPORT_ONLY=1; shift ;;
|
||||||
|
--output)
|
||||||
|
OUTPUT="${2:?缺少 --output 参数值}"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
*) echo "未知参数: $1" >&2; usage; exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ! -f "$COMPOSE_FILE" ]]; then
|
||||||
|
echo "错误: 未找到 $COMPOSE_FILE(目录: $ROOT)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$ENV_FILE" ]]; then
|
||||||
|
if [[ -f ".env.docker.example" ]]; then
|
||||||
|
echo "警告: 未找到 $ENV_FILE,将使用 .env.docker.example(生产部署请复制为 .env.docker 并修改密钥)"
|
||||||
|
ENV_FILE=".env.docker.example"
|
||||||
|
else
|
||||||
|
echo "错误: 未找到 $ENV_FILE 或 .env.docker.example" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$EXPORT_ONLY" -eq 0 ]]; then
|
||||||
|
echo "==> 构建镜像: ${SERVICES[*]}"
|
||||||
|
BUILD_ARGS=(compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" build)
|
||||||
|
if [[ "$NO_CACHE" -eq 1 ]]; then
|
||||||
|
BUILD_ARGS+=(--no-cache)
|
||||||
|
fi
|
||||||
|
BUILD_ARGS+=("${SERVICES[@]}")
|
||||||
|
docker "${BUILD_ARGS[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
OUTPUT_PATH="$OUTPUT"
|
||||||
|
if [[ "$OUTPUT" != /* ]] && [[ "$OUTPUT" != [A-Za-z]:* ]]; then
|
||||||
|
OUTPUT_PATH="$ROOT/$OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> 导出镜像 -> $OUTPUT_PATH"
|
||||||
|
docker save \
|
||||||
|
thebet365-api:latest \
|
||||||
|
thebet365-player:latest \
|
||||||
|
thebet365-admin:latest \
|
||||||
|
-o "$OUTPUT_PATH"
|
||||||
|
|
||||||
|
if command -v du >/dev/null 2>&1; then
|
||||||
|
SIZE="$(du -h "$OUTPUT_PATH" | awk '{print $1}')"
|
||||||
|
echo "完成: $OUTPUT_PATH ($SIZE)"
|
||||||
|
else
|
||||||
|
echo "完成: $OUTPUT_PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat <<'EOF'
|
||||||
|
|
||||||
|
服务器加载:
|
||||||
|
docker load -i thebet365-images.tar
|
||||||
|
docker compose -f docker-compose.prod.yml --env-file .env.docker up -d
|
||||||
|
EOF
|
||||||
202
docs/docker/镜像构建与导出.md
Normal file
202
docs/docker/镜像构建与导出.md
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
# Docker 镜像构建与导出
|
||||||
|
|
||||||
|
本文档说明如何在本地或 CI 机器上**构建** `api` / `player` / `admin` 三个生产镜像,并**导出**为 tar 包,便于上传到服务器离线加载部署。
|
||||||
|
|
||||||
|
> 全栈部署流程见上级文档:[Docker部署指南.md](../Docker部署指南.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、脚本位置
|
||||||
|
|
||||||
|
脚本与本文档同目录 `docs/docker/`:
|
||||||
|
|
||||||
|
| 文件 | 适用环境 |
|
||||||
|
|------|----------|
|
||||||
|
| `docs/docker/build-and-export-images.ps1` | Windows(PowerShell) |
|
||||||
|
| `docs/docker/build-and-export-images.sh` | Linux / macOS / Git Bash |
|
||||||
|
|
||||||
|
两个脚本行为一致:在**项目根目录**执行 compose 构建 → 导出为根目录下的 `thebet365-images.tar`(默认)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、前置条件
|
||||||
|
|
||||||
|
1. 已安装 **Docker** 与 **Docker Compose v2**(`docker compose`)
|
||||||
|
2. 项目根目录存在 `docker-compose.prod.yml`
|
||||||
|
3. 环境变量文件(二选一):
|
||||||
|
- **推荐**:`.env.docker`(从 `.env.docker.example` 复制并修改)
|
||||||
|
- 若无 `.env.docker`,脚本会回退使用 `.env.docker.example` 并给出警告
|
||||||
|
|
||||||
|
生产环境务必在 `.env.docker` 中配置:
|
||||||
|
|
||||||
|
- `POSTGRES_PASSWORD`、`JWT_SECRET`
|
||||||
|
- `CHUANGLAN_ACCOUNT`、`CHUANGLAN_PASSWORD`(短信注册)
|
||||||
|
- `SEED_DATABASE`(首次 `true`,灌完数据后改 `false`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、使用方法
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
|
||||||
|
在项目根目录打开 PowerShell:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\docs\docker\build-and-export-images.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linux / Git Bash
|
||||||
|
|
||||||
|
在项目根目录:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod +x docs/docker/build-and-export-images.sh
|
||||||
|
./docs/docker/build-and-export-images.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### 可选参数
|
||||||
|
|
||||||
|
| PowerShell | Bash | 说明 |
|
||||||
|
|------------|------|------|
|
||||||
|
| (默认) | (默认) | `--no-cache` 全量构建,适合发版 |
|
||||||
|
| `-UseCache` | `--use-cache` | 使用 Docker 缓存,构建更快 |
|
||||||
|
| `-ExportOnly` | `--export-only` | 跳过构建,仅导出已有 `latest` 镜像 |
|
||||||
|
| `-Output my.tar` | `--output my.tar` | 自定义导出文件名 |
|
||||||
|
|
||||||
|
示例:仅重新导出已有镜像
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\docs\docker\build-and-export-images.ps1 -ExportOnly
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./docs/docker/build-and-export-images.sh --export-only
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、构建产物
|
||||||
|
|
||||||
|
| 镜像名 | 说明 |
|
||||||
|
|--------|------|
|
||||||
|
| `thebet365-api:latest` | NestJS API(含 Prisma 迁移入口) |
|
||||||
|
| `thebet365-player:latest` | 玩家前台(Nginx 静态资源) |
|
||||||
|
| `thebet365-admin:latest` | 管理后台(Nginx 静态资源) |
|
||||||
|
|
||||||
|
导出文件默认路径:
|
||||||
|
|
||||||
|
```text
|
||||||
|
<项目根目录>/thebet365-images.tar
|
||||||
|
```
|
||||||
|
|
||||||
|
该文件已加入 `.gitignore`,**请勿提交到 Git**。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、上传到服务器并加载
|
||||||
|
|
||||||
|
### 1. 上传
|
||||||
|
|
||||||
|
将以下内容传到服务器同一目录(如 `/www/wwwroot/thebet365`):
|
||||||
|
|
||||||
|
- `thebet365-images.tar`
|
||||||
|
- `docker-compose.prod.yml`
|
||||||
|
- `.env.docker`(或服务器上已有配置)
|
||||||
|
- `docker/nginx/` 等 compose 依赖目录(若仅 load 镜像、不 rebuild,compose 文件仍需要)
|
||||||
|
|
||||||
|
可用 SCP、宝塔文件管理、rsync 等。
|
||||||
|
|
||||||
|
### 2. 加载镜像
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /www/wwwroot/thebet365
|
||||||
|
docker load -i thebet365-images.tar
|
||||||
|
```
|
||||||
|
|
||||||
|
确认镜像:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker images | grep thebet365
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 启动服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose -f docker-compose.prod.yml --env-file .env.docker up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
API 容器启动时会自动执行 `prisma migrate deploy`,一般无需手动迁移。
|
||||||
|
|
||||||
|
### 4. 验证
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose -f docker-compose.prod.yml ps
|
||||||
|
docker logs thebet365-api --tail 50
|
||||||
|
```
|
||||||
|
|
||||||
|
浏览器访问(端口以 `.env.docker` 为准):
|
||||||
|
|
||||||
|
- 玩家端:`http://服务器IP:8082`
|
||||||
|
- 管理端:`http://服务器IP:8081`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、与「服务器上直接 build」的区别
|
||||||
|
|
||||||
|
| 方式 | 优点 | 缺点 |
|
||||||
|
|------|------|------|
|
||||||
|
| **本地 build + 导出 tar** | 不占用服务器 CPU/内存;可重复部署同一包 | 需上传较大 tar(约 200–300 MB) |
|
||||||
|
| **服务器 `docker compose build`** | 无需传 tar | 首次/全量构建慢,小内存机器易失败 |
|
||||||
|
|
||||||
|
发版推荐流程:**本地或构建机执行脚本 → 上传 tar → 服务器 `docker load` → `up -d`**。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、常见问题
|
||||||
|
|
||||||
|
### 1. 构建时提示 `CHUANGLAN_* variable is not set`
|
||||||
|
|
||||||
|
仅为 **警告**,不影响镜像构建;运行时请在 `.env.docker` 中补全创蓝配置,否则短信验证码无法发送。
|
||||||
|
|
||||||
|
### 2. player / admin 构建失败 `ENOENT ... public/球员`
|
||||||
|
|
||||||
|
旧包残留中文目录。清理后重试:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
find packages/shared/public -mindepth 1 -maxdepth 1 -type d \
|
||||||
|
! -name flags ! -name players -exec rm -rf {} +
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. `docker load` 后 `up -d` 仍拉取或重建镜像
|
||||||
|
|
||||||
|
确保 compose 中 `image` 与 load 的 tag 一致(`thebet365-api:latest` 等),且使用同一 `docker-compose.prod.yml`。
|
||||||
|
|
||||||
|
### 4. API 启动后不断重启
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker logs thebet365-api
|
||||||
|
```
|
||||||
|
|
||||||
|
常见原因:数据库未就绪、`DATABASE_URL` 与 `POSTGRES_PASSWORD` 不一致、迁移失败。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 八、相关文件
|
||||||
|
|
||||||
|
```text
|
||||||
|
thebet365/
|
||||||
|
├── docker-compose.prod.yml
|
||||||
|
├── .env.docker.example
|
||||||
|
├── thebet365-images.tar # 导出产物(默认,已 gitignore)
|
||||||
|
├── docker/
|
||||||
|
│ ├── api/Dockerfile
|
||||||
|
│ ├── player/Dockerfile
|
||||||
|
│ ├── admin/Dockerfile
|
||||||
|
│ └── nginx/
|
||||||
|
└── docs/
|
||||||
|
├── Docker部署指南.md
|
||||||
|
└── docker/
|
||||||
|
├── 镜像构建与导出.md # 本文档
|
||||||
|
├── build-and-export-images.ps1
|
||||||
|
└── build-and-export-images.sh
|
||||||
|
```
|
||||||
213
docs/短信调试与日志说明.md
Normal file
213
docs/短信调试与日志说明.md
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
# 短信验证码调试与日志说明
|
||||||
|
|
||||||
|
本文档说明 thebet365 **玩家端短信验证码**(注册 / 找回密码)在后端的日志行为,以及如何与创蓝控制台对账、排查「收不到码」问题。
|
||||||
|
|
||||||
|
相关代码:`apps/api/src/domains/identity/sms/`
|
||||||
|
创蓝接入总览见 [chuanglan-sms-js-guide.md](./chuanglan-sms-js-guide.md)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、整体流程
|
||||||
|
|
||||||
|
```text
|
||||||
|
玩家端 POST /api/player/sms/send
|
||||||
|
→ SmsService 生成 6 位验证码
|
||||||
|
→ 拼短信正文,调用创蓝 API(uid = sessionId)
|
||||||
|
→ 验证码写入 Redis:sms:code:{sessionId}(默认 5 分钟)
|
||||||
|
|
||||||
|
玩家注册 / 找回密码
|
||||||
|
→ POST 携带 phone、sessionId、smsCode
|
||||||
|
→ SmsService.verifyCode 校验 Redis 后删除
|
||||||
|
```
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| `sessionId` | 后端生成的 UUID,作为创蓝请求的 `uid`,**对应创蓝控制台「批次号」** |
|
||||||
|
| `messageId` | 创蓝返回的发送 ID,出现在成功日志中 |
|
||||||
|
| 验证码 | 仅存于 Redis 与发信正文,**默认不写入 Docker 日志** |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、环境变量
|
||||||
|
|
||||||
|
在 `.env.docker`(或本地 API 的 `.env`)中配置:
|
||||||
|
|
||||||
|
| 变量 | 默认值 | 说明 |
|
||||||
|
|------|--------|------|
|
||||||
|
| `CHUANGLAN_ACCOUNT` | — | 创蓝账号(必填) |
|
||||||
|
| `CHUANGLAN_PASSWORD` | — | 创蓝密码(必填) |
|
||||||
|
| `CHUANGLAN_ENDPOINT` | `https://sgap.253.com/send/sms` | 国际短信网关 |
|
||||||
|
| `SMS_CODE_TTL_SECONDS` | `300` | 验证码 Redis 有效期(秒) |
|
||||||
|
| `SMS_RATE_LIMIT_SECONDS` | `60` | 同一手机号 / IP 发码冷却(秒) |
|
||||||
|
| `SMS_DEBUG_LOG_CODE` | `false` | **联调专用**:为 `true` 时在日志输出验证码明文 |
|
||||||
|
|
||||||
|
`docker-compose.prod.yml` 已将 `SMS_DEBUG_LOG_CODE` 传入 `thebet365-api` 容器。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、常规日志(生产推荐)
|
||||||
|
|
||||||
|
`SMS_DEBUG_LOG_CODE=false` 时,API 会记录短信链路,但**不打印验证码**,手机号仅保留末 4 位(如 `****1234`)。
|
||||||
|
|
||||||
|
### 3.1 查看方式
|
||||||
|
|
||||||
|
**SSH(推荐):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker logs -f thebet365-api 2>&1 | grep -E 'SMS|Chuanglan|Player registered|Password reset'
|
||||||
|
```
|
||||||
|
|
||||||
|
**宝塔:** 容器 `thebet365-api` → **容器日志** → 搜索 `SMS` 或 `Chuanglan`。若显示「暂无日志」,优先用上面 `docker logs` 命令;面板偶发读不到 Docker 日志。
|
||||||
|
|
||||||
|
### 3.2 日志含义
|
||||||
|
|
||||||
|
| 日志前缀 / 关键字 | 级别 | 含义 |
|
||||||
|
|-------------------|------|------|
|
||||||
|
| `SMS send request purpose=...` | log | 收到发码请求 |
|
||||||
|
| `SMS rate limited` | warn | 触发频控(手机号或 IP) |
|
||||||
|
| `SMS reset_password blocked reason=...` | warn | 找回密码前置校验失败 |
|
||||||
|
| `Chuanglan request` | log | 已向创蓝发起 HTTP 请求 |
|
||||||
|
| `Chuanglan success` | log | 创蓝受理成功(含 `messageId`) |
|
||||||
|
| `Chuanglan rejected` | warn | 创蓝返回业务错误码 |
|
||||||
|
| `Chuanglan HTTP error` | error | 网络超时或 HTTP 异常 |
|
||||||
|
| `SMS sent` | log | 发码完成并已写入 Redis |
|
||||||
|
| `SMS send failed` | error | 创蓝失败,前端收到 `SMS_SEND_FAILED` |
|
||||||
|
| `SMS verify request / success / failed` | log / warn | 验码过程 |
|
||||||
|
| `Player registered` | log | 注册成功(已通过验码) |
|
||||||
|
| `Password reset by phone` | log | 短信找回密码成功 |
|
||||||
|
|
||||||
|
`session=abc12345…` 为 `sessionId` 前 8 位,便于与创蓝批次号前缀对照。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、调试模式(输出验证码)
|
||||||
|
|
||||||
|
联调或排查「创蓝有记录、手机没收到」时,可临时开启:
|
||||||
|
|
||||||
|
```env
|
||||||
|
SMS_DEBUG_LOG_CODE=true
|
||||||
|
```
|
||||||
|
|
||||||
|
修改 `.env.docker` 后重启 API:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /www/wwwroot/thebet365 # 按实际路径
|
||||||
|
docker compose -f docker-compose.prod.yml --env-file .env.docker up -d api
|
||||||
|
```
|
||||||
|
|
||||||
|
若代码有更新,需先重新构建并加载 API 镜像再执行上述命令。
|
||||||
|
|
||||||
|
### 4.1 调试日志格式
|
||||||
|
|
||||||
|
每次发码会多一行 **warn** 级别日志:
|
||||||
|
|
||||||
|
```text
|
||||||
|
[SmsService] [SMS_DEBUG] purpose=register phone=0088613812345678 sessionId=ed08fe51-e9b7-4fec-9381-8249f4c65f4b code=123456 content=您的验证码是:123456。5分钟内有效。
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 与创蓝控制台对照
|
||||||
|
|
||||||
|
| 后端 `[SMS_DEBUG]` 字段 | 创蓝控制台列 |
|
||||||
|
|-------------------------|--------------|
|
||||||
|
| `sessionId` | **批次号** |
|
||||||
|
| `phone` | **手机号** |
|
||||||
|
| `code` / `content` | **发送内容** |
|
||||||
|
| 常规日志 `messageId` | 发送详情中的 messageId |
|
||||||
|
|
||||||
|
筛选调试行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker logs -f thebet365-api 2>&1 | grep SMS_DEBUG
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.3 安全提醒
|
||||||
|
|
||||||
|
- **生产环境务必保持 `SMS_DEBUG_LOG_CODE=false`**,否则验证码会留在 Docker 日志中。
|
||||||
|
- 调试结束后改回 `false` 并重启 API。
|
||||||
|
- 不要将含 `[SMS_DEBUG]` 的日志片段对外分享。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、从 Redis 读取验证码(可选)
|
||||||
|
|
||||||
|
发码接口返回的 `sessionId` 有效期内,可直接查 Redis:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec thebet365-redis redis-cli GET "sms:code:完整的sessionId"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回示例:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"phone":"0088613812345678","code":"123456","purpose":"register"}
|
||||||
|
```
|
||||||
|
|
||||||
|
列出当前未过期的 key(key 带 TTL,验码或过期后会消失):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec thebet365-redis redis-cli KEYS "sms:code:*"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、常见问题
|
||||||
|
|
||||||
|
### 6.1 创蓝显示「接收失败 / UNDELIV」
|
||||||
|
|
||||||
|
表示创蓝已提交,但**运营商未送达终端**。常见原因:
|
||||||
|
|
||||||
|
- 号码格式或国家码不正确(国际号需与创蓝侧开通路由一致)
|
||||||
|
- 目标地区/运营商拦截或关机、空号
|
||||||
|
- 短信内容或发送频率触发运营商过滤
|
||||||
|
|
||||||
|
后端若已有 `Chuanglan success` + `SMS sent`,说明 **API 与创蓝侧发送正常**,需从号码与运营商侧继续排查。
|
||||||
|
|
||||||
|
### 6.2 日志里完全没有 `SMS` / `Chuanglan`
|
||||||
|
|
||||||
|
1. 确认请求是否打到 API(Nginx 是否将 `/api` 反代到 `thebet365-api:3000`)。
|
||||||
|
2. 确认运行的是**包含短信日志的新版 API 镜像**。
|
||||||
|
3. 用 `docker logs thebet365-api --tail 200` 查看,不要仅依赖宝塔面板。
|
||||||
|
|
||||||
|
### 6.3 创蓝控制台有记录,后端没有 `[SMS_DEBUG]`
|
||||||
|
|
||||||
|
- 检查 `.env.docker` 是否 `SMS_DEBUG_LOG_CODE=true`。
|
||||||
|
- 重启后是否加载了新环境变量:`docker exec thebet365-api printenv SMS_DEBUG_LOG_CODE`。
|
||||||
|
|
||||||
|
### 6.4 发码太频繁
|
||||||
|
|
||||||
|
日志会出现 `SMS rate limited`。默认同一手机号 60 秒内只能发一次,可在 `.env.docker` 调整 `SMS_RATE_LIMIT_SECONDS`(生产不建议设过小)。
|
||||||
|
|
||||||
|
### 6.5 找回密码发码失败
|
||||||
|
|
||||||
|
关注 `SMS reset_password blocked reason=`:
|
||||||
|
|
||||||
|
| reason | 含义 |
|
||||||
|
|--------|------|
|
||||||
|
| `phone_not_registered` | 手机号未注册玩家 |
|
||||||
|
| `account_disabled` | 账号已禁用 |
|
||||||
|
| `password_change_disabled` | 系统配置禁止改密 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、相关 API
|
||||||
|
|
||||||
|
| 方法 | 路径 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| POST | `/api/player/sms/send` | 发验证码,`purpose`: `register`(默认)或 `reset_password` |
|
||||||
|
| POST | `/api/player/auth/register` | 注册,需 `sessionId` + `smsCode` |
|
||||||
|
| POST | `/api/player/auth/forgot-password` | 找回密码,需 `sessionId` + `smsCode` |
|
||||||
|
|
||||||
|
Swagger(API 容器启动后):`http://<主机>:3000/api/docs`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 八、检查清单
|
||||||
|
|
||||||
|
联调短信时建议按序确认:
|
||||||
|
|
||||||
|
- [ ] `.env.docker` 中 `CHUANGLAN_ACCOUNT` / `CHUANGLAN_PASSWORD` 正确
|
||||||
|
- [ ] 需要看验证码时 `SMS_DEBUG_LOG_CODE=true`,上线前改回 `false`
|
||||||
|
- [ ] `docker logs` 能看到 `Chuanglan success` 与 `SMS sent`
|
||||||
|
- [ ] 创蓝批次号与日志 `sessionId` 一致
|
||||||
|
- [ ] 若创蓝为 `DELIVRD` 仍收不到,检查手机拦截 / 地区路由
|
||||||
|
- [ ] 若创蓝为 `UNDELIV`,优先排查号码与运营商,而非后端代码
|
||||||
129
packages/shared/public/tawk.html
Normal file
129
packages/shared/public/tawk.html
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Tawk.to Container</title>
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://embed.tawk.to">
|
||||||
|
<link rel="dns-prefetch" href="https://embed.tawk.to">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body,
|
||||||
|
html {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: linear-gradient(180deg, #15120A 0%, #0A0A16 100%);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tawk-container {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#loading-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: linear-gradient(180deg, #15120A 0%, #0A0A16 100%);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 1rem;
|
||||||
|
z-index: 9999;
|
||||||
|
transition: opacity 0.3s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
#loading-overlay.hidden {
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
border: 2px solid rgba(200, 168, 78, 0.3);
|
||||||
|
border-top-color: #c8a84e;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.8s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-text {
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
font-size: 14px;
|
||||||
|
font-family: system-ui, -apple-system, sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="loading-overlay">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<div class="loading-text">正在连接客服...</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="tawk-container"></div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const visitorName = urlParams.get('name') || '';
|
||||||
|
const visitorAvatar = urlParams.get('avatar') || '';
|
||||||
|
const visitorId = urlParams.get('id') || '';
|
||||||
|
const loadingText = urlParams.get('loadingText') || '正在连接客服...';
|
||||||
|
|
||||||
|
const loadingTextElement = document.querySelector('.loading-text');
|
||||||
|
if (loadingTextElement) {
|
||||||
|
loadingTextElement.textContent = loadingText;
|
||||||
|
}
|
||||||
|
|
||||||
|
var Tawk_API = Tawk_API || {};
|
||||||
|
var Tawk_LoadStart = new Date();
|
||||||
|
|
||||||
|
Tawk_API.embedded = 'tawk-container';
|
||||||
|
|
||||||
|
if (visitorName) {
|
||||||
|
Tawk_API.visitor = {
|
||||||
|
name: visitorName,
|
||||||
|
email: visitorId ? visitorId + '@user.com' : undefined
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Tawk_API.onLoad = function () {
|
||||||
|
const loadingOverlay = document.getElementById('loading-overlay');
|
||||||
|
if (loadingOverlay) {
|
||||||
|
loadingOverlay.classList.add('hidden');
|
||||||
|
setTimeout(function () {
|
||||||
|
loadingOverlay.style.display = 'none';
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visitorAvatar || visitorId) {
|
||||||
|
try {
|
||||||
|
Tawk_API.setAttributes({
|
||||||
|
avatar: visitorAvatar || undefined,
|
||||||
|
userId: visitorId || undefined
|
||||||
|
}, function () { });
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
var s1 = document.createElement('script'), s0 = document.getElementsByTagName('script')[0];
|
||||||
|
s1.async = true;
|
||||||
|
s1.src = 'https://embed.tawk.to/6a2b9dc1f0b5881c2ac3ed83/1jqt60fto';
|
||||||
|
s1.charset = 'UTF-8';
|
||||||
|
s1.setAttribute('crossorigin', '*');
|
||||||
|
s0.parentNode.insertBefore(s1, s0);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user