From 58f6084896b6eacfdde95546b3f05e4cea3a0051 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 11 Mar 2020 16:26:01 +1100 Subject: [PATCH] RPN test passed with P2P and FAT --- checksum.go | 1 + config.test.json | 1 + leanworkOut.go | 3 +++ ref/rpn-call-back.txt | 8 ++++++++ rpn.go | 11 +++++++++++ rpnIn.go | 2 +- rpnOut.go | 2 +- 7 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 ref/rpn-call-back.txt diff --git a/checksum.go b/checksum.go index bcee0d0..3d1c42b 100644 --- a/checksum.go +++ b/checksum.go @@ -25,6 +25,7 @@ func md5LeanworkForm(form url.Values) string { s += form["customerId"][0] s += Config.LeanWork.MD5Key } + fmt.Println("leanwork form: " + s) return md5str(s) } diff --git a/config.test.json b/config.test.json index 0249743..c912759 100644 --- a/config.test.json +++ b/config.test.json @@ -8,6 +8,7 @@ "UrlCallBack": "http://debug.biukop.com:8080/rpn_notify" }, "LeanWork": { + "MD5KEY2": "370296119874502", "MD5Key": "492815086935204", "MD5P2P": "370296119874502", "MD5FAT": "207841502473198" diff --git a/leanworkOut.go b/leanworkOut.go index a5f55c6..e2456ab 100644 --- a/leanworkOut.go +++ b/leanworkOut.go @@ -55,11 +55,14 @@ func (m *LeanworkOut) DoHttp() (retry bool, err error) { log.Println("Fatal: Cannot read leanwork Http Response " + err.Error()) } bodyString := string(bodyBytes) + m.LeanworkResp = bodyString + m.add2db() if strings.Contains(strings.ToLower(bodyString), "success") { retry = false } else { log.Println("Leanwork response without success word : " + bodyString) } + retry = false } return } diff --git a/ref/rpn-call-back.txt b/ref/rpn-call-back.txt new file mode 100644 index 0000000..7484d28 --- /dev/null +++ b/ref/rpn-call-back.txt @@ -0,0 +1,8 @@ +POST /rpn_notify HTTP/1.1 +Host: debug.biukop.com:8080 +Accept: */* +Content-Length: 207 +Content-Type: application/x-www-form-urlencoded +User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:5.0) Gecko/20110619 Firefox/5.0 + +order_id=200311012853TW002184000000000001&order_time=20200311012906&order_amount=120000&deal_id=135104086958&deal_time=20200311013317&pay_amount=120000&pay_result=3&signature=4fd8f8e81e35d679370b957b019d4c7d diff --git a/rpn.go b/rpn.go index 64126b2..5197d8c 100644 --- a/rpn.go +++ b/rpn.go @@ -4,9 +4,12 @@ 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 @@ -30,6 +33,14 @@ func rpnNotify(w http.ResponseWriter, r *http.Request) { return } +func logRequestDebug(data []byte, err error) { + if err == nil { + fmt.Printf("%s\n\n", string(data)) + } else { + log.Fatalf("%s\n\n", err) + } +} + //receive RPN user name and card number func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { diff --git a/rpnIn.go b/rpnIn.go index 07e5286..7a11d90 100644 --- a/rpnIn.go +++ b/rpnIn.go @@ -118,7 +118,7 @@ func (m *RpnIn) signature() (sig string) { s += "|pay_result=" + m.Pay_result s += "|key=" + m.md5key() sig = md5str(s) - //log.Println("signature of rpnIn = " + sig + " using key " + m.md5key()) + log.Println("signature of rpnIn = " + sig + " using key " + m.md5key()) return } diff --git a/rpnOut.go b/rpnOut.go index b244f5d..1335fb2 100644 --- a/rpnOut.go +++ b/rpnOut.go @@ -107,7 +107,7 @@ func (m *RpnOut) sendRedirect(w http.ResponseWriter, row LeanworkIn) { func (m *RpnOut) getMD5Key() string { if m.Mid == Config.Rpn.MIDP2P { return Config.Rpn.MD5P2P - } else if m.Mid == Config.Rpn.MD5FAT { + } else if m.Mid == Config.Rpn.MIDFAT { return Config.Rpn.MD5FAT } else { return ""