Procházet zdrojové kódy

access token also using config parameter

master
Patrick Peng Sun před 8 roky
rodič
revize
fd6a6ef194
2 změnil soubory, kde provedl 5 přidání a 5 odebrání
  1. +1
    -1
      accessToken.go
  2. +4
    -4
      main.go

+ 1
- 1
accessToken.go Zobrazit soubor

//issue web request to get token from wechat //issue web request to get token from wechat
func renewAuthtoken() (authToken, error) { func renewAuthtoken() (authToken, error) {
//url := "http://vimeo.com/api/v2/brad/info.json" //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} var myClient = &http.Client{Timeout: 20 * time.Second}
r, err := myClient.Get(url) r, err := myClient.Get(url)
if err != nil { if err != nil {

+ 4
- 4
main.go Zobrazit soubor

nonce, nok := m["nonce"] nonce, nok := m["nonce"]
token := APIConfig.Token token := APIConfig.Token
if sok && tok && nok { if sok && tok && nok {
//sort token, timestamp, nonce and join them
strs := []string{token, timestamp[0], nonce[0]} strs := []string{token, timestamp[0], nonce[0]}

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


//calculate sha1
h := sha1.New() h := sha1.New()
h.Write([]byte(s)) 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 return false
} }

Načítá se…
Zrušit
Uložit