Ver código fonte

access token also using config parameter

master
Patrick Peng Sun 8 anos atrás
pai
commit
fd6a6ef194
2 arquivos alterados com 5 adições e 5 exclusões
  1. +1
    -1
      accessToken.go
  2. +4
    -4
      main.go

+ 1
- 1
accessToken.go Ver arquivo

@@ -61,7 +61,7 @@ func readTokenFromFile(path string) (authToken, error) {
//issue web request to get token from wechat
func renewAuthtoken() (authToken, error) {
//url := "http://vimeo.com/api/v2/brad/info.json"
url := "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx876e233fde456b7b&secret=4a91aa328569b10a9fb97adeb8b0af58"
url := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", APIConfig.Appid, APIConfig.AppSecret)
var myClient = &http.Client{Timeout: 20 * time.Second}
r, err := myClient.Get(url)
if err != nil {

+ 4
- 4
main.go Ver arquivo

@@ -72,16 +72,16 @@ func checkSignature(r *http.Request) bool {
nonce, nok := m["nonce"]
token := APIConfig.Token
if sok && tok && nok {
//sort token, timestamp, nonce and join them
strs := []string{token, timestamp[0], nonce[0]}

sort.Strings(strs)
s := strings.Join(strs, "")

//calculate sha1
h := sha1.New()
h.Write([]byte(s))
us := fmt.Sprintf("%x", h.Sum(nil))
return signature[0] == us
calculated := fmt.Sprintf("%x", h.Sum(nil))
return signature[0] == calculated
}
return false
}

Carregando…
Cancelar
Salvar