微信SDK接通

This commit is contained in:
2026-07-01 19:56:44 +08:00
parent a1cbfc7241
commit aea1513836
38 changed files with 1610 additions and 92 deletions
@@ -1,5 +1,6 @@
import { Module } from '@nestjs/common';
import { IamModule } from '../iam/iam.module';
import { IntegrationsModule } from '../../integrations/integrations.module';
import { ResourceService } from './resource.service';
import { EventService } from './event.service';
import { TicketService } from './ticket.service';
@@ -8,10 +9,11 @@ import { ResourceController } from './resource.controller';
import { EventController } from './event.controller';
import { TicketController } from './ticket.controller';
import { ThirdPartyLogController } from './third-party-log.controller';
import { WechatController } from './wechat.controller';
@Module({
imports: [IamModule],
controllers: [ResourceController, EventController, TicketController, ThirdPartyLogController],
imports: [IamModule, IntegrationsModule],
controllers: [ResourceController, EventController, TicketController, ThirdPartyLogController, WechatController],
providers: [ResourceService, EventService, TicketService, ThirdPartyLogService],
exports: [ResourceService, EventService, TicketService],
})
@@ -0,0 +1,43 @@
import { BadRequestException, Body, Controller, Get, Inject, Post, Query } from '@nestjs/common';
import { IsIn, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { WECHAT_PROVIDER } from '../../integrations/integrations.constants';
import type { IWechatProvider } from '../../integrations/wechat/wechat.interface';
class PhoneNumberDto {
@IsString()
@IsNotEmpty()
code: string;
@IsString()
@IsIn(['mini', 'h5'])
@IsOptional()
platform?: 'mini' | 'h5';
}
@Controller('common/wechat')
export class WechatController {
constructor(@Inject(WECHAT_PROVIDER) private readonly wechat: IWechatProvider) {}
@Get('jssdk-config')
async jssdkConfig(@Query('url') url: string) {
if (!url) throw new BadRequestException('url 参数必填');
return this.wechat.createJssdkConfig(url);
}
@Get('oauth-url')
oauthUrl(
@Query('redirectUri') redirectUri: string,
@Query('state') state: string,
@Query('scope') scope?: string,
) {
if (!redirectUri || !state) throw new BadRequestException('redirectUri 与 state 必填');
return { url: this.wechat.buildOAuthUrl(redirectUri, state, scope) };
}
@Post('phone-number')
phoneNumber(@Body() dto: PhoneNumberDto) {
return this.wechat
.getPhoneNumberByCode(dto.code, dto.platform ?? 'mini')
.then((phone) => ({ phone }));
}
}