Browse Source

build an echo server, but does not work for events or voice images.

master
Patrick Peng Sun 8 years ago
parent
commit
f20a1c2ae4
1 changed files with 16 additions and 1 deletions
  1. +16
    -1
      server.go

+ 16
- 1
server.go View File

@@ -26,7 +26,8 @@ func apiV1Main(w http.ResponseWriter, r *http.Request) {

switch r.Method {
case "POST":
answerWechatPost(w, r)
answerWechatPostEcho(w, r)
//answerWechatPost(w, r)
case "GET":
answerInitialAuth(w, r)
default:
@@ -74,6 +75,20 @@ func answerWechatPost(w http.ResponseWriter, r *http.Request) {
return
}

func answerWechatPostEcho(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
//fmt.Printf("get body: %s", string(body))
s := ReadEncryptedMsg(string(body))
//fmt.Printf("to decrypt %s", s.Encrypt)
d := Decode(s.Encrypt)
fmt.Printf("echo as: \n%s", d)

e := strings.Replace(d, "ToUserName", "FDDD20170506xyzunique", 2)
f := strings.Replace(e, "FromUserName", "ToUserName", 2)
g := strings.Replace(f, "FDDD20170506xyzunique", "FromUserName", 2)
fmt.Fprint(w, g)
}

//
func checkSignature(r *http.Request) bool {
rq := r.URL.RawQuery

Loading…
Cancel
Save