You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
2.7 KiB

  1. package mill
  2. import (
  3. "crypto/rand"
  4. "fmt"
  5. "io"
  6. "net/http"
  7. "time"
  8. )
  9. func makeNonce() string {
  10. buf := make([]byte, 8)
  11. _, _ = io.ReadFull(rand.Reader, buf)
  12. return fmt.Sprintf("%x", buf)
  13. }
  14. func addDefaultHeaders(req *http.Request) {
  15. req.Header.Add("Content-Type", "application/x-zc-object")
  16. req.Header.Add("Connection", "Keep-Alive")
  17. req.Header.Add("X-Zc-Major-Domain", "seanywell")
  18. req.Header.Add("X-Zc-Msg-Name", "millService")
  19. req.Header.Add("X-Zc-Sub-Domain", "milltype")
  20. req.Header.Add("X-Zc-Seq-Id", "1")
  21. req.Header.Add("X-Zc-Version", "1")
  22. }
  23. var gen2subDomains = []int{863, 5316, 5317, 5332, 5333, 6933}
  24. func subDomainToGeneration(subDomain int) int {
  25. for _, gen2sd := range gen2subDomains {
  26. if subDomain == gen2sd {
  27. return 2
  28. }
  29. }
  30. return 3
  31. }
  32. const accountEndpoint = "https://eurouter.ablecloud.cn:9005/zc-account/v1/"
  33. const serviceEndpoint = "https://eurouter.ablecloud.cn:9005/millService/v1/"
  34. type millHome struct {
  35. HomeID int64 `json:"homeId"`
  36. HomeName string `json:"homeName"`
  37. }
  38. type millDevice struct {
  39. DeviceID int `json:"deviceId"`
  40. DeviceName string `json:"deviceName"`
  41. PowerStatus int `json:"powerStatus"`
  42. HolidayTemp int `json:"holidayTemp"`
  43. CurrentTemp float64 `json:"currentTemp"`
  44. SubDomainID int `json:"subDomainId"`
  45. }
  46. type authReqBody struct {
  47. Account string `json:"account"`
  48. Password string `json:"password"`
  49. }
  50. type authResBody struct {
  51. Token string `json:"token"`
  52. UserID int `json:"userId"`
  53. NickName string `json:"nickName"`
  54. TokenExpire string `json:"tokenExpire"`
  55. }
  56. type listHomeReqBody struct{}
  57. type listHomeResBody struct {
  58. HomeList []millHome `json:"homeList"`
  59. }
  60. type listDeviceReqBody struct {
  61. HomeID int64 `json:"homeId"`
  62. }
  63. type listDeviceResBody struct {
  64. DeviceInfo []millDevice `json:"deviceInfo"`
  65. }
  66. type changeInfoReqBody struct {
  67. HomeType int `json:"homeType"`
  68. DeviceID int `json:"deviceId"`
  69. Value int `json:"value"`
  70. TimeZoneNum string `json:"timeZoneNum"`
  71. Key string `json:"key"`
  72. }
  73. type deviceControlReqBody struct {
  74. SubDomain string `json:"subDomain"`
  75. DeviceID int `json:"deviceId"`
  76. TestStatus int `json:"testStatus"`
  77. Operation int `json:"operation"`
  78. Status int `json:"status"`
  79. WindStatus int `json:"windStatus"`
  80. TempType int `json:"tempType"`
  81. PowerLevel int `json:"powerLevel"`
  82. }
  83. type deviceControlGen3Body struct {
  84. Operation string `json:"operation"`
  85. Status int `json:"status"`
  86. SubDomain int `json:"subDomain"`
  87. DeviceId int `json:"deviceId"`
  88. HoldTemp int `json:"holdTemp,omitempty"`
  89. }
  90. var location *time.Location
  91. func init() {
  92. myLocation, err := time.LoadLocation("Europe/Oslo")
  93. if err != nil {
  94. panic(err.Error())
  95. }
  96. location = myLocation
  97. }