From 733c53a044440b3b4a0c97a1fde82ec5571f3483 Mon Sep 17 00:00:00 2001 From: "larry.liu" Date: Fri, 15 Nov 2019 16:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device/bind.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- device/device.go | 2 ++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/device/bind.go b/device/bind.go index 5168a74..6d2b3d0 100644 --- a/device/bind.go +++ b/device/bind.go @@ -9,9 +9,9 @@ import ( // ReqBind 设备绑定解绑共通实体 type ReqBind struct { - Ticket string `json:"ticket"` + Ticket string `json:"ticket,omitempty"` DeviceID string `json:"device_id"` - OpenID string `json:"open_id"` + OpenID string `json:"openid"` } type resBind struct { BaseResp util.CommonError `json:"base_resp"` @@ -60,3 +60,47 @@ func (d *Device) Unbind(req ReqBind) (err error) { } return } + +// CompelBind 强制绑定用户和设备 +func (d *Device) CompelBind(req ReqBind) (err error) { + var accessToken string + if accessToken, err = d.GetAccessToken(); err != nil { + return + } + uri := fmt.Sprintf("%s?access_token=%s", uriCompelBind, accessToken) + var response []byte + if response, err = util.PostJSON(uri, req); err != nil { + return + } + var result resBind + if err = json.Unmarshal(response, &result); err != nil { + return + } + if result.BaseResp.ErrCode != 0 { + err = fmt.Errorf("DeviceBind Error , errcode=%d , errmsg=%s", result.BaseResp.ErrCode, result.BaseResp.ErrMsg) + return + } + return +} + +// CompelUnbind 强制解绑用户和设备 +func (d *Device) CompelUnbind(req ReqBind) (err error) { + var accessToken string + if accessToken, err = d.GetAccessToken(); err != nil { + return + } + uri := fmt.Sprintf("%s?access_token=%s", uriCompelUnbind, accessToken) + var response []byte + if response, err = util.PostJSON(uri, req); err != nil { + return + } + var result resBind + if err = json.Unmarshal(response, &result); err != nil { + return + } + if result.BaseResp.ErrCode != 0 { + err = fmt.Errorf("DeviceBind Error , errcode=%d , errmsg=%s", result.BaseResp.ErrCode, result.BaseResp.ErrMsg) + return + } + return +} diff --git a/device/device.go b/device/device.go index bdc1059..3c0074a 100644 --- a/device/device.go +++ b/device/device.go @@ -14,6 +14,8 @@ const ( uriVerifyQRCode = "https://api.weixin.qq.com/device/verify_qrcode" uriBind = "https://api.weixin.qq.com/device/bind" uriUnbind = "https://api.weixin.qq.com/device/unbind" + uriCompelBind = "https://api.weixin.qq.com/device/compel_bind" + uriCompelUnbind = "https://api.weixin.qq.com/device/compel_unbind" uriState = "https://api.weixin.qq.com/device/get_stat" )