definitions.go 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package device
  2. import "github.com/silenceper/wechat/util"
  3. const (
  4. //添加设备标识
  5. DEVICE_ADD = iota
  6. //更新设备标识
  7. DEVCIE_UPGRADE
  8. )
  9. const (
  10. //android classic bluetooth
  11. PROTOCOL_ANDROID_BLE = iota
  12. //ios classic bluetooth
  13. PROTOCOL_IOS_BLE
  14. PROTOCOL_BLE
  15. PROTOCOL_WIFI
  16. )
  17. type reqDeviceAuthorize struct {
  18. // 设备id的个数
  19. DeviceNum string `json:"device_num"`
  20. // 设备id的列表,json的array格式,其size必须等于device_num
  21. DeviceList []ReqDevice `json:"device_list"`
  22. // 请求操作的类型,限定取值为:0:设备授权(缺省值为0) 1:设备更新(更新已授权设备的各属性值)
  23. OpType string `json:"op_type,omitempty"`
  24. // 设备的产品编号(由微信硬件平台分配)。可在公众号设备功能管理页面查询。
  25. //当 op_type 为‘0’,product_id 为‘1’时,不要填写 product_id 字段(会引起不必要错误);
  26. //当 op_typy 为‘0’,product_id 不为‘1’时,必须填写 product_id 字段;
  27. //当 op_type 为 1 时,不要填写 product_id 字段。
  28. ProductId string `json:"product_id,omitempty"`
  29. }
  30. type ReqDevice struct {
  31. // 设备的 device id
  32. Id string `json:"id"`
  33. // 设备的mac地址 格式采用16进制串的方式(长度为12字节),
  34. // 不需要0X前缀,如: 1234567890AB
  35. Mac string `json:"mac"`
  36. // 支持以下四种连接协议:
  37. // android classic bluetooth – 1
  38. // ios classic bluetooth – 2
  39. // ble – 3
  40. // wifi -- 4
  41. // 一个设备可以支持多种连接类型,用符号"|"做分割,客户端优先选择靠前的连接方式(优先级按|关系的排序依次降低),举例:
  42. // 1:表示设备仅支持andiod classic bluetooth 1|2:表示设备支持andiod 和ios 两种classic bluetooth,但是客户端优先选择andriod classic bluetooth 协议,如果andriod classic bluetooth协议连接失败,再选择ios classic bluetooth协议进行连接
  43. // (注:安卓平台不同时支持BLE和classic类型)
  44. ConnectProtocol string `json:"connect_protocol"`
  45. //auth及通信的加密key,第三方需要将key烧制在设备上(128bit),格式采用16进制串的方式(长度为32字节),不需要0X前缀,如: 1234567890ABCDEF1234567890ABCDEF
  46. AuthKey string `json:"auth_key"`
  47. // 断开策略,目前支持: 1:退出公众号页面时即断开连接 2:退出公众号之后保持连接不断开
  48. CloseStrategy string `json:"close_strategy"`
  49. //连接策略,32位整型,按bit位置位,目前仅第1bit和第3bit位有效(bit置0为无效,1为有效;第2bit已被废弃),且bit位可以按或置位(如1|4=5),各bit置位含义说明如下:
  50. //1:(第1bit置位)在公众号对话页面,不停的尝试连接设备
  51. //4:(第3bit置位)处于非公众号页面(如主界面等),微信自动连接。当用户切换微信到前台时,可能尝试去连接设备,连上后一定时间会断开
  52. ConnStrategy string `json:"conn_strategy"`
  53. // auth version,设备和微信进行auth时,会根据该版本号来确认auth buf和auth key的格式(各version对应的auth buf及key的具体格式可以参看“客户端蓝牙外设协议”),该字段目前支持取值:
  54. // 0:不加密的version
  55. // 1:version 1
  56. AuthVer string `json:"auth_ver"`
  57. // 表示mac地址在厂商广播manufature data里含有mac地址的偏移,取值如下:
  58. // -1:在尾部、
  59. // -2:表示不包含mac地址 其他:非法偏移
  60. ManuMacPos string `json:"manu_mac_pos"`
  61. // 表示mac地址在厂商serial number里含有mac地址的偏移,取值如下:
  62. // -1:表示在尾部
  63. // -2:表示不包含mac地址 其他:非法偏移
  64. SerMacPost string `json:"ser_mac_post"`
  65. // 精简协议类型,取值如下:计步设备精简协议:1 (若该字段填1,connect_protocol 必须包括3。非精简协议设备切勿填写该字段)
  66. BleSimpleProtocol string `json:"ble_simple_protocol,omitempty"`
  67. }
  68. // 授权回调实体
  69. type resBaseInfo struct {
  70. BaseInfo struct {
  71. DeviceType string `json:"device_type"`
  72. DeviceId string `json:"device_id"`
  73. } `json:"base_info"`
  74. }
  75. // 授权回调根信息
  76. type ResDeviceAuthorize struct {
  77. util.CommonError
  78. Resp []resBaseInfo `json:"resp"`
  79. }
  80. type ResCreateQRCode struct {
  81. util.CommonError
  82. DeviceNum int `json:"device_num"`
  83. CodeList []resQRCode `json:"code_list"`
  84. }
  85. type resQRCode struct {
  86. DeviceId string `json:"device_id"`
  87. Ticket string `json:"ticket"`
  88. }