微信相关接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
753 B

  1. package wechat
  2. import (
  3. "fmt"
  4. "log"
  5. )
  6. type wx_access_token_res struct {
  7. AccessToken string `json:"access_token"`
  8. ExpiresIn int `json:"expires_in"`
  9. Errcode int `json:"errcode"`
  10. Errmsg string `json:"errmsg"`
  11. }
  12. /**
  13. * 从微信api取access_token
  14. */
  15. func GetAccessToken(appid, secret string) (wx_access_token_res, error) {
  16. url := fmt.Sprintf(ACCESS_TOKEN_API, appid, secret)
  17. data_byte, err := SendHttp("GET", url, nil)
  18. var data wx_access_token_res
  19. if err == nil {
  20. err = json.Unmarshal(data_byte, &data)
  21. if err != nil {
  22. log.Println("get access token from WX api error:", err)
  23. }
  24. if data.Errcode != 0 {
  25. log.Println("get access token from WX api fail:", data.Errcode, data.Errmsg)
  26. }
  27. }
  28. return data, err
  29. }