1 Star 0 Fork 0

kzangv/gsf-fof

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
common.go 1.99 KB
Copy Edit Raw Blame History
kzangv authored 2023-02-23 13:34 . fixed
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)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kzangv/gsf-fof.git
git@gitee.com:kzangv/gsf-fof.git
kzangv
gsf-fof
gsf-fof
v0.2.0

Search

0d507c66 1850385 C8b1a773 1850385