server.go 738 B

12345678910111213141516171819202122232425262728
  1. package wechat
  2. // Server wechat
  3. type Server struct {
  4. AppID string `json:"appid"`
  5. AppSecret string `json:"appsecret"`
  6. Token string `json:"token"`
  7. EncodingAESKey string `json:"encodingaeskey"`
  8. }
  9. // NewServer new Server
  10. func NewServer(appID, appSecret, token, encodingAESKey string) *Server {
  11. key := "wechat:server:" + appID
  12. if v, ok := cache.Load(key); ok {
  13. return v.(*Server)
  14. }
  15. s := &Server{AppID: appID, AppSecret: appSecret, Token: token, EncodingAESKey: encodingAESKey}
  16. cache.Store(key, s)
  17. return s
  18. }
  19. // Echo notify echo GET
  20. func (wc Server) Echo(s FormSignature) (data string, err error) {
  21. if ok := makeSignature(wc.Token, s.Signature, s.TimeStamp, s.Nonce); ok {
  22. data = s.Echostr
  23. }
  24. return
  25. }