Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: work js-api signature #818

Merged
merged 16 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions credential/default_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (ak *WorkAccessToken) GetAccessTokenContext(ctx context.Context) (accessTok

// 构建缓存key
var accessTokenCacheKey string

if ak.AgentID != "" {
// 如果设置了AgentID,使用新的key格式
accessTokenCacheKey = fmt.Sprintf("%s_access_token_%s_%s", ak.cacheKeyPrefix, ak.CorpID, ak.AgentID)
Expand Down
9 changes: 5 additions & 4 deletions work/jsapi/jsapi.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package jsapi

import (
"strconv"

"fmt"
houseme marked this conversation as resolved.
Show resolved Hide resolved
"github.com/silenceper/wechat/v2/credential"
"github.com/silenceper/wechat/v2/util"
"github.com/silenceper/wechat/v2/work/context"
Expand Down Expand Up @@ -49,7 +48,8 @@ func (js *Js) GetConfig(uri string) (config *Config, err error) {
}
config.NonceStr = util.RandomStr(16)
config.Timestamp = util.GetCurrTS()
config.Signature = util.Signature(ticketStr, config.NonceStr, strconv.FormatInt(config.Timestamp, 10), uri)
str := fmt.Sprintf("jsapi_ticket=%s&noncestr=%s&timestamp=%d&url=%s", ticketStr, config.NonceStr, config.Timestamp, uri)
config.Signature = util.Signature(str)
return
}

Expand All @@ -68,6 +68,7 @@ func (js *Js) GetAgentConfig(uri string) (config *Config, err error) {
}
config.NonceStr = util.RandomStr(16)
config.Timestamp = util.GetCurrTS()
config.Signature = util.Signature(ticketStr, config.NonceStr, strconv.FormatInt(config.Timestamp, 10), uri)
str := fmt.Sprintf("jsapi_ticket=%s&noncestr=%s&timestamp=%d&url=%s", ticketStr, config.NonceStr, config.Timestamp, uri)
config.Signature = util.Signature(str)
return
}