1 Star 0 Fork 19

春宇 / wechat-proxy

forked from bfbd / wechat-proxy 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
wxproxy.go 3.08 KB
一键复制 编辑 原始数据 按行查看 历史
aiportal 提交于 2017-09-17 12:58 . /user interface.
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"wechat-proxy/enterprise"
"wechat-proxy/wechat"
"wechat-proxy/wrap"
)
func main() {
wrapHandlers()
wechatHandlers()
enterpriseHandlers()
http.Handle("/example/", http.StripPrefix("/example/", http.FileServer(http.Dir("./example"))))
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
if err != nil {
w.Write([]byte(err.Error()))
return
}
w.Write(body)
log.Println(string(body))
})
host, port, tls := parseArgs()
address := fmt.Sprintf("%s:%d", host, port)
fmt.Printf("wechat proxy starting at %q ...\n", address)
if tls {
log.Fatal(http.ListenAndServeTLS(address, "wxproxy.crt", "wxproxy.key", nil))
} else {
log.Fatal(http.ListenAndServe(address, nil))
}
}
func parseArgs() (host string, port uint, tls bool) {
flag.UintVar(&port, "port", 8080, "Listening port.")
flag.UintVar(&port, "p", 8080, "Listening port.")
flag.BoolVar(&tls, "tls", false, "Https scheme.")
flag.Parse()
return
}
func wrapHandlers() {
// /register?key=...&appid=...&secret=...
// &token=&aes=
// &mch_id=&mch_key=&server_ip=
// &expires=&call=/msg&call=/api&call=
http.Handle("/register", wrap.NewRegisterServer())
// /app/<key>/api
// /app/<key>/msg?signature=...
// ...
http.Handle("/app/", wrap.NewWrapAppServer())
// /qrcode?path=...&size=
http.Handle("/qrcode", wrap.NewQrCodeServer())
// /short?path=...&expires=
// http.Handle("/short/", wrap.NewShortServer())
// /user
userServer := wrap.NewUserServer()
http.Handle("/user", userServer)
}
func wechatHandlers() {
// /api?appid=...&secret=...
// /api/new?appid=...&secret=...
apiServer := wechat.NewApiServer()
http.Handle("/api", apiServer)
http.Handle("/api/new", apiServer)
// /msg?token=...&aes=...&call=...&call=...&...
// /msg/json?token=...&aes=...&call=...&call=...&...
msgServer := wechat.NewMessageServer()
http.Handle("/msg", msgServer)
http.Handle("/msg/json", msgServer)
// /auth??appid=...&secret=...&call=...&state=&lang=
// /auth/info?appid=...&secret=...&call=...&state=&lang=
authServer := wechat.NewAuthServer()
http.Handle("/auth", authServer) // get openid & unionid
http.Handle("/auth/info", authServer) // get user info
payServer := wechat.NewPayServer()
http.Handle("/pay", payServer)
// /pay/qrcode?
// &appid=...&mch_id=...&mch_key=...&server_ip=...
// &fee=...&name=&call=&...
http.Handle("/pay/qrcode", payServer)
// /pay/js?
// &appid=...&mch_id=...&mch_key=...&server_ip=...
// &openid=...&fee=...&name=&call=&...
http.Handle("/pay/js", payServer)
// /jsapi?appid=...&secret=...
// /jsapi?access_token=...
http.Handle("/jsapi", wechat.NewJsTicketServer())
// /js/config?appid=...&secret=...&debug=&apilist=
http.Handle("/js/config", wechat.NewJsConfigServer())
http.Handle("/js/card", wechat.NewCardServer())
}
func enterpriseHandlers() {
// /qyapi?corpid=...&corpsecret=...
// /qyapi/new?corpid=...&corpsecret=...
qyServer := enterprise.NewQyServer()
http.Handle("/qyapi", qyServer)
http.Handle("/qyapi/new", qyServer)
}
Go
1
https://gitee.com/zhouchunnyu/wechat-proxy.git
git@gitee.com:zhouchunnyu/wechat-proxy.git
zhouchunnyu
wechat-proxy
wechat-proxy
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891