1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 21:02:25 +08:00

Compare commits

..

2 Commits

Author SHA1 Message Date
huangx
a6eb2eedc3 check errcode in ListUserOpenIDs (#312)
Co-authored-by: huangxiang <huangxiang@didichuxing.com>
2020-08-11 09:46:59 +08:00
NaRro
404d522d09 feat: 增加获取第三方公众号授权链接的接口 (#310) 2020-08-08 16:57:31 +08:00
2 changed files with 27 additions and 3 deletions

View File

@@ -52,6 +52,8 @@ type Info struct {
// OpenidList 用户列表
type OpenidList struct {
util.CommonError
Total int `json:"total"`
Count int `json:"count"`
Data struct {
@@ -124,13 +126,14 @@ func (user *User) ListUserOpenIDs(nextOpenid ...string) (*OpenidList, error) {
return nil, err
}
userlist := new(OpenidList)
err = json.Unmarshal(response, userlist)
userlist := OpenidList{}
err = util.DecodeWithError(response, &userlist, "ListUserOpenIDs")
if err != nil {
return nil, err
}
return userlist, nil
return &userlist, nil
}
// ListAllUserOpenIDs 返回所有用户OpenID列表

View File

@@ -3,6 +3,7 @@ package context
import (
"encoding/json"
"fmt"
"net/url"
"time"
"github.com/silenceper/wechat/v2/util"
@@ -14,6 +15,8 @@ const (
queryAuthURL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%s"
refreshTokenURL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%s"
getComponentInfoURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%s"
componentLoginURL = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s&auth_type=%d&biz_appid=%s"
bindComponentURL = "https://mp.weixin.qq.com/safe/bindcomponent?action=bindcomponent&auth_type=%d&no_scan=1&component_appid=%s&pre_auth_code=%s&redirect_uri=%s&biz_appid=%s#wechat_redirect"
//TODO 获取授权方选项信息
//getComponentConfigURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option?component_access_token=%s"
//TODO 获取已授权的账号信息
@@ -86,6 +89,24 @@ func (ctx *Context) GetPreCode() (string, error) {
return ret.PreCode, nil
}
// GetComponentLoginPage 获取第三方公众号授权链接(扫码授权)
func (ctx *Context) GetComponentLoginPage(redirectURI string, authType int, bizAppID string) (string, error) {
code, err := ctx.GetPreCode()
if err != nil {
return "", err
}
return fmt.Sprintf(componentLoginURL, ctx.AppID, code, url.QueryEscape(redirectURI), authType, bizAppID), nil
}
// GetBindComponentURL 获取第三方公众号授权链接(链接跳转,适用移动端)
func (ctx *Context) GetBindComponentURL(redirectURI string, authType int, bizAppID string) (string, error) {
code, err := ctx.GetPreCode()
if err != nil {
return "", err
}
return fmt.Sprintf(bindComponentURL, authType, ctx.AppID, code, url.QueryEscape(redirectURI), bizAppID), nil
}
// ID 微信返回接口中各种类型字段
type ID struct {
ID int `json:"id"`