- EncodeToString in jingding.signParams

This commit is contained in:
gazebo
2019-03-08 11:58:33 +08:00
parent 470ca6da2f
commit 9179fa3559

View File

@@ -4,7 +4,9 @@ import (
"bytes" "bytes"
"crypto/hmac" "crypto/hmac"
"crypto/sha256" "crypto/sha256"
"encoding/base64"
"net/http" "net/http"
"net/url"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -90,7 +92,7 @@ func (a *API) RetrieveToken() (token string, err error) {
func (a *API) signParams(timestamp int64) string { func (a *API) signParams(timestamp int64) string {
mac := hmac.New(sha256.New, []byte(a.GetSecret())) mac := hmac.New(sha256.New, []byte(a.GetSecret()))
mac.Write([]byte(utils.Int64ToStr(timestamp))) mac.Write([]byte(utils.Int64ToStr(timestamp)))
return string(mac.Sum(nil)) return url.QueryEscape(base64.StdEncoding.EncodeToString(mac.Sum(nil)))
} }
func (a *API) AccessAPI(action string, params map[string]interface{}, bodyMap map[string]interface{}) (retVal map[string]interface{}, err error) { func (a *API) AccessAPI(action string, params map[string]interface{}, bodyMap map[string]interface{}) (retVal map[string]interface{}, err error) {