ソースを参照

feat(rcs-number): 新增 smspva 通道支持

wui 1 年間 前
コミット
dc37ccf53f

+ 2 - 1
src/rcs-number/entities/rcs-number.entity.ts

@@ -31,7 +31,8 @@ export enum RcsNumberSource {
     durainus = 'durainus',
     textverified = 'textverified',
     usapanel = 'usapanel',
-    dashboard = 'dashboard'
+    dashboard = 'dashboard',
+    smspva = 'smspva'
 }
 
 @Entity()

+ 65 - 0
src/rcs-number/impl/smspva.service.ts

@@ -0,0 +1,65 @@
+import { GetNumberResponse, GetNumberService } from './get-number-service'
+import { RcsNumberSource } from '../entities/rcs-number.entity'
+import axios from 'axios'
+import { InternalServerErrorException } from '@nestjs/common'
+
+const API_KEY = 'uNW56fGr0zstfs87Xn0e1l2gCYVnb1'
+const SERVICE = 'opt259'
+
+const axiosInstance = axios.create({
+    baseURL: 'https://api.smspva.com/activation/'
+})
+
+const countryMap = {
+    US: 'US',
+    GB: 'UK',
+    BR: 'BR'
+}
+
+export class smspva extends GetNumberService {
+    source: RcsNumberSource = RcsNumberSource.smspva
+
+    async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
+        const countryCode = countryMap[country]
+        if (!countryCode) {
+            throw new Error('No available country')
+        }
+        const res = await axiosInstance.get(`number/${country}/${SERVICE}`, {
+            headers: {
+                apikey: API_KEY
+            }
+        })
+
+        if (res.data.statusCode !== 200) {
+            throw new InternalServerErrorException(res.data.error.description)
+        }
+
+        return {
+            number: res.data.data.phoneNumber,
+            orderId: res.data.data.orderId,
+            operatorCode: '',
+            operatorName: '',
+            rawResponse: res.data
+        }
+    }
+
+    async releaseNumber(number: string) {}
+
+    async retriveMessage(orderId: string, num?: number): Promise<string> {
+        const res = await axiosInstance.get(`sms/${Number(orderId)}`, {
+            headers: {
+                apikey: API_KEY
+            }
+        })
+
+        if (res.data.statusCode === 200) {
+            return res.data.data.sms.fullText
+        }
+    }
+
+    async blockNumber(number: string) {}
+
+    async cacheNumber(country: string, size: number) {
+        return null
+    }
+}

+ 3 - 1
src/rcs-number/rcs-number.module.ts

@@ -23,6 +23,7 @@ import { SysConfigModule } from 'src/sys-config/sys-config.module'
 import { usapanel } from './impl/usapanel.service'
 import { textverified } from './impl/textverified.service'
 import { dashboard } from './impl/dashboard.service'
+import { smspva } from './impl/smspva.service'
 
 @Module({
     imports: [
@@ -48,7 +49,8 @@ import { dashboard } from './impl/dashboard.service'
         durainus,
         usapanel,
         textverified,
-        dashboard
+        dashboard,
+        smspva
     ],
     controllers: [RcsNumberController],
     exports: [RcsNumberService]

+ 5 - 1
src/rcs-number/rcs-number.service.ts

@@ -33,6 +33,7 @@ import { Channel } from '../channel/entities/channel.entities'
 import { durainus } from './impl/durainus.service'
 import { usapanel } from './impl/usapanel.service'
 import { dashboard } from './impl/dashboard.service'
+import { smspva } from './impl/smspva.service'
 
 @Injectable()
 export class RcsNumberService {
@@ -70,6 +71,7 @@ export class RcsNumberService {
         private usapanel: usapanel,
         private textverified: textverified,
         private dashboard: dashboard,
+        private smspva: smspva,
         private readonly redisService: RedisService
     ) {
         this.cloud033 = new cloud214('100033', '1e40ca9795b1fc038db76512175d59b5', RcsNumberSource.cloud033)
@@ -315,6 +317,8 @@ export class RcsNumberService {
                 return this.usapanel
             case RcsNumberSource.dashboard:
                 return this.dashboard
+            case RcsNumberSource.smspva:
+                return this.smspva
             default:
                 throw new ServiceUnavailableException('不支持的短信通道')
         }
@@ -357,7 +361,7 @@ export class RcsNumberService {
                         } else if (number.orderId.slice(-4) === '0034') {
                             update.from = RcsNumberSource.cloud034
                         }
-                    } else if (number.from === RcsNumberSource.usacode) {
+                    } else if (number.from === RcsNumberSource.usapanel) {
                         await this.redis.del('usapanel')
                     }
                     await this.rcsNumberRepository.update(number.id, update)

+ 18 - 1
src/task/task.service.ts

@@ -39,6 +39,7 @@ import { Device } from '../device/entities/device.entity'
 import Decimal from 'decimal.js'
 import { CountryConfigService } from '../country-config/country-config.service'
 import { dashboard } from '../rcs-number/impl/dashboard.service'
+import { smspva } from '../rcs-number/impl/smspva.service'
 
 @Injectable()
 export class TaskService implements OnModuleInit {
@@ -688,7 +689,8 @@ export class TaskService implements OnModuleInit {
             xyz: 0,
             cowboy: 0,
             usapanel: 0,
-            dashboard: 0
+            dashboard: 0,
+            smspva: 0
         }
         const cloudInstance = axios.create({
             baseURL: 'http://52.77.17.214:9001/api/'
@@ -702,6 +704,9 @@ export class TaskService implements OnModuleInit {
         const dashboardInstance = axios.create({
             baseURL: 'https://code.smscodes.io/api/sms/'
         })
+        const smspvaInstance = axios.create({
+            baseURL: 'https://api.smspva.com/activation/'
+        })
         await Promise.all([
             (async () => {
                 try {
@@ -849,6 +854,18 @@ export class TaskService implements OnModuleInit {
                         res.dashboard = dashboardRes.data.Balance
                     }
                 } catch (e) {}
+            })(),
+            (async () => {
+                try {
+                    const smspvaRes = await smspvaInstance.get('balance', {
+                        headers: {
+                            apikey: 'uNW56fGr0zstfs87Xn0e1l2gCYVnb1'
+                        }
+                    })
+                    if (smspvaRes.data.statusCode === 200) {
+                        res.smspva = smspvaRes.data.data.balance
+                    }
+                } catch (e) {}
             })()
         ])
         return res