Ver código fonte

refactor(rcs-number): 新增 durian02 号源并重构 durian 服务

- 新增 durian02 号源配置
- 重构 durian服务类,支持多个 durian 实例
- 更新 RcsNumberService,添加 durian02 实例
- 修改相关实体和枚举,增加 durian02 相关内容
wui 10 meses atrás
pai
commit
fa35f847ad

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

@@ -20,6 +20,7 @@ export enum RcsNumberSource {
     usacode = 'usacode',
     mwze167 = 'mwze167',
     durian = 'durian',
+    durian02 = 'durian02',
     i18nvc = 'i18nvc',
     firefox = 'firefox',
     d38 = 'd38',

+ 21 - 17
src/rcs-number/impl/durian.service.ts

@@ -16,12 +16,6 @@ const ApiKey2 = 'RHJGV1paR1BFWjlFbCtnakUza2xJdz09'
 const name3 = 'unsnap30942'
 const ApiKey3 = 'UzVzWkFWekZCeXF1U1RxcFlXRGdWdz09'
 
-const user = [
-    { name: name1, ApiKey: ApiKey1 },
-    { name: name2, ApiKey: ApiKey2 },
-    { name: name3, ApiKey: ApiKey3 }
-]
-
 const durianInstance = axios.create({
     baseURL: 'http://8.218.211.187/out/ext_api/',
     headers: {
@@ -31,13 +25,23 @@ const durianInstance = axios.create({
 })
 
 export class durian extends GetNumberService {
-    source: RcsNumberSource = RcsNumberSource.durian
+    source: RcsNumberSource
+
+    name: string
+    ApiKey: string
+
+    constructor(name: string, ApiKey: string, source: RcsNumberSource) {
+        super()
+        this.name = name
+        this.ApiKey = ApiKey
+        this.source = source
+    }
 
     async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
         const res = await durianInstance.get('getMobile', {
             params: {
-                name: name1,
-                ApiKey: ApiKey1,
+                name: this.name,
+                ApiKey: this.ApiKey,
                 cuy: country.toUpperCase(),
                 pid,
                 num: 1,
@@ -80,8 +84,8 @@ export class durian extends GetNumberService {
     async releaseNumber(number: string) {
         const { data } = await durianInstance.get('passMobile', {
             params: {
-                name: name1,
-                ApiKey: ApiKey1,
+                name: this.name,
+                ApiKey: this.ApiKey,
                 pn: number,
                 pid
             }
@@ -96,8 +100,8 @@ export class durian extends GetNumberService {
     async retriveMessage(orderId: string, num?: number): Promise<string> {
         const { data } = await durianInstance.get('getMsg', {
             params: {
-                name: name1,
-                ApiKey: ApiKey1,
+                name: this.name,
+                ApiKey: this.ApiKey,
                 pn: orderId,
                 pid: pid,
                 serial: 2
@@ -111,8 +115,8 @@ export class durian extends GetNumberService {
     async blockNumber(number: string) {
         const { data } = await durianInstance.get('addBlack', {
             params: {
-                name: name1,
-                ApiKey: ApiKey1,
+                name: this.name,
+                ApiKey: this.ApiKey,
                 pn: number,
                 pid: pid
             }
@@ -127,8 +131,8 @@ export class durian extends GetNumberService {
     async cacheNumber(country: string, size: number) {
         const res = await durianInstance.get('getMobile', {
             params: {
-                name: name1,
-                ApiKey: ApiKey1,
+                name: this.name,
+                ApiKey: this.ApiKey,
                 cuy: country.toUpperCase(),
                 pid,
                 num: 10,

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

@@ -42,6 +42,8 @@ import { smsapi } from './impl/smsapi.service'
 @Injectable()
 export class RcsNumberService {
     private lock = new AsyncLock()
+    private durian: durian
+    private durian02: durian
     private cloud033: cloud214
     private cloud034: cloud214
     private cloud037: cloud214
@@ -70,7 +72,6 @@ export class RcsNumberService {
         private carrierIdService: CarrierIdService,
         private sysConfigService: SysConfigService,
         private mwze167: mwze167,
-        private durian: durian,
         private i18nvc: i18nvc,
         private firefox: firefox,
         private d38: d38,
@@ -86,6 +87,8 @@ export class RcsNumberService {
         private smsapi: smsapi,
         private readonly redisService: RedisService
     ) {
+        this.durian = new durian('unsnap3094', 'U3Jma1hkbUxXblEyL0ZYai9WWFVvdz09', RcsNumberSource.durian)
+        this.durian02 = new durian('unsnap30941', 'RHJGV1paR1BFWjlFbCtnakUza2xJdz09', RcsNumberSource.durian02)
         this.cloud033 = new cloud214('100033', '1e40ca9795b1fc038db76512175d59b5', RcsNumberSource.cloud033)
         this.cloud034 = new cloud214('100034', '54bdd0d9dd6707b2b40d8deb5edb1385', RcsNumberSource.cloud034)
         this.cloud037 = new cloud214('100037', 'aaec6c21e54dc53b92e472df21a95bb7', RcsNumberSource.cloud037)
@@ -312,6 +315,8 @@ export class RcsNumberService {
                 return this.mwze167
             case RcsNumberSource.durian:
                 return this.durian
+            case RcsNumberSource.durian02:
+                return this.durian02
             case RcsNumberSource.i18nvc:
                 return this.i18nvc
             case RcsNumberSource.firefox: