123456789101112131415161718192021222324252627282930313233 |
- package wechat
- // Server wechat
- type Server struct {
- AppID string `json:"appid"`
- AppSecret string `json:"appsecret"`
- Token string `json:"token"`
- EncodingAESKey string `json:"encodingaeskey"`
- }
- // NewServer new Server
- func NewServer(appID, appSecret, token, encodingAESKey string) *Server {
- key := "wechat:server:" + appID
- if v, ok := cache.Load(key); ok {
- return v.(*Server)
- }
- s := &Server{AppID: appID, AppSecret: appSecret, Token: token, EncodingAESKey: encodingAESKey}
- cache.Store(key, s)
- return s
- }
- // Echo notify echo GET
- func (ws Server) Echo(s FormSignature) (data string, err error) {
- if ok := makeSignature(ws.Token, s.Signature, s.TimeStamp, s.Nonce); ok {
- data = s.Echostr
- }
- return
- }
- // Validate 验证请求合法性
- func (ws Server) Validate(signature, timestamp, nonce string) bool {
- return makeSignature(ws.Token, signature, timestamp, nonce)
- }
|