Просмотр исходного кода

feat(rcs-number): 新增 sms4verify 服务

wui 1 год назад
Родитель
Сommit
d09ff09e7b

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

@@ -4,6 +4,7 @@ import { Exclude } from 'class-transformer'
 import { durainus } from '../impl/durainus.service'
 import { dashboard } from '../impl/dashboard.service'
 import { sms7979 } from '../impl/sms7979.service'
+import { sms4verify } from '../impl/sms4verify.service'
 
 export enum RcsNumberStatus {
     PENDING = 'pending',
@@ -34,7 +35,9 @@ export enum RcsNumberSource {
     usapanel = 'usapanel',
     dashboard = 'dashboard',
     smspva = 'smspva',
-    sms7979 = 'sms7979'
+    sms7979 = 'sms7979',
+    sms4verify01 = 'sms4verify01',
+    sms4verify02 = 'sms4verify02'
 }
 
 @Entity()

+ 70 - 0
src/rcs-number/impl/sms4verify.service.ts

@@ -0,0 +1,70 @@
+import { RcsNumberSource } from '../entities/rcs-number.entity'
+import { GetNumberResponse, GetNumberService } from './get-number-service'
+import axios from 'axios'
+
+const service = 'googlemessenger'
+
+const axiosInstance = axios.create({
+    baseURL: 'https://sms4verify.com/stubs/'
+})
+
+export class sms4verify extends GetNumberService {
+    source: RcsNumberSource
+
+    apikey: string
+
+    constructor(apikey: string, source: RcsNumberSource) {
+        super()
+        this.apikey = apikey
+        this.source = source
+    }
+
+    async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
+        if (country !== 'US') {
+            throw new Error(`Platform ${this.source} only support US.`)
+        }
+        const res = await axiosInstance.get('handler_api.php', {
+            params: {
+                api_key: this.apikey,
+                action: 'getNumber',
+                service: service
+            }
+        })
+
+        const data = res.data
+        const split = data.split(':')
+        if (split[0] !== 'ACCESS_NUMBER') {
+            throw new Error(`Platform ${this.source} get number error: ${data}`)
+        }
+
+        return {
+            number: split[2],
+            orderId: split[1],
+            operatorCode: '',
+            operatorName: '',
+            rawResponse: data
+        }
+    }
+
+    async retriveMessage(orderId: string, num?: number): Promise<string> {
+        const res = await axiosInstance.get('handler_api.php', {
+            params: {
+                api_key: this.apikey,
+                action: 'getStatus',
+                id: orderId
+            }
+        })
+        const data = res.data.split(':')
+        if (data[0] === 'STATUS_OK') {
+            return `Your Messenger verification code is G-${data[1]}`
+        }
+    }
+
+    async releaseNumber(number: string): Promise<void> {}
+
+    async blockNumber(number: string): Promise<void> {}
+
+    async cacheNumber(country: string, size: number): Promise<GetNumberResponse[]> {
+        return null
+    }
+}

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

@@ -25,6 +25,7 @@ import { textverified } from './impl/textverified.service'
 import { dashboard } from './impl/dashboard.service'
 import { smspva } from './impl/smspva.service'
 import { sms7979 } from './impl/sms7979.service'
+import { sms4verify } from './impl/sms4verify.service'
 
 @Module({
     imports: [
@@ -52,7 +53,8 @@ import { sms7979 } from './impl/sms7979.service'
         textverified,
         dashboard,
         smspva,
-        sms7979
+        sms7979,
+        sms4verify
     ],
     controllers: [RcsNumberController],
     exports: [RcsNumberService]

+ 9 - 0
src/rcs-number/rcs-number.service.ts

@@ -35,6 +35,7 @@ import { usapanel } from './impl/usapanel.service'
 import { dashboard } from './impl/dashboard.service'
 import { smspva } from './impl/smspva.service'
 import { sms7979 } from './impl/sms7979.service'
+import { sms4verify } from './impl/sms4verify.service'
 
 @Injectable()
 export class RcsNumberService {
@@ -44,6 +45,8 @@ export class RcsNumberService {
     private cloud037: cloud214
     private cloud041: cloud214
     private cloud050: cloud214
+    private sms4verify01: sms4verify
+    private sms4verify02: sms4verify
 
     private readonly redis: Redis | null
 
@@ -81,6 +84,8 @@ export class RcsNumberService {
         this.cloud037 = new cloud214('100037', 'aaec6c21e54dc53b92e472df21a95bb7', RcsNumberSource.cloud037)
         this.cloud041 = new cloud214('100041', '8174f3107605645d17fd6c5edc0bfb7d', RcsNumberSource.cloud041)
         this.cloud050 = new cloud214('100050', '6c0f25c802b82d2a5c78f01fb627be2c', RcsNumberSource.cloud050)
+        this.sms4verify01 = new sms4verify('Yt8kbBGbvMTL3OBZ2dvwXCm78MI59D', RcsNumberSource.sms4verify01)
+        this.sms4verify02 = new sms4verify('7FwojO3gHajkmyaHFJEd5brt4iq8HN', RcsNumberSource.sms4verify02)
         this.redis = this.redisService.getOrThrow()
         this.redis.get('hello').then((res) => {
             console.log(res)
@@ -326,6 +331,10 @@ export class RcsNumberService {
                 return this.smspva
             case RcsNumberSource.sms7979:
                 return this.sms7979
+            case RcsNumberSource.sms4verify01:
+                return this.sms4verify01
+            case RcsNumberSource.sms4verify02:
+                return this.sms4verify02
             default:
                 throw new ServiceUnavailableException('不支持的短信通道')
         }