12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package models
- import (
- "encoding/json"
- "eta/eta_report/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/http"
- )
- type WechatSign struct {
- AppId string
- NonceStr string
- Timestamp int64
- Url string
- Signature string
- RawString string
- }
- type WxTicket struct {
- Errcode int `json:"errcode"`
- Errmsg string `json:"errmsg"`
- Ticket string `json:"ticket"`
- }
- type WxAccessToken struct {
- AccessToken string `json:"access_token"`
- ExpiresIn int `json:"expires_in"`
- Errcode int `json:"errcode"`
- Errmsg string `json:"errmsg"`
- }
- func GetWxToken(wxAppId, wxAppSecret string) (item *WxAccessToken, err error) {
- getUrl := "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxAppId + "&secret=" + wxAppSecret
- result, err := http.Get(getUrl)
- if err != nil {
- utils.FileLog.Info("GetWxToken Err:", err.Error())
- return
- }
- utils.FileLog.Info(fmt.Sprintf("GetWxAccessToken :%s", string(result)))
- err = json.Unmarshal(result, &item)
- if err != nil {
- fmt.Println(fmt.Sprintf("GetWxToken Unmarshal Err:%s", err.Error()))
- return
- }
- if item.Errmsg != "" {
- utils.FileLog.Info(fmt.Sprintf("GetWxToken fail result:%s", string(result)))
- }
- return
- }
|