forked from Narasimha1997/fake-sms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recvsms.go
91 lines (75 loc) · 1.74 KB
/
recvsms.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
const (
pageURL = "https://onlinesim.io/"
)
func ScrapeAvailableCountries() []Country {
apiURL := fmt.Sprintf("%sapi/v1/free_numbers_content/countries", pageURL)
resp, err := http.Get(apiURL)
if err != nil {
fmt.Println("Error:", err)
return nil
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error:", err)
return nil
}
var data Response
err = json.Unmarshal(body, &data)
if err != nil {
fmt.Println("Error:", err)
return nil
}
return data.Countries
}
// ScrapeAvailableNumbers Extracts the list of phone-numbers from the page
func ScrapeAvailableNumbers(code string) []Number {
apiURL := fmt.Sprintf("%sapi/v1/free_numbers_content/countries/%s", pageURL, code)
resp, err := http.Get(apiURL)
if err != nil {
fmt.Println("Error:", err)
return nil
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error:", err)
return nil
}
var data ResponseNumbers
err = json.Unmarshal(body, &data)
if err != nil {
fmt.Println("Error:", err)
return nil
}
return data.Numbers
}
// ScrapeMessagesForNumber GET SMS from number
func ScrapeMessagesForNumber(countryCode int, number string) []Message {
apiURL := fmt.Sprintf("%sapi/getFreeMessageList?&phone=%s&country=%d", pageURL, number, countryCode)
resp, err := http.Get(apiURL)
if err != nil {
fmt.Println("Error:", err)
return nil
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error:", err)
return nil
}
var data MessagesResponse
err = json.Unmarshal(body, &data)
if err != nil {
fmt.Println("Error:", err)
return nil
}
return data.Messages.Data
}