38b07634ce2d065c900b92ac769c66f046e40338.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package util
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io/ioutil"
  6. "mime/multipart"
  7. "net/http"
  8. )
  9. type JSON1 struct {
  10. Access_token string `json:"access_token"`
  11. }
  12. func Get_AccessToken1(corpid,corpsecret string) string {
  13. gettoken_url := "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + corpid + "&corpsecret=" + corpsecret
  14. //print(gettoken_url)
  15. client := &http.Client{}
  16. req, _ := client.Get(gettoken_url)
  17. defer req.Body.Close()
  18. body, _ := ioutil.ReadAll(req.Body)
  19. //fmt.Printf("\n%q",string(body))
  20. var json_str JSON
  21. json.Unmarshal([]byte(body), &json_str)
  22. //fmt.Printf("\n%q",json_str.Access_token)
  23. return json_str.Access_token
  24. }
  25. func Send_Message1(msg string,url string)[]byte {
  26. //print(send_url)
  27. client := &http.Client{}
  28. body := bytes.NewBuffer([]byte(msg))
  29. req, err := http.NewRequest("POST",url,body)
  30. req.Header.Set("Content-Type", "application/json")
  31. req.Header.Set("charset","UTF-8")
  32. if err != nil {
  33. // handle error
  34. }
  35. resp, err := client.Do(req)
  36. if err != nil {
  37. fmt.Println(err)
  38. return nil
  39. }
  40. defer resp.Body.Close()
  41. result_body, err := ioutil.ReadAll(resp.Body)
  42. if err != nil {
  43. fmt.Println(err)
  44. return nil
  45. }
  46. return result_body
  47. }
  48. /*func main() {
  49. postData := make(map[string]string)
  50. postData["anchorId"] = "361155076095561728"
  51. postData["searchBegin"] = "2019-03-01 00:00:00"
  52. postData["searchEnd"] = "2020-03-10 00:00:00"
  53. url := "https:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  54. PostWithFormData("POST",url ,&postData)
  55. }*/
  56. func PostWithFormData(method, url string, postData *map[string]string)[]byte{
  57. body := new(bytes.Buffer)
  58. w := multipart.NewWriter(body)
  59. for k,v := range *postData{
  60. w.WriteField(k, v)
  61. }
  62. w.Close()
  63. req, _ := http.NewRequest(method, url, body)
  64. req.Header.Set("Content-Type", w.FormDataContentType())
  65. resp, _ := http.DefaultClient.Do(req)
  66. data, _ := ioutil.ReadAll(resp.Body)
  67. resp.Body.Close()
  68. fmt.Println(resp.StatusCode)
  69. fmt.Printf("%s", data)
  70. return data
  71. }
  72. // 栏舍
  73. type Feedp struct{
  74. Status int `json:"status"`
  75. ReturnCode string `json:"returnCode"`
  76. MessageType int `json:"messageType"`
  77. Message string `json:"message"`
  78. Data []FeedpData `json:"data"`
  79. }
  80. type FeedpData struct{
  81. PenId string `json:"penId"`
  82. PenName string `json:"penName"`
  83. CowCount int `json:"cowCount"`
  84. CreatedAt string `json:"createdAt"`
  85. ModifiedAt string `json:"modifiedAt"`
  86. CcountRatio string `json:"ccountRatio"`
  87. }
  88. // 牛群类别分类
  89. type Feed struct{
  90. Status int `json:"status"`
  91. Message string `json:"message"`
  92. Data []FeedData `json:"data"`
  93. }
  94. type FeedData struct{
  95. FId string `json:"fId"`
  96. FName string `json:"fName"`
  97. FeedclassName string `json:"feedclassName"`
  98. DryMatter string `json:"dryMatter"`
  99. Price string `json:"price"`
  100. AutoChange string `json:"autoChange"`
  101. AllowDev string `json:"allowDev"`
  102. CreatedAt string `json:"createdAt"`
  103. ModifiedAt string `json:"modifiedAt"`
  104. }
  105. // 饲料分类
  106. type FeedClass struct{
  107. Status int `json:"status"`
  108. Message string `json:"message"`
  109. Data []FeedClassData `json:"data"`
  110. }
  111. type FeedClassData struct{
  112. FeedclassName string `json:"feedclassName"`
  113. FeedclassId string `json:"feedclassId"`
  114. CreatedAt string `json:"createdAt"`
  115. ModifiedAt string `json:"modifiedAt"`
  116. }
  117. // 牛群类别分类
  118. type CowClass struct{
  119. Status int `json:"status"`
  120. Message string `json:"message"`
  121. Data []CowClassData `json:"data"`
  122. }
  123. type CowClassData struct{
  124. CowClassCode string `json:"cowClassCode"`
  125. CowClassName string `json:"cowClassName"`
  126. CreatedAt string `json:"createdAt"`
  127. ModifiedAt string `json:"modifiedAt"`
  128. }
  129. // 配方
  130. type FeedTemplet struct{
  131. Status int `json:"status"`
  132. Message string `json:"message"`
  133. Data []FeedTempletData `json:"data"`
  134. }
  135. type FeedTempletData struct{
  136. FtId string `json:"ftId"`
  137. FtName string `json:"ftName"`
  138. CreatedAt string `json:"createdAt"`
  139. ModifiedAt string `json:"modifiedAt"`
  140. FeedList []FeedListData `json:"feedList"`
  141. }
  142. type FeedListData struct{
  143. FId string `json:"fId"`
  144. FName string `json:"fName"`
  145. DryMatter string `json:"dryMatter"`
  146. FodderWeight string `json:"fodderWeight"`
  147. MixNo string `json:"mixNo"`
  148. RecipeCost string `json:"recipeCost"`
  149. FeedclassName string `json:"feedclassName"`
  150. AllowableError string `json:"allowableError"`
  151. Autosecond string `json:"autosecond"`
  152. }