package sms import ( "bytes" "crypto/md5" "encoding/hex" "io/ioutil" "net/http" "strings" "github.com/json-iterator/go" ) var json = jsoniter.ConfigCompatibleWithStandardLibrary //密码加密 func Md5Str(str ...string) string { var build strings.Builder if len(str) > 0 { for _, v := range str { build.WriteString(v) } } else { return "" } h := md5.New() h.Write([]byte(build.String())) // 需要加密的字符串 cipher2Str := h.Sum(nil) sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果 return sMd5 } /* * 连接多个字符串 */ func StringJoin(s ...string) string { var build strings.Builder if len(s) > 0 { for _, v := range s { build.WriteString(v) } } return build.String() } /** * post 请求 */ func PostJsonData(url string, param interface{}, header ...map[string]string) ([]byte, error) { httpClient := &http.Client{} params, err := json.Marshal(param) if err != nil { return []byte(""), err } req, err := http.NewRequest("POST", url, bytes.NewBuffer(params)) if err != nil { return []byte(""), err } req.Header.Set("Content-Type", "application/json") if len(header) > 0 { for _, item := range header { for k, v := range item { req.Header[k] = []string{v} } } } resp, err := httpClient.Do(req) if err != nil { return []byte(""), err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return []byte(""), err } return body, nil }