微信相关接口
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.

50 lines
1.2 KiB

  1. package wechat
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. type MpUserInfo struct {
  7. Subscribe int `json:"subscribe"`
  8. Openid string `json:"openid"`
  9. Language string `json:"language"`
  10. SubscribeTime int `json:"subscribe_time"`
  11. Unionid string `json:"unionid"`
  12. Remark string `json:"remark"`
  13. Groupid int `json:"groupid"`
  14. TagidList interface{} `json:"tagid_list"`
  15. SubscribeScene string `json:"subscribe_scene"`
  16. QrScene int `json:"qr_scene"`
  17. QrSceneStr string `json:"qr_scene_str"`
  18. Errcode int `json:"errcode"`
  19. Errmsg string `json:"errmsg"`
  20. }
  21. /**
  22. * 公众号获取用户基本信息(UnionID机制)
  23. */
  24. func GetMpUserInfo(access_token, openid string, lang ...string) (MpUserInfo, error) {
  25. var data MpUserInfo
  26. var language string = "zh_CN"
  27. if len(lang) > 0 {
  28. language = lang[0]
  29. }
  30. url := fmt.Sprintf(MP_USERINFO_API, access_token, openid, language)
  31. data_byte, err := SendHttp("GET", url, nil)
  32. if err != nil {
  33. return data, err
  34. }
  35. err = json.Unmarshal(data_byte, &data)
  36. if data.Errcode != 0 {
  37. return data, errors.New(data.Errmsg)
  38. }
  39. return data, err
  40. }