|
|
- package wechat
-
- import (
- "fmt"
- "log"
- )
-
- type wx_access_token_res struct {
- AccessToken string `json:"access_token"`
- ExpiresIn int `json:"expires_in"`
- Errcode int `json:"errcode"`
- Errmsg string `json:"errmsg"`
- }
-
- /**
- * 从微信api取access_token
- */
- func GetAccessToken(appid, secret string) (wx_access_token_res, error) {
-
- url := fmt.Sprintf(ACCESS_TOKEN_API, appid, secret)
-
- data_byte, err := SendHttp("GET", url, nil)
-
- var data wx_access_token_res
-
- if err == nil {
- err = json.Unmarshal(data_byte, &data)
-
- if err != nil {
- log.Println("get access token from WX api error:", err)
- }
-
- if data.Errcode != 0 {
- log.Println("get access token from WX api fail:", data.Errcode, data.Errmsg)
- }
- }
-
- return data, err
- }
|