Skip to content

Commit fffa123

Browse files
committed
chore: aliyun identitfy
1 parent a409d06 commit fffa123

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

src/config/config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ export const redis = {
5454
export const sms = {
5555
provider: loadEnv('SMS_PROVIDER', { default: 'aliyun' }),
5656
aliyun: {
57-
keyId: loadEnv('ALIYUN_SMS_KEY_ID'),
58-
keySecret: loadEnv('ALIYUN_SMS_KEY_SECRET'),
57+
keyId: loadEnv('ALIYUN_KEY'),
58+
keySecret: loadEnv('ALIYUN_SECRET'),
5959
},
6060
volcengine: {
6161
account: loadEnv('VOLCENGINE_SMS_ACCOUNT'), // 消息组 ID
62-
accessKeyId: loadEnv('VOLCENGINE_SMS_ACCESS_KEY_ID'),
63-
secretKey: loadEnv('VOLCENGINE_SMS_SECRET_KEY'),
62+
accessKeyId: loadEnv('VOLCENGINE_KEY'),
63+
secretKey: loadEnv('VOLCENGINE_SECRET'),
6464
},
6565
};
6666

6767
export const user = {
6868
identityVerify: {
69-
appCode: 'appCode',
69+
appCode: loadEnv('IDENTITY_VERIFY_APP_CODE'),
7070
},
7171
};
7272

src/user/verify-identity.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
import axios from 'axios';
2-
import { get } from 'lodash';
32

43
import * as config from 'src/config';
54

6-
const results = {
7-
400: '400 参数不能为空',
8-
401: '401 参数非法',
9-
402: '402 无权限调用',
10-
403: '403 异常重复调用',
11-
500: '系统错误',
12-
};
13-
145
export async function verifyIdentity(name: string, identity: string): Promise<boolean> {
15-
const response = await axios.get('http://id2meta.market.alicloudapi.com/id2meta', {
6+
const response = await axios.get('https://zidv2.market.alicloudapi.com/idcard/VerifyIdcardv2', {
167
params: {
17-
userName: name,
18-
identifyNum: identity,
8+
realName: name,
9+
cardNo: identity,
1910
},
2011
headers: {
2112
Authorization: `APPCODE ${config.user.identityVerify.appCode}`,
2213
},
2314
});
2415

25-
if (!response.data?.code) {
26-
throw new Error('没有返回 code');
16+
const { error_code, reason, result } = response.data ?? {};
17+
18+
if (error_code === undefined) {
19+
throw new Error('没有返回 error_code');
2720
}
2821

29-
if (response.data.code !== '200') {
30-
throw new Error(results[response.data.code] || '未知错误');
22+
if (error_code !== 0) {
23+
throw new Error(reason || '未知错误');
3124
}
3225

33-
return get(response.data, 'data.bizCode') === '1';
26+
return result?.isok === true;
3427
}

0 commit comments

Comments
 (0)