diff --git a/.gitignore b/.gitignore index 36eec47..0c874bc 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ _testmain.go .DS_Store .vscode/ vendor/*/ +.idea/ diff --git a/material/media.go b/material/media.go index 4465605..70ff09e 100644 --- a/material/media.go +++ b/material/media.go @@ -31,10 +31,10 @@ const ( type Media struct { util.CommonError - Type MediaType `json:"type"` - MediaID string `json:"media_id"` - ThumbMediaID string `json:"thumb_media_id"` - CreatedAt int64 `json:"created_at"` + Type MediaType `json:"type"` + MediaID string `json:"media_id"` + ThumbMediaID string `json:"thumb_media_id"` + CreatedAt int64 `json:"created_at"` } //MediaUpload 临时素材上传 diff --git a/message/message.go b/message/message.go index e8cf5a4..00809be 100644 --- a/message/message.go +++ b/message/message.go @@ -83,15 +83,15 @@ type MixMessage struct { URL string `xml:"Url"` //事件相关 - Event EventType `xml:"Event"` - EventKey string `xml:"EventKey"` - Ticket string `xml:"Ticket"` - Latitude string `xml:"Latitude"` - Longitude string `xml:"Longitude"` - Precision string `xml:"Precision"` - MenuID string `xml:"MenuId"` - Status string `xml:"Status"` - SessionFrom string `xml:"SessionFrom"` + Event EventType `xml:"Event"` + EventKey string `xml:"EventKey"` + Ticket string `xml:"Ticket"` + Latitude string `xml:"Latitude"` + Longitude string `xml:"Longitude"` + Precision string `xml:"Precision"` + MenuID string `xml:"MenuId"` + Status string `xml:"Status"` + SessionFrom string `xml:"SessionFrom"` ScanCodeInfo struct { ScanType string `xml:"ScanType"` diff --git a/server/server.go b/server/server.go index 5a40c25..ad3c8ca 100644 --- a/server/server.go +++ b/server/server.go @@ -18,6 +18,8 @@ import ( type Server struct { *context.Context + debug bool + openID string messageHandler func(message.MixMessage) *message.Reply @@ -40,6 +42,11 @@ func NewServer(context *context.Context) *Server { return srv } +// SetDebug set debug field +func (srv *Server) SetDebug(debug bool) { + srv.debug = debug +} + //Serve 处理微信的请求消息 func (srv *Server) Serve() error { if !srv.Validate() { @@ -65,6 +72,9 @@ func (srv *Server) Serve() error { //Validate 校验请求是否合法 func (srv *Server) Validate() bool { + if srv.debug { + return true + } timestamp := srv.Query("timestamp") nonce := srv.Query("nonce") signature := srv.Query("signature") diff --git a/wechat.go b/wechat.go index 02e3a34..19856b8 100644 --- a/wechat.go +++ b/wechat.go @@ -10,10 +10,10 @@ import ( "github.com/silenceper/wechat/material" "github.com/silenceper/wechat/menu" "github.com/silenceper/wechat/oauth" + "github.com/silenceper/wechat/pay" "github.com/silenceper/wechat/server" "github.com/silenceper/wechat/template" "github.com/silenceper/wechat/user" - "github.com/silenceper/wechat/pay" ) // Wechat struct @@ -27,9 +27,9 @@ type Config struct { AppSecret string Token string EncodingAESKey string - PayMchID string //支付 - 商户 ID - PayNotifyURL string //支付 - 接受微信支付结果通知的接口地址 - PayKey string //支付 - 商户后台设置的支付 key + PayMchID string //支付 - 商户 ID + PayNotifyURL string //支付 - 接受微信支付结果通知的接口地址 + PayKey string //支付 - 商户后台设置的支付 key Cache cache.Cache } @@ -98,4 +98,4 @@ func (wc *Wechat) GetTemplate() *template.Template { // GetPay 返回支付消息的实例 func (wc *Wechat) GetPay() *pay.Pay { return pay.NewPay(wc.Context) -} \ No newline at end of file +}