1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-17 03:02:26 +08:00

[feature] Format the code and improve Mini Program authorization to o… (#473)

* [feature] Format the code and improve Mini Program authorization to obtain openid(miniprogram/auth/auth.go Code2Session)

* [feature] CheckEncryptedData (https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html)

* upgrade json error

* upgrade json error

Co-authored-by: houseme <houseme@outlook.com>
This commit is contained in:
houseme
2021-09-08 11:03:23 +08:00
committed by GitHub
parent 47adf42208
commit 96c1f98944
90 changed files with 787 additions and 760 deletions

View File

@@ -18,42 +18,42 @@ const (
menuSelfMenuInfoURL = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info"
)
//Menu struct
// Menu struct
type Menu struct {
*context.Context
}
//reqMenu 设置菜单请求数据
// reqMenu 设置菜单请求数据
type reqMenu struct {
Button []*Button `json:"button,omitempty"`
MatchRule *MatchRule `json:"matchrule,omitempty"`
}
//reqDeleteConditional 删除个性化菜单请求数据
// reqDeleteConditional 删除个性化菜单请求数据
type reqDeleteConditional struct {
MenuID int64 `json:"menuid"`
}
//reqMenuTryMatch 菜单匹配请求
// reqMenuTryMatch 菜单匹配请求
type reqMenuTryMatch struct {
UserID string `json:"user_id"`
}
//resConditionalMenu 个性化菜单返回结果
// resConditionalMenu 个性化菜单返回结果
type resConditionalMenu struct {
Button []Button `json:"button"`
MatchRule MatchRule `json:"matchrule"`
MenuID int64 `json:"menuid"`
}
//resMenuTryMatch 菜单匹配请求结果
// resMenuTryMatch 菜单匹配请求结果
type resMenuTryMatch struct {
util.CommonError
Button []Button `json:"button"`
}
//ResMenu 查询菜单的返回数据
// ResMenu 查询菜单的返回数据
type ResMenu struct {
util.CommonError
@@ -64,7 +64,7 @@ type ResMenu struct {
Conditionalmenu []resConditionalMenu `json:"conditionalmenu"`
}
//ResSelfMenuInfo 自定义菜单配置返回结果
// ResSelfMenuInfo 自定义菜单配置返回结果
type ResSelfMenuInfo struct {
util.CommonError
@@ -74,7 +74,7 @@ type ResSelfMenuInfo struct {
} `json:"selfmenu_info"`
}
//SelfMenuButton 自定义菜单配置详情
// SelfMenuButton 自定义菜单配置详情
type SelfMenuButton struct {
Type string `json:"type"`
Name string `json:"name"`
@@ -89,7 +89,7 @@ type SelfMenuButton struct {
} `json:"news_info,omitempty"`
}
//ButtonNew 图文消息菜单
// ButtonNew 图文消息菜单
type ButtonNew struct {
Title string `json:"title"`
Author string `json:"author"`
@@ -100,7 +100,7 @@ type ButtonNew struct {
SourceURL string `json:"source_url"`
}
//MatchRule 个性化菜单规则
// MatchRule 个性化菜单规则
type MatchRule struct {
GroupID string `json:"group_id,omitempty"`
Sex string `json:"sex,omitempty"`
@@ -111,14 +111,14 @@ type MatchRule struct {
Language string `json:"language,omitempty"`
}
//NewMenu 实例
// NewMenu 实例
func NewMenu(context *context.Context) *Menu {
menu := new(Menu)
menu.Context = context
return menu
}
//SetMenu 设置按钮
// SetMenu 设置按钮
func (menu *Menu) SetMenu(buttons []*Button) error {
accessToken, err := menu.GetAccessToken()
if err != nil {
@@ -138,7 +138,7 @@ func (menu *Menu) SetMenu(buttons []*Button) error {
return util.DecodeWithCommonError(response, "SetMenu")
}
//SetMenuByJSON 设置按钮
// SetMenuByJSON 设置按钮
func (menu *Menu) SetMenuByJSON(jsonInfo string) error {
accessToken, err := menu.GetAccessToken()
if err != nil {
@@ -155,7 +155,7 @@ func (menu *Menu) SetMenuByJSON(jsonInfo string) error {
return util.DecodeWithCommonError(response, "SetMenuByJSON")
}
//GetMenu 获取菜单配置
// GetMenu 获取菜单配置
func (menu *Menu) GetMenu() (resMenu ResMenu, err error) {
var accessToken string
accessToken, err = menu.GetAccessToken()
@@ -179,7 +179,7 @@ func (menu *Menu) GetMenu() (resMenu ResMenu, err error) {
return
}
//DeleteMenu 删除菜单
// DeleteMenu 删除菜单
func (menu *Menu) DeleteMenu() error {
accessToken, err := menu.GetAccessToken()
if err != nil {
@@ -194,7 +194,7 @@ func (menu *Menu) DeleteMenu() error {
return util.DecodeWithCommonError(response, "GetMenu")
}
//AddConditional 添加个性化菜单
// AddConditional 添加个性化菜单
func (menu *Menu) AddConditional(buttons []*Button, matchRule *MatchRule) error {
accessToken, err := menu.GetAccessToken()
if err != nil {
@@ -215,7 +215,7 @@ func (menu *Menu) AddConditional(buttons []*Button, matchRule *MatchRule) error
return util.DecodeWithCommonError(response, "AddConditional")
}
//AddConditionalByJSON 添加个性化菜单
// AddConditionalByJSON 添加个性化菜单
func (menu *Menu) AddConditionalByJSON(jsonInfo string) error {
accessToken, err := menu.GetAccessToken()
if err != nil {
@@ -231,7 +231,7 @@ func (menu *Menu) AddConditionalByJSON(jsonInfo string) error {
return util.DecodeWithCommonError(response, "AddConditional")
}
//DeleteConditional 删除个性化菜单
// DeleteConditional 删除个性化菜单
func (menu *Menu) DeleteConditional(menuID int64) error {
accessToken, err := menu.GetAccessToken()
if err != nil {
@@ -251,7 +251,7 @@ func (menu *Menu) DeleteConditional(menuID int64) error {
return util.DecodeWithCommonError(response, "DeleteConditional")
}
//MenuTryMatch 菜单匹配
// MenuTryMatch 菜单匹配
func (menu *Menu) MenuTryMatch(userID string) (buttons []Button, err error) {
var accessToken string
accessToken, err = menu.GetAccessToken()
@@ -278,7 +278,7 @@ func (menu *Menu) MenuTryMatch(userID string) (buttons []Button, err error) {
return
}
//GetCurrentSelfMenuInfo 获取自定义菜单配置接口
// GetCurrentSelfMenuInfo 获取自定义菜单配置接口
func (menu *Menu) GetCurrentSelfMenuInfo() (resSelfMenuInfo ResSelfMenuInfo, err error) {
var accessToken string
accessToken, err = menu.GetAccessToken()