MCPcopy Index your code
hub / github.com/TruthHun/BookStack / GetAccessToken

Function GetAccessToken

utils/wechat.go:29–47  ·  view source on GitHub ↗

获取access_token

()

Source from the content-addressed store, hash-verified

27
28// 获取access_token
29func GetAccessToken() (token *WechatToken) {
30 now := time.Now().Unix()
31 if now < wechatToken.ExpiresIn-600 { //提前10分钟失效
32 return wechatToken
33 }
34 appId := beego.AppConfig.String("appId")
35 appSecret := beego.AppConfig.String("appSecret")
36 api := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%v&secret=%v", appId, appSecret)
37 req := httplib.Get(api).SetTimeout(10*time.Second, 10*time.Second).SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
38 resp, err := req.String()
39 if err != nil {
40 beego.Error(err.Error())
41 }
42 token = &WechatToken{}
43 json.Unmarshal([]byte(resp), token)
44 token.ExpiresIn = now + token.ExpiresIn
45 wechatToken = token
46 return
47}
48
49// 获取书籍页面小程序码
50func GetBookWXACode(accessToken string, bookId int) (tmpFile string, err error) {

Callers 1

CreateWechatCodeMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected