|
|
@@ -5,42 +5,71 @@ import axios from 'axios'
|
|
|
const axiosInstance = axios.create({
|
|
|
baseURL: 'https://api.tiger-sms.com/stubs/'
|
|
|
})
|
|
|
-const api_key = 't6AV7f5KgwRmWsK9M5xN6uTTtHiog8EQ'
|
|
|
+const api_key_sz = 'Aq7XKGX7qnCf6y8CouchYJ0VK60AxISm'
|
|
|
+const api_key_xs = 't6AV7f5KgwRmWsK9M5xN6uTTtHiog8EQ'
|
|
|
const service = 'gms'
|
|
|
const countryCode = '187'
|
|
|
|
|
|
export class smstiger extends GetNumberService {
|
|
|
- source: RcsNumberSource = RcsNumberSource.smstiger
|
|
|
+ source: RcsNumberSource
|
|
|
+
|
|
|
+ api_key: string
|
|
|
+
|
|
|
+ constructor(key: string, source: RcsNumberSource) {
|
|
|
+ super()
|
|
|
+ this.api_key = key
|
|
|
+ this.source = source
|
|
|
+ }
|
|
|
|
|
|
async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
|
|
|
if (country.toLocaleLowerCase() !== 'us') throw new Error(`Platform ${this.source} only support US.`)
|
|
|
- const res = await axiosInstance.get(`handler_api.php`, {
|
|
|
- params: {
|
|
|
- api_key,
|
|
|
- action: 'getNumber',
|
|
|
- service,
|
|
|
- country: countryCode
|
|
|
- }
|
|
|
- })
|
|
|
- const data = res.data
|
|
|
- const split = data.split(':')
|
|
|
- if (split[0] !== 'ACCESS_NUMBER') {
|
|
|
- throw new Error(`Platform ${this.source} get number error: ${data}`)
|
|
|
+
|
|
|
+ const requestPhoneInfo = async () => {
|
|
|
+ const res = await axiosInstance.get(`handler_api.php`, {
|
|
|
+ params: {
|
|
|
+ api_key: this.api_key,
|
|
|
+ action: 'getNumber',
|
|
|
+ service,
|
|
|
+ country: countryCode
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return res.data
|
|
|
}
|
|
|
|
|
|
- return {
|
|
|
- number: split[2],
|
|
|
- orderId: split[1],
|
|
|
- operatorCode: '',
|
|
|
- operatorName: '',
|
|
|
- rawResponse: data
|
|
|
+ const requests = Array(10)
|
|
|
+ .fill(null)
|
|
|
+ .map(() => requestPhoneInfo())
|
|
|
+
|
|
|
+ try {
|
|
|
+ const result = await Promise.any(
|
|
|
+ requests.map(async (request) => {
|
|
|
+ const data = await request
|
|
|
+ const split = data.split(':')
|
|
|
+ if (split[0] === 'ACCESS_NUMBER') {
|
|
|
+ return data
|
|
|
+ }
|
|
|
+ throw new Error(data)
|
|
|
+ })
|
|
|
+ )
|
|
|
+
|
|
|
+ const split = result.split(':')
|
|
|
+
|
|
|
+ return {
|
|
|
+ number: split[2],
|
|
|
+ orderId: split[1],
|
|
|
+ operatorCode: '',
|
|
|
+ operatorName: '',
|
|
|
+ rawResponse: result
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ throw new Error(`Platform ${this.source} Failed to get a valid number: ${e.message}`)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async retriveMessage(orderId: string, num?: number): Promise<string> {
|
|
|
const res = await axiosInstance.get(`handler_api.php`, {
|
|
|
params: {
|
|
|
- api_key,
|
|
|
+ api_key: this.api_key,
|
|
|
action: 'getStatus',
|
|
|
id: orderId
|
|
|
}
|