- update wechatoffice

master
李光春 2 years ago
parent 9c109c5add
commit 028ad2b6db

@ -19,5 +19,5 @@ func (c *Client) GetJsapiTicket() string {
}
func (c *Client) getJsapiTicketCacheKeyName() string {
return fmt.Sprintf("wechat_jsapi_ticket:%v", c.getAppId())
return fmt.Sprintf("wechat_jsapi_ticket:%v", c.GetAppId())
}

@ -30,7 +30,7 @@ func newCgiBinTokenResult(result CgiBinTokenResponse, body []byte, http goreques
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
func (c *Client) CgiBinToken() *CgiBinTokenResult {
// request
request, err := c.request(fmt.Sprintf(apiUrl+"/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", c.getAppId(), c.getAppSecret()), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf(apiUrl+"/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", c.GetAppId(), c.GetAppSecret()), map[string]interface{}{}, http.MethodGet)
// 定义
var response CgiBinTokenResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -18,5 +18,5 @@ func (c *Client) GetAccessToken() string {
}
func (c *Client) getAccessTokenCacheKeyName() string {
return fmt.Sprintf("wechat_access_token:%v", c.getAppId())
return fmt.Sprintf("wechat_access_token:%v", c.GetAppId())
}

@ -1,10 +1,10 @@
package wechatoffice
func (c *Client) getAppId() string {
func (c *Client) GetAppId() string {
return c.config.AppId
}
func (c *Client) getAppSecret() string {
func (c *Client) GetAppSecret() string {
return c.config.AppSecret
}

@ -9,7 +9,7 @@ import (
// https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#0
func (c *Client) Oauth2(redirectUri, state string) string {
param := url.Values{}
param.Add("appid", c.getAppId()) // 公众号的唯一标识
param.Add("appid", c.GetAppId()) // 公众号的唯一标识
param.Add("redirect_uri", redirectUri) // 授权后重定向的回调链接地址, 请使用 urlEncode 对链接进行处理
param.Add("response_type", "code") // 返回类型
param.Add("scope", "snsapi_userinfo") // 应用授权作用域

@ -30,7 +30,7 @@ func (c *Client) Share(url string) *ShareResult {
c.getAccessToken()
c.config.JsapiTicket = c.GetJsapiTicket()
var response ShareResponse
response.AppId = c.getAppId()
response.AppId = c.GetAppId()
response.NonceStr = gorandom.Alphanumeric(32)
response.Timestamp = time.Now().Unix()
response.Url = url

@ -28,7 +28,7 @@ func newSnsJsCode2sessionResult(result SnsJsCode2sessionResponse, body []byte, h
func (c *Client) SnsJsCode2session(jsCode string) *SnsJsCode2sessionResult {
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code", c.getAppId(), c.getAppSecret(), jsCode), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf(apiUrl+"/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code", c.GetAppId(), c.GetAppSecret(), jsCode), map[string]interface{}{}, http.MethodGet)
// 定义
var response SnsJsCode2sessionResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -30,7 +30,7 @@ func newSnsOauth2AccessTokenResult(result SnsOauth2AccessTokenResponse, body []b
// https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#0
func (c *Client) SnsOauth2AccessToken(code string) *SnsOauth2AccessTokenResult {
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code", c.getAppId(), c.getAppSecret(), code), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf(apiUrl+"/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code", c.GetAppId(), c.GetAppSecret(), code), map[string]interface{}{}, http.MethodGet)
// 定义
var response SnsOauth2AccessTokenResponse
err = json.Unmarshal(request.ResponseBody, &response)

Loading…
Cancel
Save