package service import ( "bytes" "crypto/tls" "io/ioutil" "net/http" "recook/tools" "strings" jsoniter "github.com/json-iterator/go" "github.com/pkg/errors" ) type Packet struct { PicUrls []string `json:"picUrls"` Name string `json:"name"` No string `json:"no"` Process []Process `json:"data"` } type Process struct { Context string `json:"context"` Time string `json:"ftime"` } func QueryPackage(mobile, expressCompCode, expressNo string) (pac Packet, err error) { tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } client := &http.Client{Transport: tr} buf := bytes.NewBuffer([]byte(newRequestParam(mobile, expressCompCode, expressNo))) request, err := http.NewRequest("POST", url, buf) request.Header.Add("Content-Type", "application/x-www-form-urlencoded") if err != nil { return } response, err := client.Do(request) if err != nil { err = errors.New("DO err:" + err.Error()) return } result, err := ioutil.ReadAll(response.Body) if err != nil { err = errors.New("Read err:" + err.Error()) return } response.Body.Close() _ = jsoniter.Unmarshal(result, &pac) return } const ( key = "EcrXiVGj6488" customer = "8547631AFB44524C4AB3F88557444A5D" url = "https://poll.kuaidi100.com/poll/query.do" ) func newRequestParam(phone string, code string, no string) string { type param struct { Com string `json:"com"` Num string `json:"num"` Phone string `json:"phone"` } p := param{ code, no, phone, } s, _ := jsoniter.Marshal(&p) sign := strings.ToUpper(tools.MD5(string(s) + key + customer)) return "customer=" + customer + "&sign=" + sign + "¶m=" + string(s) }