瀏覽代碼

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

wui 10 月之前
父節點
當前提交
b50cf8dd3e

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

@@ -38,7 +38,8 @@ export enum RcsNumberSource {
     sms7979 = 'sms7979',
     sms797902 = 'sms797902',
     sms4verify01 = 'sms4verify01',
-    sms4verify02 = 'sms4verify02'
+    sms4verify02 = 'sms4verify02',
+    sms23256 = 'sms23256'
 }
 
 @Entity()

+ 57 - 0
src/rcs-number/impl/sms23256.service.ts

@@ -0,0 +1,57 @@
+import { GetNumberResponse, GetNumberService } from './get-number-service'
+import { RcsNumberSource } from '../entities/rcs-number.entity'
+import axios from 'axios'
+import { InternalServerErrorException } from '@nestjs/common'
+
+const token = 'Wr7bluUmhMKc7ouUKgdL4CR3YGIDLMiV27EWhP71u2ifu65FJ8iAb2fHweC60tZ8w_t_z4ISQlcEfLvfe7SWytJOzhcdtA=='
+
+const axiosInstance = axios.create({
+    baseURL: 'http://www.23256api.com/smsapi/record/'
+})
+
+export class sms23256 extends GetNumberService {
+    source: RcsNumberSource = RcsNumberSource.sms23256
+
+    async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
+        if (country.toLocaleLowerCase() !== 'us') throw new Error('Only US is supported')
+        const res = await axiosInstance.get('phone', {
+            params: {
+                token,
+                keyword: 'googlemessenger'
+            }
+        })
+
+        if (res.data.code !== 200) {
+            throw new InternalServerErrorException(res.data.msg)
+        }
+
+        return {
+            number: res.data.data.phoneNumber,
+            orderId: res.data.data.id,
+            operatorCode: '',
+            operatorName: '',
+            rawResponse: res.data
+        }
+    }
+
+    async releaseNumber(number: string) {}
+
+    async retriveMessage(orderId: string, num?: number): Promise<string> {
+        const { data } = await axiosInstance.get('code', {
+            params: {
+                token,
+                phoneid: orderId
+            }
+        })
+        // 如果data是一串数字字符串
+        if (/^\d+$/.test(data)) {
+            return `Your Messenger verification code is G-${data}`
+        }
+    }
+
+    async blockNumber(number: string) {}
+
+    async cacheNumber(country: string, size: number) {
+        return null
+    }
+}

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

@@ -26,6 +26,7 @@ import { dashboard } from './impl/dashboard.service'
 import { smspva } from './impl/smspva.service'
 import { sms7979 } from './impl/sms7979.service'
 import { sms4verify } from './impl/sms4verify.service'
+import { sms23256 } from './impl/sms23256.service'
 
 @Module({
     imports: [
@@ -54,7 +55,8 @@ import { sms4verify } from './impl/sms4verify.service'
         dashboard,
         smspva,
         sms7979,
-        sms4verify
+        sms4verify,
+        sms23256
     ],
     controllers: [RcsNumberController],
     exports: [RcsNumberService]

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

@@ -29,13 +29,13 @@ import { cowboy } from './impl/cowboy.service'
 import { SysConfigService } from 'src/sys-config/sys-config.service'
 import { RedisService } from '@liaoliaots/nestjs-redis'
 import Redis from 'ioredis'
-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'
 import { sms7979 } from './impl/sms7979.service'
 import { sms4verify } from './impl/sms4verify.service'
+import { sms23256 } from './impl/sms23256.service'
 
 @Injectable()
 export class RcsNumberService {
@@ -78,6 +78,7 @@ export class RcsNumberService {
         private textverified: textverified,
         private dashboard: dashboard,
         private smspva: smspva,
+        private sms23256: sms23256,
         private readonly redisService: RedisService
     ) {
         this.cloud033 = new cloud214('100033', '1e40ca9795b1fc038db76512175d59b5', RcsNumberSource.cloud033)
@@ -338,6 +339,8 @@ export class RcsNumberService {
                 return this.sms4verify01
             case RcsNumberSource.sms4verify02:
                 return this.sms4verify02
+            case RcsNumberSource.sms23256:
+                return this.sms23256
             default:
                 throw new ServiceUnavailableException('不支持的短信通道')
         }