mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 15:09:51 +00:00
Added SMSGlobal HTTP support.
This commit is contained in:
45
smsglobal.go
Normal file
45
smsglobal.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"errors"
|
||||
)
|
||||
|
||||
const (
|
||||
SMSGLOBAL_API_URL = "http://www.smsglobal.com/http-api.php"
|
||||
)
|
||||
|
||||
func SMSNotify(username, password, from, to, message string) (error) {
|
||||
values := url.Values{}
|
||||
values.Set("action", "sendsms")
|
||||
values.Set("user", username)
|
||||
values.Set("password", password)
|
||||
values.Set("from", from)
|
||||
values.Set("to", to)
|
||||
values.Set("text", message)
|
||||
|
||||
reqBody := strings.NewReader(values.Encode())
|
||||
req, err := http.NewRequest("POST", SMSGLOBAL_API_URL, reqBody)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("PostRequest: Unable to send request")
|
||||
}
|
||||
|
||||
contents, _ := ioutil.ReadAll(resp.Body)
|
||||
fmt.Printf("Recieved raw: %s\n", string(contents))
|
||||
resp.Body.Close()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user