wechat.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package models
  2. import (
  3. "encoding/json"
  4. "eta/eta_report/utils"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/http"
  7. )
  8. type WechatSign struct {
  9. AppId string
  10. NonceStr string
  11. Timestamp int64
  12. Url string
  13. Signature string
  14. RawString string
  15. }
  16. type WxTicket struct {
  17. Errcode int `json:"errcode"`
  18. Errmsg string `json:"errmsg"`
  19. Ticket string `json:"ticket"`
  20. }
  21. type WxAccessToken struct {
  22. AccessToken string `json:"access_token"`
  23. ExpiresIn int `json:"expires_in"`
  24. Errcode int `json:"errcode"`
  25. Errmsg string `json:"errmsg"`
  26. }
  27. func GetWxToken(wxAppId, wxAppSecret string) (item *WxAccessToken, err error) {
  28. getUrl := "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxAppId + "&secret=" + wxAppSecret
  29. result, err := http.Get(getUrl)
  30. if err != nil {
  31. utils.FileLog.Info("GetWxToken Err:", err.Error())
  32. return
  33. }
  34. utils.FileLog.Info(fmt.Sprintf("GetWxAccessToken :%s", string(result)))
  35. err = json.Unmarshal(result, &item)
  36. if err != nil {
  37. fmt.Println(fmt.Sprintf("GetWxToken Unmarshal Err:%s", err.Error()))
  38. return
  39. }
  40. if item.Errmsg != "" {
  41. utils.FileLog.Info(fmt.Sprintf("GetWxToken fail result:%s", string(result)))
  42. }
  43. return
  44. }