1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| package main
import ( "fmt" "strings" "net/http" "io/ioutil" "crypto/md5" "encoding/hex" "encoding/json" "encoding/base64" )
type Object struct{ EcName string `json:"ecName"` ApId string `json:"apId"` SecretKey string `json:"secretKey"` Mobiles string `json:"mobiles"` Content string `json:"content"` Sign string `json:"sign"` AddSerial string `json:"addserial"` Mac string `json:"mac"` }
func mkmd5(s string) string { md5Ctx := md5.New() md5Ctx.Write([]byte(s)) cipherStr := md5Ctx.Sum(nil) return hex.EncodeToString(cipherStr) }
func main() { client := &http.Client{} posturl := "http://112.35.1.155:1992/sms/norsubmit"
ecName := "管理中心"; apId := "xxx"; secretKey := "L00001"; mobiles := "136****00"; content := "移动改变生活"; sign := "xcxxcxcxc"; addSerial := ""; mac_origin := ecName + apId + secretKey + mobiles + content + sign + addSerial;
mac := mkmd5(mac_origin)
object := Object{ EcName: ecName, ApId:apId, SecretKey:secretKey, Mobiles:mobiles, Content:content, Sign:sign, AddSerial:addSerial, Mac:mac, }
sdata, err := json.Marshal(object) fmt.Println(sdata) if err != nil { fmt.Println("json.marshal failed, err:", err) return }
message := base64.StdEncoding.EncodeToString(sdata)
req, err := http.NewRequest("POST", posturl, strings.NewReader(message)) if err != nil { }
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req) defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { } fmt.Println(string(body)) }
|