Fetch the repository succeeded.
package sms
import (
"crypto/md5"
"crypto/sha1"
"encoding/hex"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
)
// 官方地址:https://github.com/dev-submail/submail_go_sdk
const Server = "https://api.mysubmail.com"
func _GetTimestamp() string {
resp := _Get(Server + "/service/timestamp")
var dict map[string]interface{}
err := json.Unmarshal([]byte(resp), &dict)
if err != nil {
return err.Error()
}
return strconv.Itoa(int(dict["timestamp"].(float64)))
}
func _CreateSignature(req map[string]string, config map[string]string) string {
appkey := config["appkey"]
appid := config["appid"]
signtype := config["signType"]
keys := make([]string, 0, 32)
for key, _ := range req {
keys = append(keys, key)
}
sort.Strings(keys)
str_list := make([]string, 0, 32)
for _, key := range keys {
str_list = append(str_list, key+"="+req[key])
}
sigstr := strings.Join(str_list, "&")
sigstr = appid + appkey + sigstr + appid + appkey
if signtype == "md5" {
mymd5 := md5.New()
io.WriteString(mymd5, sigstr)
return hex.EncodeToString(mymd5.Sum(nil))
} else if signtype == "sha1" {
mysha1 := sha1.New()
io.WriteString(mysha1, sigstr)
return hex.EncodeToString(mysha1.Sum(nil))
} else {
return appkey
}
}
func _Get(requesturl string) string {
u, _ := url.Parse(requesturl)
retstr, err := http.Get(u.String())
if err != nil {
return err.Error()
}
result, err := ioutil.ReadAll(retstr.Body)
retstr.Body.Close()
if err != nil {
return err.Error()
}
return string(result)
}
func _Post(requesturl string, postdata map[string]string) string {
var r http.Request
r.ParseForm()
for key, val := range postdata {
r.Form.Add(key, val)
}
body := strings.NewReader(r.Form.Encode())
retstr, err := http.Post(requesturl, "application/x-www-form-urlencoded;charset=utf-8", body)
if err != nil {
return err.Error()
}
result, err := ioutil.ReadAll(retstr.Body)
retstr.Body.Close()
if err != nil {
return err.Error()
}
return string(result)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。