Browse Source

修复Server酱推送失败问题

main
ztino 3 years ago
parent
commit
fb2be80bdf
  1. 7
      service/wechat.go

7
service/wechat.go

@ -7,7 +7,6 @@ import (
"github.com/tidwall/gjson"
"github.com/unknwon/goconfig"
"github.com/ztino/jd_seckill/log"
"net/http"
)
type Wechat struct {
@ -23,11 +22,7 @@ func (this *Wechat) Send(title,msg string) error {
req:=httpc.NewRequest(client)
url:=fmt.Sprintf("http://sc.ftqq.com/%s.send",this.conf.MustValue("messenger","server_chan_sckey",""))
req.SetHeader("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36")
resp,body,err:=req.SetUrl(url+"?text="+title+"&desp="+msg).SetMethod("get").Send().End()
if err!=nil || resp.StatusCode!=http.StatusOK {
log.Println("微信推送失败,网络错误")
return errors.New("微信推送失败,网络错误")
}
_,body,_:=req.SetUrl(url+"?text="+title+"&desp="+msg).SetMethod("get").Send().End()
if gjson.Get(body,"errno").Int()!=0 {
log.Println("微信推送失败,返回错误:"+gjson.Get(body,"errmsg").String())
return errors.New("微信推送失败,返回错误:"+gjson.Get(body,"errmsg").String())

Loading…
Cancel
Save