package services import ( "encoding/json" "errors" "eta/eta_report/models" "eta/eta_report/services/wechat" "eta/eta_report/utils" "fmt" "github.com/rdlucklib/rdluck_tools/http" "strconv" "strings" "time" ) func GetWxTicket(accessToken string) (int, string, error) { Url := strings.Join([]string{"https://api.weixin.qq.com/cgi-bin/ticket/getticket", "?access_token=", accessToken, "&type=jsapi"}, "") infoBody, err := http.Get(Url) if err != nil { return 0, "", err } atr := models.WxTicket{} err = json.Unmarshal(infoBody, &atr) fmt.Println("ticket result:", string(infoBody)) if err != nil { return atr.Errcode, atr.Errmsg, err } else { return 0, atr.Ticket, nil } } func GetWxSignature(ticket, url, noncestr string) (string, string, int64) { timestamp := time.Now().Unix() signStr := strings.Join([]string{"jsapi_ticket=", ticket, "&noncestr=", noncestr, "×tamp=", strconv.FormatInt(timestamp, 10), "&url=", url}, "") signature := utils.Sha1(signStr) fmt.Println("signStr", signStr) return signature, noncestr, timestamp } // GetDefaultWxAccessToken 获取微信token func GetDefaultWxAccessToken() (accessToken string, err error, errMsg string) { // 微信配置信息 conf, e := models.GetBusinessConf() if e != nil { errMsg = "获取配置信息失败, Err: " + e.Error() err = errors.New(errMsg) return } appId := "" appSecret := "" if v, ok := conf[models.BusinessConfWxAppId]; ok { appId = v } if v, ok := conf[models.BusinessConfWxAppSecret]; ok { appSecret = v } if appId == "" || appSecret == "" { errMsg = "获取微信公众号未配置" err = errors.New(errMsg) return } req := wechat.WxTokenReq{ WxAppId: appId, WxAppSecret: appSecret, } accessToken, err, errMsg = wechat.GetAccessToken(req) return }