1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-09 23:22:27 +08:00

格式化代码样式

This commit is contained in:
larry.liu
2019-11-15 15:56:38 +08:00
parent d806d1c968
commit 5617c9512d
5 changed files with 35 additions and 26 deletions

View File

@@ -3,14 +3,15 @@ package device
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/silenceper/wechat/util" "github.com/silenceper/wechat/util"
) )
const ( const (
//添加设备标识 // DeviceAdd 添加设备标识
DEVICE_ADD = iota DeviceAdd = iota
//更新设备标识 // DeviceUpgrade 更新设备标识
DEVCIE_UPGRADE DeviceUpgrade
) )
type reqDeviceAuthorize struct { type reqDeviceAuthorize struct {
@@ -24,12 +25,13 @@ type reqDeviceAuthorize struct {
//当 op_type 为0product_id 为1不要填写 product_id 字段(会引起不必要错误); //当 op_type 为0product_id 为1不要填写 product_id 字段(会引起不必要错误);
//当 op_typy 为0product_id 不为1必须填写 product_id 字段; //当 op_typy 为0product_id 不为1必须填写 product_id 字段;
//当 op_type 为 1 时,不要填写 product_id 字段。 //当 op_type 为 1 时,不要填写 product_id 字段。
ProductId string `json:"product_id,omitempty"` ProductID string `json:"product_id,omitempty"`
} }
//ReqDevice 设备授权实体
type ReqDevice struct { type ReqDevice struct {
// 设备的 device id // 设备的 device id
Id string `json:"id"` ID string `json:"id"`
// 设备的mac地址 格式采用16进制串的方式长度为12字节 // 设备的mac地址 格式采用16进制串的方式长度为12字节
// 不需要0X前缀 1234567890AB // 不需要0X前缀 1234567890AB
Mac string `json:"mac"` Mac string `json:"mac"`
@@ -66,22 +68,22 @@ type ReqDevice struct {
BleSimpleProtocol string `json:"ble_simple_protocol,omitempty"` BleSimpleProtocol string `json:"ble_simple_protocol,omitempty"`
} }
// 授权回调实体 //ResBaseInfo 授权回调实体
type resBaseInfo struct { type ResBaseInfo struct {
BaseInfo struct { BaseInfo struct {
DeviceType string `json:"device_type"` DeviceType string `json:"device_type"`
DeviceId string `json:"device_id"` DeviceID string `json:"device_id"`
} `json:"base_info"` } `json:"base_info"`
} }
// 授权回调根信息 // 授权回调根信息
type resDeviceAuthorize struct { type resDeviceAuthorize struct {
util.CommonError util.CommonError
Resp []resBaseInfo `json:"resp"` Resp []ResBaseInfo `json:"resp"`
} }
// DeviceAuthorize 设备授权 // 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 var accessToken string
accessToken, err = d.GetAccessToken() accessToken, err = d.GetAccessToken()
if err != nil { if err != nil {
@@ -93,7 +95,7 @@ func (d *Device) DeviceAuthorize(devices []ReqDevice, opType int, productId stri
DeviceNum: fmt.Sprintf("%d", len(devices)), DeviceNum: fmt.Sprintf("%d", len(devices)),
DeviceList: devices, DeviceList: devices,
OpType: fmt.Sprintf("%d", opType), OpType: fmt.Sprintf("%d", opType),
ProductId: productId, ProductID: product,
} }
var response []byte var response []byte
response, err = util.PostJSON(uri, req) response, err = util.PostJSON(uri, req)

View File

@@ -3,13 +3,15 @@ package device
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/silenceper/wechat/util" "github.com/silenceper/wechat/util"
) )
// ReqBind 设备绑定解绑共通实体
type ReqBind struct { type ReqBind struct {
Ticket string `json:"ticket"` Ticket string `json:"ticket"`
DeviceId string `json:"device_id"` DeviceID string `json:"device_id"`
OpenId string `json:"open_id"` OpenID string `json:"open_id"`
} }
type resBind struct { type resBind struct {
BaseResp util.CommonError `json:"base_resp"` BaseResp util.CommonError `json:"base_resp"`
@@ -37,7 +39,7 @@ func (d *Device) Bind(req ReqBind) (err error) {
return return
} }
// Bind 设备解绑 // Unbind 设备解绑
func (d *Device) Unbind(req ReqBind) (err error) { func (d *Device) Unbind(req ReqBind) (err error) {
var accessToken string var accessToken string
if accessToken, err = d.GetAccessToken(); err != nil { if accessToken, err = d.GetAccessToken(); err != nil {

View File

@@ -3,6 +3,7 @@ package device
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/silenceper/wechat/context" "github.com/silenceper/wechat/context"
"github.com/silenceper/wechat/util" "github.com/silenceper/wechat/util"
) )
@@ -28,19 +29,20 @@ func NewDevice(context *context.Context) *Device {
return device return device
} }
type resDeviceState struct { // ResDeviceState 设备状态响应实体
type ResDeviceState struct {
util.CommonError util.CommonError
Status int `json:"status"` Status int `json:"status"`
StatusInfo string `json:"status_info"` StatusInfo string `json:"status_info"`
} }
// State 设备状态查询 // State 设备状态查询
func (d *Device) State(deviceId string) (res resDeviceState, err error) { func (d *Device) State(device string) (res ResDeviceState, err error) {
var accessToken string var accessToken string
if accessToken, err = d.GetAccessToken(); err != nil { if accessToken, err = d.GetAccessToken(); err != nil {
return 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 var response []byte
if response, err = util.HTTPGet(uri); err != nil { if response, err = util.HTTPGet(uri); err != nil {
return return

View File

@@ -1,9 +1,9 @@
package device package device
// 设备消息响应 //MsgDevice 设备消息响应
type MsgDevice struct { type MsgDevice struct {
DeviceType string DeviceType string
DeviceID string DeviceID string
SessionId string SessionID string
OpenID string OpenID string
} }

View File

@@ -3,20 +3,22 @@ package device
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/silenceper/wechat/util" "github.com/silenceper/wechat/util"
) )
type resCreateQRCode struct { //ResCreateQRCode 获取二维码的返回实体
type ResCreateQRCode struct {
util.CommonError util.CommonError
DeviceNum int `json:"device_num"` DeviceNum int `json:"device_num"`
CodeList []struct { CodeList []struct {
DeviceId string `json:"device_id"` DeviceID string `json:"device_id"`
Ticket string `json:"ticket"` Ticket string `json:"ticket"`
} `json:"code_list"` } `json:"code_list"`
} }
// CreateQRCode 获取设备二维码 // CreateQRCode 获取设备二维码
func (d *Device) CreateQRCode(devices []string) (res resCreateQRCode, err error) { func (d *Device) CreateQRCode(devices []string) (res ResCreateQRCode, err error) {
var accessToken string var accessToken string
if accessToken, err = d.GetAccessToken(); err != nil { if accessToken, err = d.GetAccessToken(); err != nil {
return return
@@ -40,15 +42,16 @@ func (d *Device) CreateQRCode(devices []string) (res resCreateQRCode, err error)
return return
} }
type resVerifyQRCode struct { //ResVerifyQRCode 验证授权结果实体
type ResVerifyQRCode struct {
util.CommonError util.CommonError
DeviceType string `json:"device_type"` DeviceType string `json:"device_type"`
DeviceId string `json:"device_id"` DeviceID string `json:"device_id"`
Mac string `json:"mac"` Mac string `json:"mac"`
} }
// VerifyQRCode 验证设备二维码 // VerifyQRCode 验证设备二维码
func (d *Device) VerifyQRCode(ticket string) (res resVerifyQRCode, err error) { func (d *Device) VerifyQRCode(ticket string) (res ResVerifyQRCode, err error) {
var accessToken string var accessToken string
if accessToken, err = d.GetAccessToken(); err != nil { if accessToken, err = d.GetAccessToken(); err != nil {
return return