-
Notifications
You must be signed in to change notification settings - Fork 0
/
smsru.go
84 lines (77 loc) · 1.96 KB
/
smsru.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
package go_sms_ru
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Smsru struct {
Token string
Http *http.Client
}
func SmsRU(token string) (sms *Smsru) {
return &Smsru{
Token: token,
Http: &http.Client{},
}
}
func (sms *Smsru) Send(mobile string, message string) (map[string]interface{}, error) {
URI := fmt.Sprintf("https://sms.ru/sms/send?api_id=%s&to=%s&msg=%s,&json=1", sms.Token, mobile, message)
res, err := sms.Http.Get(URI)
if err != nil {
return nil, err
}
resBody, _ := ioutil.ReadAll(res.Body)
resBytes := []byte(string(resBody))
var jsonRes map[string]interface{}
err = json.Unmarshal(resBytes, &jsonRes)
if err != nil {
return nil, err
}
return jsonRes, nil
}
func (sms *Smsru) Call(mobile string) (map[string]interface{}, error) {
URI := fmt.Sprintf("https://sms.ru/code/call?api_id=%s&phone=%s", sms.Token, mobile)
res, err := sms.Http.Get(URI)
if err != nil {
return nil, err
}
resBody, _ := ioutil.ReadAll(res.Body)
resBytes := []byte(string(resBody))
var jsonRes map[string]interface{}
err = json.Unmarshal(resBytes, &jsonRes)
if err != nil {
return nil, err
}
return jsonRes, nil
}
func (sms *Smsru) Balance() (map[string]interface{}, error) {
URI := fmt.Sprintf("https://sms.ru/my/balance?api_id=%s&json=1", sms.Token)
res, err := sms.Http.Get(URI)
if err != nil {
return nil, err
}
resBody, _ := ioutil.ReadAll(res.Body)
resBytes := []byte(string(resBody))
var jsonRes map[string]interface{}
err = json.Unmarshal(resBytes, &jsonRes)
if err != nil {
return nil, err
}
return jsonRes, nil
}
func (sms *Smsru) Limit() (map[string]interface{}, error) {
URI := fmt.Sprintf("https://sms.ru/my/limit?api_id=%s&json=1", sms.Token)
res, err := sms.Http.Get(URI)
if err != nil {
return nil, err
}
resBody, _ := ioutil.ReadAll(res.Body)
resBytes := []byte(string(resBody))
var jsonRes map[string]interface{}
err = json.Unmarshal(resBytes, &jsonRes)
if err != nil {
return nil, err
}
return jsonRes, nil
}