tower_auth.go 961 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "fmt"
  6. "strings"
  7. "tower-monitor/util"
  8. )
  9. func TowerFramAuthRequestHandle(sn string, towerNo byte, version byte, data []byte) (res []byte, err error) {
  10. deviceInfo, err := util.GetDeviceInfo(sn)
  11. if err != nil {
  12. fmt.Printf("get device info err:%v\n", err)
  13. if strings.Contains(err.Error(), "20001") {
  14. res := makeResponse(sn, towerNo, TowerFrameAuthResponse, version, []byte{0x01})
  15. return res, nil
  16. } else {
  17. res := makeResponse(sn, towerNo, TowerFrameAuthResponse, version, []byte{0xfd})
  18. return res, nil
  19. }
  20. }
  21. if deviceInfo.Key != strings.TrimSpace(string(data)) {
  22. res := makeResponse(sn, towerNo, TowerFrameAuthResponse, version, []byte{0x02})
  23. return res, nil
  24. }
  25. authCache(sn, deviceInfo.ProjectId, deviceInfo.Name)
  26. return makeResponse(sn, towerNo, TowerFrameAuthResponse, version, []byte{0x00}), nil
  27. }