package main import ( "fmt" "log" "net/http" "net/http/httputil" ) func rpnNotify(w http.ResponseWriter, r *http.Request) { logRequestDebug(httputil.DumpRequest(r, true)) if r.Method != "POST" { errPage(w, http.StatusMethodNotAllowed, "invalid request") return } ri, err := GetRpnInFromHTTPRequest(r) //ParseForm called if err != nil { errPage(w, http.StatusBadRequest, "invalid parameters") return } ro, _ := getRpnOutByOrderId(ri.Order_id) ri.Leanwork = ro.Leanwork _, err = ri.add2db() //TODO:check error add if err != nil { log.Printf("failed to add rpnIn %+v , error is %s", ri, err.Error()) } fmt.Fprintf(w, "[SUCCESS]") //start informing leanwork in separate thread, maximum 5 retry, interval 5 minutes go startLeanworkCallBack(ri) return } //receive RPN user name and card number func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { errPage(w, http.StatusMethodNotAllowed, "invalid request") return } r.ParseForm() id := r.FormValue("id") sign := r.FormValue("sign") user_name := r.FormValue("name") user_card := r.FormValue("card") rpn_type := r.FormValue("rpnType") if !(id != "" && sign != "" && user_name != "" && user_card != "") { errPage(w, http.StatusBadRequest, "missing parameters") return } row, err := getRequestRowByIdAndSign(id, sign) if err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Fprintf(w, "bad parameters") return } ro := RpnOut{} ro.Ip4 = getClientIPLong(r) ro.Leanwork = row.Id if rpn_type == "rpnp2p" { ro.buildReqByLeanworkINP2P(row, user_name, user_card) } else { ro.buildReqByLeanworkINFAT(row, user_name, user_card) } //create db record db.addRpnOut(ro) //build rpn redirect page and send it ro.sendRedirect(w, row) }