Ver código fonte

refactor(rcs-number): 重构获取手机码接口逻辑

- 注释掉缓存相关的代码,暂时不使用缓存功能
- 修改请求参数 num 从 10 改为 1,以适应新的接口要求
- 简化对返回数据的处理逻辑,直接使用 res.data.data
wuyi 1 ano atrás
pai
commit
4375844b5c
1 arquivos alterados com 18 adições e 26 exclusões
  1. 18 26
      src/rcs-number/impl/durian.service.ts

+ 18 - 26
src/rcs-number/impl/durian.service.ts

@@ -45,22 +45,22 @@ export class durian extends GetNumberService {
 
     async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
         // 缓存中是否有值
-        const resString = await this.redis.rpop(`durian_${country.toUpperCase()}`)
-        let cacheRes = resString ? JSON.parse(resString) : null
-        let attempts = 0
-        while (
-            cacheRes !== null &&
-            new Date(cacheRes.expiryTime).getTime() - 120000 < new Date().getTime() &&
-            attempts < 20
-        ) {
-            attempts++
-            const newVar = await this.redis.rpop(`durian_${country.toUpperCase()}`)
-            cacheRes = newVar ? JSON.parse(newVar) : null
-        }
-        if (cacheRes !== null) {
-            Logger.log(`${country.toUpperCase()} - ${cacheRes.source}\t Get the number from the cache`, 'GetNumber')
-            return cacheRes
-        }
+        // const resString = await this.redis.rpop(`durian_${country.toUpperCase()}`)
+        // let cacheRes = resString ? JSON.parse(resString) : null
+        // let attempts = 0
+        // while (
+        //     cacheRes !== null &&
+        //     new Date(cacheRes.expiryTime).getTime() - 120000 < new Date().getTime() &&
+        //     attempts < 20
+        // ) {
+        //     attempts++
+        //     const newVar = await this.redis.rpop(`durian_${country.toUpperCase()}`)
+        //     cacheRes = newVar ? JSON.parse(newVar) : null
+        // }
+        // if (cacheRes !== null) {
+        //     Logger.log(`${country.toUpperCase()} - ${cacheRes.source}\t Get the number from the cache`, 'GetNumber')
+        //     return cacheRes
+        // }
 
         const res = await durianInstance.get('getMobile', {
             params: {
@@ -68,7 +68,7 @@ export class durian extends GetNumberService {
                 ApiKey: ApiKey1,
                 cuy: country.toUpperCase(),
                 pid,
-                num: 10,
+                num: 1,
                 noblack: 1,
                 serial: 2
             }
@@ -76,15 +76,7 @@ export class durian extends GetNumberService {
         if (res.data.code !== 200) {
             throw new InternalServerErrorException(res.data.msg)
         }
-        const numbers = res.data.data
-        let number
-        // 判断numbers是否是数组
-        if (!Array.isArray(numbers)) {
-            number = numbers[0]
-        } else {
-            number = numbers
-        }
-
+        const number = res.data.data
         // const imsiRes = await durianInstance.get('getMobileUserCode', {
         //     params: {
         //         name,