mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-13 01:02:27 +08:00
Merge pull request #85 from Chyroc/add-user-updare-remark
add: user update-remark api
This commit is contained in:
@@ -184,13 +184,6 @@ func (material *Material) DeleteMaterial(mediaID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var resDeleteMaterial util.CommonError
|
|
||||||
err = json.Unmarshal(response, &resDeleteMaterial)
|
return util.DecodeWithCommonError(response, "DeleteMaterial")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if resDeleteMaterial.ErrCode != 0 {
|
|
||||||
return fmt.Errorf("DeleteMaterial error : errcode=%v , errmsg=%v", resDeleteMaterial.ErrCode, resDeleteMaterial.ErrMsg)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
44
menu/menu.go
44
menu/menu.go
@@ -134,15 +134,8 @@ func (menu *Menu) SetMenu(buttons []*Button) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var commError util.CommonError
|
|
||||||
err = json.Unmarshal(response, &commError)
|
return util.DecodeWithCommonError(response, "SetMenu")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if commError.ErrCode != 0 {
|
|
||||||
return fmt.Errorf("SetMenu Error , errcode=%d , errmsg=%s", commError.ErrCode, commError.ErrMsg)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetMenu 获取菜单配置
|
//GetMenu 获取菜单配置
|
||||||
@@ -180,15 +173,8 @@ func (menu *Menu) DeleteMenu() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var commError util.CommonError
|
|
||||||
err = json.Unmarshal(response, &commError)
|
return util.DecodeWithCommonError(response, "GetMenu")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if commError.ErrCode != 0 {
|
|
||||||
return fmt.Errorf("GetMenu Error , errcode=%d , errmsg=%s", commError.ErrCode, commError.ErrMsg)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//AddConditional 添加个性化菜单
|
//AddConditional 添加个性化菜单
|
||||||
@@ -208,15 +194,8 @@ func (menu *Menu) AddConditional(buttons []*Button, matchRule *MatchRule) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var commError util.CommonError
|
|
||||||
err = json.Unmarshal(response, &commError)
|
return util.DecodeWithCommonError(response, "AddConditional")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if commError.ErrCode != 0 {
|
|
||||||
return fmt.Errorf("AddConditional Error , errcode=%d , errmsg=%s", commError.ErrCode, commError.ErrMsg)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//DeleteConditional 删除个性化菜单
|
//DeleteConditional 删除个性化菜单
|
||||||
@@ -235,15 +214,8 @@ func (menu *Menu) DeleteConditional(menuID int64) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var commError util.CommonError
|
|
||||||
err = json.Unmarshal(response, &commError)
|
return util.DecodeWithCommonError(response, "DeleteConditional")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if commError.ErrCode != 0 {
|
|
||||||
return fmt.Errorf("DeleteConditional Error , errcode=%d , errmsg=%s", commError.ErrCode, commError.ErrMsg)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//MenuTryMatch 菜单匹配
|
//MenuTryMatch 菜单匹配
|
||||||
|
|||||||
23
user/user.go
23
user/user.go
@@ -9,7 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
userInfoURL = "https://api.weixin.qq.com/cgi-bin/user/info"
|
userInfoURL = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=zh_CN"
|
||||||
|
updateRemarkURL = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
//User 用户管理
|
//User 用户管理
|
||||||
@@ -52,7 +53,7 @@ func (user *User) GetUserInfo(openID string) (userInfo *Info, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?access_token=%s&openid=%s&lang=zh_CN", userInfoURL, accessToken, openID)
|
uri := fmt.Sprintf(userInfoURL, accessToken, openID)
|
||||||
var response []byte
|
var response []byte
|
||||||
response, err = util.HTTPGet(uri)
|
response, err = util.HTTPGet(uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -69,3 +70,21 @@ func (user *User) GetUserInfo(openID string) (userInfo *Info, err error) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateRemark 设置用户备注名
|
||||||
|
func (user *User) UpdateRemark(openID, remark string) (err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = user.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := fmt.Sprintf(updateRemarkURL, accessToken)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(uri, map[string]string{"openid": openID, "remark": remark})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return util.DecodeWithCommonError(response, "UpdateRemark")
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,25 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
// CommonError 微信返回的通用错误json
|
// CommonError 微信返回的通用错误json
|
||||||
type CommonError struct {
|
type CommonError struct {
|
||||||
ErrCode int64 `json:"errcode"`
|
ErrCode int64 `json:"errcode"`
|
||||||
ErrMsg string `json:"errmsg"`
|
ErrMsg string `json:"errmsg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DecodeWithCommonError 将返回值按照CommonError解析
|
||||||
|
func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
||||||
|
var commError CommonError
|
||||||
|
err = json.Unmarshal(response, &commError)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if commError.ErrCode != 0 {
|
||||||
|
return fmt.Errorf("%s Error , errcode=%d , errmsg=%s", apiName, commError.ErrCode, commError.ErrMsg)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user