Compare commits
No commits in common. "1988b121ed20969c6f80ec96cab495cdb77539ad" and "f06581c5d70521017fed540052a16c0ab09e3288" have entirely different histories.
1988b121ed
...
f06581c5d7
|
@ -18,14 +18,6 @@ const (
|
|||
code2UserinfoUrl string = "https://api.weixin.qq.com/sns/userinfo"
|
||||
oaQrCodeCreateUrl string = "https://api.weixin.qq.com/cgi-bin/qrcode/create"
|
||||
userInfoByOpenid string = "https://api.weixin.qq.com/cgi-bin/user/info"
|
||||
CreateOaMenu string = "https://api.weixin.qq.com/cgi-bin/menu/create"
|
||||
QueryOaMenu string = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info"
|
||||
DeleteOaMenu string = "https://api.weixin.qq.com/cgi-bin/menu/delete"
|
||||
)
|
||||
|
||||
const (
|
||||
OaMenuTypeClick = "click"
|
||||
OaMenuTypeView = "view"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
|
@ -48,14 +40,6 @@ type BaseSdk struct {
|
|||
lock sync.Mutex
|
||||
}
|
||||
|
||||
type OaMenuButton struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
SubButton []*OaMenuButton `json:"sub_button"`
|
||||
}
|
||||
|
||||
func (o *BaseSdk) getAccessToken() (string, error) {
|
||||
o.lock.Lock()
|
||||
defer o.lock.Unlock()
|
||||
|
|
|
@ -97,52 +97,3 @@ func (o *OaSdk) GetUserInfoByOpenid(openid string) (*UserInfo, error) {
|
|||
user.Openid = openid
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (o *OaSdk) CreateMenu(buttons []*OaMenuButton) error {
|
||||
accessToken, err := o.getAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bodyMp := make(map[string]interface{})
|
||||
bodyMp["button"] = buttons
|
||||
bodyBytes, _ := json.Marshal(bodyMp)
|
||||
|
||||
url := fmt.Sprintf("%s?access_token=%s", CreateOaMenu, accessToken)
|
||||
res, err := http.Post(url, "application/json", bytes.NewBuffer(bodyBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
all, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
g := gjson.ParseBytes(all)
|
||||
errCode := g.Get("errcode").Int()
|
||||
if errCode != 0 {
|
||||
return fmt.Errorf("%d:%s", errCode, g.Get("errmsg").String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *OaSdk) DeleteMenu() error {
|
||||
accessToken, err := o.getAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("%s?access_token=%s", DeleteOaMenu, accessToken)
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
all, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
g := gjson.ParseBytes(all)
|
||||
errCode := g.Get("errcode").Int()
|
||||
if errCode != 0 {
|
||||
return fmt.Errorf("%d:%s", errCode, g.Get("errmsg").String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue