mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 21:02:25 +08:00
格式化代码样式
This commit is contained in:
@@ -3,14 +3,15 @@ package device
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
)
|
||||
|
||||
const (
|
||||
//添加设备标识
|
||||
DEVICE_ADD = iota
|
||||
//更新设备标识
|
||||
DEVCIE_UPGRADE
|
||||
// DeviceAdd 添加设备标识
|
||||
DeviceAdd = iota
|
||||
// DeviceUpgrade 更新设备标识
|
||||
DeviceUpgrade
|
||||
)
|
||||
|
||||
type reqDeviceAuthorize struct {
|
||||
@@ -24,12 +25,13 @@ type reqDeviceAuthorize struct {
|
||||
//当 op_type 为‘0’,product_id 为‘1’时,不要填写 product_id 字段(会引起不必要错误);
|
||||
//当 op_typy 为‘0’,product_id 不为‘1’时,必须填写 product_id 字段;
|
||||
//当 op_type 为 1 时,不要填写 product_id 字段。
|
||||
ProductId string `json:"product_id,omitempty"`
|
||||
ProductID string `json:"product_id,omitempty"`
|
||||
}
|
||||
|
||||
//ReqDevice 设备授权实体
|
||||
type ReqDevice struct {
|
||||
// 设备的 device id
|
||||
Id string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
// 设备的mac地址 格式采用16进制串的方式(长度为12字节),
|
||||
// 不需要0X前缀,如: 1234567890AB
|
||||
Mac string `json:"mac"`
|
||||
@@ -66,22 +68,22 @@ type ReqDevice struct {
|
||||
BleSimpleProtocol string `json:"ble_simple_protocol,omitempty"`
|
||||
}
|
||||
|
||||
// 授权回调实体
|
||||
type resBaseInfo struct {
|
||||
//ResBaseInfo 授权回调实体
|
||||
type ResBaseInfo struct {
|
||||
BaseInfo struct {
|
||||
DeviceType string `json:"device_type"`
|
||||
DeviceId string `json:"device_id"`
|
||||
DeviceID string `json:"device_id"`
|
||||
} `json:"base_info"`
|
||||
}
|
||||
|
||||
// 授权回调根信息
|
||||
type resDeviceAuthorize struct {
|
||||
util.CommonError
|
||||
Resp []resBaseInfo `json:"resp"`
|
||||
Resp []ResBaseInfo `json:"resp"`
|
||||
}
|
||||
|
||||
// DeviceAuthorize 设备授权
|
||||
func (d *Device) DeviceAuthorize(devices []ReqDevice, opType int, productId string) (res []resBaseInfo, err error) {
|
||||
func (d *Device) DeviceAuthorize(devices []ReqDevice, opType int, product string) (res []ResBaseInfo, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = d.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -93,7 +95,7 @@ func (d *Device) DeviceAuthorize(devices []ReqDevice, opType int, productId stri
|
||||
DeviceNum: fmt.Sprintf("%d", len(devices)),
|
||||
DeviceList: devices,
|
||||
OpType: fmt.Sprintf("%d", opType),
|
||||
ProductId: productId,
|
||||
ProductID: product,
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, req)
|
||||
|
||||
@@ -3,13 +3,15 @@ package device
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
)
|
||||
|
||||
// ReqBind 设备绑定解绑共通实体
|
||||
type ReqBind struct {
|
||||
Ticket string `json:"ticket"`
|
||||
DeviceId string `json:"device_id"`
|
||||
OpenId string `json:"open_id"`
|
||||
DeviceID string `json:"device_id"`
|
||||
OpenID string `json:"open_id"`
|
||||
}
|
||||
type resBind struct {
|
||||
BaseResp util.CommonError `json:"base_resp"`
|
||||
@@ -37,7 +39,7 @@ func (d *Device) Bind(req ReqBind) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Bind 设备解绑
|
||||
// Unbind 设备解绑
|
||||
func (d *Device) Unbind(req ReqBind) (err error) {
|
||||
var accessToken string
|
||||
if accessToken, err = d.GetAccessToken(); err != nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package device
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
)
|
||||
@@ -28,19 +29,20 @@ func NewDevice(context *context.Context) *Device {
|
||||
return device
|
||||
}
|
||||
|
||||
type resDeviceState struct {
|
||||
// ResDeviceState 设备状态响应实体
|
||||
type ResDeviceState struct {
|
||||
util.CommonError
|
||||
Status int `json:"status"`
|
||||
StatusInfo string `json:"status_info"`
|
||||
}
|
||||
|
||||
// State 设备状态查询
|
||||
func (d *Device) State(deviceId string) (res resDeviceState, err error) {
|
||||
func (d *Device) State(device string) (res ResDeviceState, err error) {
|
||||
var accessToken string
|
||||
if accessToken, err = d.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s&device_id=%s", uriState, accessToken, deviceId)
|
||||
uri := fmt.Sprintf("%s?access_token=%s&device_id=%s", uriState, accessToken, device)
|
||||
var response []byte
|
||||
if response, err = util.HTTPGet(uri); err != nil {
|
||||
return
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package device
|
||||
|
||||
// 设备消息响应
|
||||
//MsgDevice 设备消息响应
|
||||
type MsgDevice struct {
|
||||
DeviceType string
|
||||
DeviceID string
|
||||
SessionId string
|
||||
SessionID string
|
||||
OpenID string
|
||||
}
|
||||
|
||||
@@ -3,20 +3,22 @@ package device
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
)
|
||||
|
||||
type resCreateQRCode struct {
|
||||
//ResCreateQRCode 获取二维码的返回实体
|
||||
type ResCreateQRCode struct {
|
||||
util.CommonError
|
||||
DeviceNum int `json:"device_num"`
|
||||
CodeList []struct {
|
||||
DeviceId string `json:"device_id"`
|
||||
DeviceID string `json:"device_id"`
|
||||
Ticket string `json:"ticket"`
|
||||
} `json:"code_list"`
|
||||
}
|
||||
|
||||
// CreateQRCode 获取设备二维码
|
||||
func (d *Device) CreateQRCode(devices []string) (res resCreateQRCode, err error) {
|
||||
func (d *Device) CreateQRCode(devices []string) (res ResCreateQRCode, err error) {
|
||||
var accessToken string
|
||||
if accessToken, err = d.GetAccessToken(); err != nil {
|
||||
return
|
||||
@@ -40,15 +42,16 @@ func (d *Device) CreateQRCode(devices []string) (res resCreateQRCode, err error)
|
||||
return
|
||||
}
|
||||
|
||||
type resVerifyQRCode struct {
|
||||
//ResVerifyQRCode 验证授权结果实体
|
||||
type ResVerifyQRCode struct {
|
||||
util.CommonError
|
||||
DeviceType string `json:"device_type"`
|
||||
DeviceId string `json:"device_id"`
|
||||
DeviceID string `json:"device_id"`
|
||||
Mac string `json:"mac"`
|
||||
}
|
||||
|
||||
// VerifyQRCode 验证设备二维码
|
||||
func (d *Device) VerifyQRCode(ticket string) (res resVerifyQRCode, err error) {
|
||||
func (d *Device) VerifyQRCode(ticket string) (res ResVerifyQRCode, err error) {
|
||||
var accessToken string
|
||||
if accessToken, err = d.GetAccessToken(); err != nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user