archives.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package controller
  2. import (
  3. "bigdata_archives/app/e"
  4. "bigdata_archives/configs"
  5. "bytes"
  6. "encoding/json"
  7. "github.com/gin-gonic/gin"
  8. "io"
  9. "net/http"
  10. )
  11. type RequestData struct {
  12. AppId string `json:"appId"`
  13. Secret string `json:"secret"`
  14. }
  15. type T struct {
  16. Success bool `json:"success"`
  17. Message string `json:"message"`
  18. Code int `json:"code"`
  19. Result struct {
  20. QzCount int `json:"qzCount"`
  21. QsCount int `json:"qsCount"`
  22. JsCount int `json:"jsCount"`
  23. DzdaCount int `json:"dzdaCount"`
  24. YjCount int `json:"yjCount"`
  25. CqqsCount int `json:"cqqsCount"`
  26. CqjsCount int `json:"cqjsCount"`
  27. QueryCount int `json:"queryCount"`
  28. FileCount int `json:"fileCount"`
  29. ZkList []struct {
  30. Name string `json:"name"`
  31. Num int `json:"num"`
  32. } `json:"zkList"`
  33. CkList []struct {
  34. Name string `json:"name"`
  35. Num int `json:"num"`
  36. } `json:"ckList"`
  37. DrkList []struct {
  38. Name string `json:"name"`
  39. Num int `json:"num"`
  40. } `json:"drkList"`
  41. DckList []struct {
  42. Name string `json:"name"`
  43. Num int `json:"num"`
  44. } `json:"dckList"`
  45. ZkNum int `json:"zkNum"`
  46. CkNum int `json:"ckNum"`
  47. DrkNum int `json:"drkNum"`
  48. DckNum int `json:"dckNum"`
  49. } `json:"result"`
  50. Timestamp int64 `json:"timestamp"`
  51. }
  52. func Archives(c *gin.Context) {
  53. // 创建要发送的数据
  54. data := &RequestData{
  55. AppId: "1686846386279535435",
  56. Secret: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDvv8hgUuIzp7WdTS5zHQPt9bOytMNRY+s1MBCbLp6C2sz9kg+agQ/cMqztYgwjlYqETyUTiu/uuF0y71VHtfazip6eYI++EHqBCNgmgGBkdyV5EyiSBC+RsJ0tX+oCFFtIIlYzIwgserkZyVKrSF61OieQj+C2rqbJBZq5svXlwIDAQAB",
  57. }
  58. marshal, err2 := json.Marshal(data)
  59. if err2 != nil {
  60. e.ResponseWithMsg(c, e.ERROR, "json序列化失败")
  61. return
  62. }
  63. resp, err := http.Post(configs.Config.GetString("archives.arc"), "application/json", bytes.NewReader(marshal))
  64. if err != nil {
  65. e.ResponseWithMsg(c, e.ERROR, "请求接口失败")
  66. return
  67. }
  68. defer resp.Body.Close()
  69. all, _ := io.ReadAll(resp.Body)
  70. var datas T
  71. json.Unmarshal(all, &datas)
  72. if datas.Code == 200 {
  73. e.ResponseSuccess(c, datas.Result)
  74. return
  75. } else {
  76. e.ResponseWithMsg(c, e.ERROR, "请求接口失败")
  77. return
  78. }
  79. }