返回 AiToEarn
realAuth.service.ts
根目录 / project / aitoearn-electron / server / src / lib / realAuth / realAuth.service.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-04-27 06:41:31
4 * @LastEditTime: 2025-04-27 14:03:43
5 * @LastEditors: nevin
6 * @Description:
7 */
8 import Cloudauth20190307, * as $Cloudauth20190307 from '@alicloud/cloudauth20190307';
9 import * as $OpenApi from '@alicloud/openapi-client';
10 import * as $Util from '@alicloud/tea-util';
11 import { Injectable } from '@nestjs/common';
12 import { ConfigService } from '@nestjs/config';
13
14 @Injectable()
15 export class AlicloudRealAuthService {
16 private client: any;
17 constructor(private configService: ConfigService) {
18 const options: {
19 accessKeyId: string;
20 accessKeySecret: string;
21 } = this.configService.get('REAL_NAME_CONFIG');
22
23 const config = new $OpenApi.Config({
24 ...options,
25 });
26
27 config.endpoint = `cloudauth.cn-beijing.aliyuncs.com`;
28 this.client = new Cloudauth20190307(config);
29 }
30
31 /**
32 * 身份号认证
33 * @param identifyNum
34 * @param userName
35 */
36 public async realNameAuth(
37 identifyNum: string,
38 userName: string,
39 ): Promise<boolean> {
40 const id2MetaVerifyRequest = new $Cloudauth20190307.Id2MetaVerifyRequest({
41 paramType: 'normal',
42 identifyNum,
43 userName,
44 });
45 const runtime = new $Util.RuntimeOptions({});
46 try {
47 const res: {
48 body: {
49 code: string;
50 message: string;
51 requestId: string;
52 resultObject: {
53 bizCode: '1' | '2' | '3';
54 };
55 };
56 } = await this.client.id2MetaVerifyWithOptions(
57 id2MetaVerifyRequest,
58 runtime,
59 );
60
61 return res.body.resultObject.bizCode === '1';
62 } catch (error) {
63 console.log('----- realNameAuth error ------', error.message);
64
65 return false;
66 }
67 }
68 }
69
69 lines TYPESCRIPT