|
@@ -0,0 +1,57 @@
|
|
|
+package ssmsSuApi
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+// "strings"
|
|
|
+ "net/url"
|
|
|
+ "net/http"
|
|
|
+ "encoding/json"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ API_SERVER_URL string = "http://api2.ssms.su/"
|
|
|
+)
|
|
|
+
|
|
|
+type ResponseResponseMsg struct {
|
|
|
+ Err_Code string
|
|
|
+ Text string
|
|
|
+ Type string
|
|
|
+}
|
|
|
+
|
|
|
+type ResponseResponseData struct {
|
|
|
+ Id int
|
|
|
+ Credits float32
|
|
|
+ N_Raw_SMS int
|
|
|
+ Sender_Name string
|
|
|
+}
|
|
|
+
|
|
|
+type ResponseResponse struct {
|
|
|
+ Msg ResponseResponseMsg
|
|
|
+ Data ResponseResponseData
|
|
|
+}
|
|
|
+
|
|
|
+type Response struct {
|
|
|
+ Response ResponseResponse
|
|
|
+}
|
|
|
+
|
|
|
+func SendSms(login string, password string, recipient string, message string, senderName string) (error, Response) {
|
|
|
+ resp, err := http.PostForm(API_SERVER_URL, url.Values{"format":{"JSON"}, "method":{"push_msg"}, "email":{login}, "password":{password}, "sender_name":{senderName}, "phone":{recipient}, "text":{message}})
|
|
|
+
|
|
|
+ if (err != nil) {
|
|
|
+ return err, Response{};
|
|
|
+ }
|
|
|
+
|
|
|
+ defer resp.Body.Close()
|
|
|
+ decoder := json.NewDecoder(resp.Body)
|
|
|
+ //decoder := json.NewDecoder(strings.NewReader("{\"response\":{\"msg\":{\"err_code\":\"0\",\"text\":\"OK\",\"type\":\"message\"},\"data\":{\"id\":7021498,\"credits\":\"1.50\",\"n_raw_sms\":1,\"sender_name\":\"MEPHI\"}}}"))
|
|
|
+ var responseData Response;
|
|
|
+ decoder.Decode(&responseData)
|
|
|
+ // response example: {"response":{"msg":{"err_code":"0","text":"OK","type":"message"},"data":{"id":7021498,"credits":"1.50","n_raw_sms":1,"sender_name":"MEPHI"}}}
|
|
|
+
|
|
|
+ if (responseData.Response.Msg.Err_Code != "0") {
|
|
|
+ return fmt.Errorf("Incorrect request: %v: %v [%v]", responseData.Response.Msg.Err_Code, responseData.Response.Msg.Text, responseData.Response.Msg.Type), responseData
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil, responseData
|
|
|
+}
|
|
|
+
|