| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import { GetNumberResponse, GetNumberService } from './get-number-service'
- import { RcsNumberSource } from '../entities/rcs-number.entity'
- import axios from 'axios'
- import { InternalServerErrorException, Logger } from '@nestjs/common'
- const API_KEY01 = 'uNW56fGr0zstfs87Xn0e1l2gCYVnb1'
- const API_KEY02 = 'rTTL8pZtKkQ60zjU82bvbMEP7G6XGU'
- const SERVICE = 'opt259'
- const axiosInstance = axios.create({
- baseURL: 'http://8.218.211.187/activation/',
- headers: {
- uhost: 'api.smspva.com',
- uprotocol: 'https'
- }
- })
- const countryMap = {
- US: 'US',
- US1: 'US',
- US2: 'US',
- US3: 'US',
- GB: 'UK'
- }
- export class smspva extends GetNumberService {
- source: RcsNumberSource
- apikey: string
- constructor(key: string, source: RcsNumberSource) {
- super()
- this.apikey = key
- this.source = source
- }
- async getNumber(country: string, num?: number): Promise<GetNumberResponse> {
- let countryCode = countryMap[country]
- if (!countryCode) {
- countryCode = country
- }
- const res = await axiosInstance.get(`number/${countryCode}/${SERVICE}`, {
- headers: {
- apikey: this.apikey
- }
- })
- 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) {
- const res = await axiosInstance.put(
- `cancelorder/${Number(number)}`,
- {},
- {
- headers: {
- apikey: this.apikey
- }
- }
- )
- if (res.data.statusCode === 200) {
- Logger.log(`release orderId ${number} success`)
- } else {
- throw new InternalServerErrorException(res.data.error.description)
- }
- }
- async retriveMessage(orderId: string, num?: number): Promise<string> {
- const res = await axiosInstance.get(`sms/${Number(orderId)}`, {
- headers: {
- apikey: this.apikey
- }
- })
- if (res.data.statusCode === 200) {
- return res.data.data.sms.fullText
- }
- }
- async blockNumber(orderId: string) {
- try {
- await axiosInstance.put(
- `blocknumber/${orderId}`,
- {},
- {
- headers: {
- apikey: this.apikey
- }
- }
- )
- } catch (error) {
- Logger.error(`block number ${orderId} failed`, error)
- }
- }
- async cacheNumber(country: string, size: number) {
- return null
- }
- }
|