-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package auth | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
const apiGetStableAccessToken = "/cgi-bin/stable_token" | ||
|
||
type GetStableAccessTokenRequest struct { | ||
// 必填 填写 client_credential | ||
GrantType string `json:"grant_type"` | ||
// 必填 小程序唯一凭证,即 AppID,可在「微信公众平台 - 设置 - 开发设置」页中获得。(需要已经成为开发者,且帐号没有异常状态) | ||
Appid string `json:"appid"` | ||
// 必填 小程序唯一凭证密钥,即 AppSecret,获取方式同 appid | ||
Secret string `json:"secret"` | ||
// 默认使用 false。1. force_refresh = false 时为普通调用模式,access_token 有效期内重复调用该接口不会更新 access_token;2. 当force_refresh = true 时为强制刷新模式,会导致上次获取的 access_token 失效,并返回新的 access_token | ||
ForceRefresh bool `json:"force_refresh"` | ||
} | ||
|
||
type GetStableAccessTokenResponse struct { | ||
request.CommonError | ||
// 获取到的凭证 | ||
AccessToken string `json:"access_token"` | ||
// 凭证有效时间,单位:秒。目前是7200秒之内的值。 | ||
ExpiresIn int64 `json:"expires_in"` | ||
} | ||
|
||
// 获取稳定版接口调用凭据 | ||
// doc: https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/getStableAccessToken.html | ||
func (cli *Auth) GetStableAccessToken(req *GetStableAccessTokenRequest) (*GetStableAccessTokenResponse, error) { | ||
|
||
api, err := cli.conbineURI(apiGetStableAccessToken, nil, false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(GetStableAccessTokenResponse) | ||
err = cli.request.Post(api, req, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |