mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-08 22:52:27 +08:00
improve comment ,参考:https://github.com/huacnlee/autocorrect
This commit is contained in:
@@ -10,15 +10,15 @@ import (
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// getTicketURL 获取ticket的url
|
||||
// getTicketURL 获取 ticket 的 url
|
||||
const getTicketURL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi"
|
||||
|
||||
// DefaultJsTicket 默认获取js ticket方法
|
||||
// DefaultJsTicket 默认获取 js ticket 方法
|
||||
type DefaultJsTicket struct {
|
||||
appID string
|
||||
cacheKeyPrefix string
|
||||
cache cache.Cache
|
||||
// jsAPITicket 读写锁 同一个AppID一个
|
||||
// jsAPITicket 读写锁 同一个 AppID 一个
|
||||
jsAPITicketLock *sync.Mutex
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func NewDefaultJsTicket(appID string, cacheKeyPrefix string, cache cache.Cache)
|
||||
}
|
||||
}
|
||||
|
||||
// ResTicket 请求jsapi_tikcet返回结果
|
||||
// ResTicket 请求 jsapi_tikcet 返回结果
|
||||
type ResTicket struct {
|
||||
util.CommonError
|
||||
|
||||
@@ -40,9 +40,9 @@ type ResTicket struct {
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
}
|
||||
|
||||
// GetTicket 获取jsapi_ticket
|
||||
// GetTicket 获取 jsapi_ticket
|
||||
func (js *DefaultJsTicket) GetTicket(accessToken string) (ticketStr string, err error) {
|
||||
// 先从cache中取
|
||||
// 先从 cache 中取
|
||||
jsAPITicketCacheKey := fmt.Sprintf("%s_jsapi_ticket_%s", js.cacheKeyPrefix, js.appID)
|
||||
if val := js.cache.Get(jsAPITicketCacheKey); val != nil {
|
||||
return val.(string), nil
|
||||
@@ -67,7 +67,7 @@ func (js *DefaultJsTicket) GetTicket(accessToken string) (ticketStr string, err
|
||||
return
|
||||
}
|
||||
|
||||
// GetTicketFromServer 从服务器中获取ticket
|
||||
// GetTicketFromServer 从服务器中获取 ticket
|
||||
func GetTicketFromServer(accessToken string) (ticket ResTicket, err error) {
|
||||
var response []byte
|
||||
url := fmt.Sprintf(getTicketURL, accessToken)
|
||||
|
||||
Reference in New Issue
Block a user