Giter Site home page Giter Site logo

wechat-go's Introduction

wechat

简单高效的微信公众平台消息处理库

Installation

$ go get github.com/feit/wechat

Usage

package main
import (
  "net/http"
  "wechat"
)

func wechatHandler(this *wechat.Message) {

  switch this.Msg["Content"] {
    case "text":
    this.Reply("hello text")

    case "news":
      news := []wechat.News{}
      news = append(news, wechat.News{
        Title:  "Hello Golang",
        Desc:   "Golang is Good",
        Url:    "feit.me",
        PicUrl: "feit.me/aa.png",
      })
      this.Reply(news)

    case "image":
      replyMsg := wechat.Image{
        MediaId: "mediaid",
      }
      this.Reply(replyMsg)

    case "voice":
      replyMsg := wechat.Voice{
        MediaId: "mediaid",
      }
      this.Reply(replyMsg)

    case "video":
      replyMsg := wechat.Video{
        Title:   "VideoMsg",
        Desc:    "this is a video msg",
        MediaId: "mediaid",
      }
      this.Reply(replyMsg)

    case "music":
      replyMsg := wechat.Music{
        Title:        "GO GO GO",
        Desc:         "song for Golang",
        MusicUrl:     "music.com/golang.mp3",
        HQMusicUrl:   "music.com/golang.flac",
        ThumbMediaId: "ididid",
      }
      this.Reply(replyMsg)

    case "cs":
      replyMsg := wechat.CustomService{
        KfAccount: "test1@test",
      }
      this.Reply(replyMsg)

    default:
      this.Reply("hehe")

  }
}

func main() {
  http.HandleFunc("/wechat/api", wechat.HandleMessage("token", wechatHandler))
  http.ListenAndServe(":80", nil)
}

License

The MIT licence

wechat-go's People

Contributors

terry-fei avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.