12345678910111213141516171819202122232425262728293031323334353637 |
- package mp
-
- import (
- "net/url"
- "strings"
-
- wxerr "gitee.com/yansen_zh/wxcomponent/errors"
- )
-
- // MpWebAccessTokenResult 网页授权, 通过 code 换取 access_token 返回值
- type MpWebAccessTokenResult struct {
- wxerr.Error
- // AccessToken 接口调用凭证
- AccessToken string `json:"access_token"`
- // ExpiresIn access_token 接口调用凭证超时时间,单位(秒)
- ExpiresIn int `json:"expires_in"`
- // RefreshToken 用户刷新 access_token
- RefreshToken string `json:"refresh_token"`
- // Openid 授权用户唯一标识
- OpenID string `json:"openid"`
- // Scope 用户授权的作用域,使用逗号(,)分隔
- Scope string `json:"scope"`
- }
-
- // GetAuthorizationCodeLink 代公众号发起网页授权, 构造授权链接
- // redirectURI 必须是未经编码的原始网址字符串
- func GetAuthorizationCodeLink(componentAppID, appID, redirectURI, state string, scopes ...string) string {
- params := url.Values{}
- params.Set("appid", appID)
- params.Set("redirect_uri", redirectURI)
- params.Set("response_type", "code")
- params.Set("scope", strings.Join(scopes, ","))
- params.Set("state", state)
- params.Set("component_appid", componentAppID)
-
- return "https://open.weixin.qq.com/connect/oauth2/authorize?" + params.Encode()
- }
|