package util import ( "bytes" "fmt" "io/ioutil" "mime/multipart" "net/http" ) type JSON1 struct { Access_token string `json:"access_token"` } func Get_AccessToken1(corpid,corpsecret string) string { gettoken_url := "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + corpid + "&corpsecret=" + corpsecret //print(gettoken_url) client := &http.Client{} req, _ := client.Get(gettoken_url) defer req.Body.Close() body, _ := ioutil.ReadAll(req.Body) //fmt.Printf("\n%q",string(body)) var json_str JSON json.Unmarshal([]byte(body), &json_str) //fmt.Printf("\n%q",json_str.Access_token) return json_str.Access_token } func Send_Message1(msg string,url string)[]byte { //print(send_url) client := &http.Client{} body := bytes.NewBuffer([]byte(msg)) req, err := http.NewRequest("POST",url,body) req.Header.Set("Content-Type", "application/json") req.Header.Set("charset","UTF-8") if err != nil { // handle error } resp, err := client.Do(req) if err != nil { fmt.Println(err) return nil } defer resp.Body.Close() result_body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err) return nil } return result_body } /*func main() { postData := make(map[string]string) postData["anchorId"] = "361155076095561728" postData["searchBegin"] = "2019-03-01 00:00:00" postData["searchEnd"] = "2020-03-10 00:00:00" url := "https:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" PostWithFormData("POST",url ,&postData) }*/ func PostWithFormData(method, url string, postData *map[string]string)[]byte{ body := new(bytes.Buffer) w := multipart.NewWriter(body) for k,v := range *postData{ w.WriteField(k, v) } w.Close() req, _ := http.NewRequest(method, url, body) req.Header.Set("Content-Type", w.FormDataContentType()) resp, _ := http.DefaultClient.Do(req) data, _ := ioutil.ReadAll(resp.Body) resp.Body.Close() fmt.Println(resp.StatusCode) fmt.Printf("%s", data) return data } // 栏舍 type Feedp struct{ Status int `json:"status"` ReturnCode string `json:"returnCode"` MessageType int `json:"messageType"` Message string `json:"message"` Data []FeedpData `json:"data"` } type FeedpData struct{ PenId string `json:"penId"` PenName string `json:"penName"` CowCount int `json:"cowCount"` CreatedAt string `json:"createdAt"` ModifiedAt string `json:"modifiedAt"` CcountRatio string `json:"ccountRatio"` } // 牛群类别分类 type Feed struct{ Status int `json:"status"` Message string `json:"message"` Data []FeedData `json:"data"` } type FeedData struct{ FId string `json:"fId"` FName string `json:"fName"` FeedclassName string `json:"feedclassName"` DryMatter string `json:"dryMatter"` Price string `json:"price"` AutoChange string `json:"autoChange"` AllowDev string `json:"allowDev"` CreatedAt string `json:"createdAt"` ModifiedAt string `json:"modifiedAt"` } // 饲料分类 type FeedClass struct{ Status int `json:"status"` Message string `json:"message"` Data []FeedClassData `json:"data"` } type FeedClassData struct{ FeedclassName string `json:"feedclassName"` FeedclassId string `json:"feedclassId"` CreatedAt string `json:"createdAt"` ModifiedAt string `json:"modifiedAt"` } // 牛群类别分类 type CowClass struct{ Status int `json:"status"` Message string `json:"message"` Data []CowClassData `json:"data"` } type CowClassData struct{ CowClassCode string `json:"cowClassCode"` CowClassName string `json:"cowClassName"` CreatedAt string `json:"createdAt"` ModifiedAt string `json:"modifiedAt"` } // 配方 type FeedTemplet struct{ Status int `json:"status"` Message string `json:"message"` Data []FeedTempletData `json:"data"` } type FeedTempletData struct{ FtId string `json:"ftId"` FtName string `json:"ftName"` CreatedAt string `json:"createdAt"` ModifiedAt string `json:"modifiedAt"` FeedList []FeedListData `json:"feedList"` } type FeedListData struct{ FId string `json:"fId"` FName string `json:"fName"` DryMatter string `json:"dryMatter"` FodderWeight string `json:"fodderWeight"` MixNo string `json:"mixNo"` RecipeCost string `json:"recipeCost"` FeedclassName string `json:"feedclassName"` AllowableError string `json:"allowableError"` Autosecond string `json:"autosecond"` }