| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 | package utilimport (	"bytes"	"fmt"	"tmr-watch/pkg/logging"	"io/ioutil"	"mime/multipart"	"net/http"	"github.com/pkg/errors"	"github.com/xormplus/xorm")type JSON1 struct {	Access_token string `json:"access_token"`}//格润富德api调用(可咨询刘欢)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) error {	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)	logging.Info("setdata:    ", body.String())	req.Header.Set("Content-Type", w.FormDataContentType())	resp, _ := http.DefaultClient.Do(req)	data, _ := ioutil.ReadAll(resp.Body)	resp.Body.Close()	m := make(map[string]interface{}, 0)	json.Unmarshal(data, &m)	rescode := 0	switch m["status"].(type) {	case float64:		rescode = int(m["status"].(float64))	case int:		rescode = m["status"].(int)	}	if rescode == 1 {		return errors.New(xorm.String(m["message"]))	}	return nil}// 栏舍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"`}
 |