diff --git a/db.go b/db.go index 6fc8fbf..d81aaf7 100644 --- a/db.go +++ b/db.go @@ -37,7 +37,7 @@ func (m *TransactionDB) close() { m.h = nil //clear it, very important to prevent multiple opening } -func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkRequest, err error) { +func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkIn, err error) { if err = m.conn(Config); err != nil { return row, err } @@ -45,7 +45,7 @@ func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkRequest, err er r.ParseForm() //assuming form has been parsed - row = LeanworkRequest{} + row = LeanworkIn{} pickupUrl := r.FormValue("pickupUrl") receiveUrl := r.FormValue("receiveUrl") signType := r.FormValue("signType") @@ -57,7 +57,7 @@ func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkRequest, err er valid := isLeanworkFormValid(r.Form) ip4 := getClientIPLong(r) - insForm, err := m.h.Prepare("INSERT INTO request(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) VALUES(?,?,?,?,?,?,?,?,?,?)") + insForm, err := m.h.Prepare("INSERT INTO leanworkIn (pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) VALUES(?,?,?,?,?,?,?,?,?,?)") if err != nil { log.Printf("Failed to prepare SQL statment for insert") return @@ -65,7 +65,7 @@ func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkRequest, err er res, err := insForm.Exec(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) if err != nil { - log.Printf("Error inserting leanwork request with orderNo =%s \n", orderNo) + log.Printf("Error inserting leanworkIn with orderNo =%s \n", orderNo) return } diff --git a/leanwork_request.go b/leanworkIn.go similarity index 85% rename from leanwork_request.go rename to leanworkIn.go index 13cbf1d..64bebd7 100644 --- a/leanwork_request.go +++ b/leanworkIn.go @@ -5,7 +5,7 @@ import ( "time" ) -type LeanworkRequest struct { +type LeanworkIn struct { Id int64 PickupUrl string ReceiveUrl string @@ -27,11 +27,11 @@ func lrIsIdMatchSign(id string, sign string) bool { return err == nil } -func getRequestRowByIdAndSign(id string, sign string) (row LeanworkRequest, err error) { +func getRequestRowByIdAndSign(id string, sign string) (row LeanworkIn, err error) { //retrieve form DB - row = LeanworkRequest{} + row = LeanworkIn{} db.conn(Config) - selDB, err := db.h.Query("SELECT * FROM request WHERE id=? and sign=?", id, sign) + selDB, err := db.h.Query("SELECT * FROM leanworkIN WHERE id=? and sign=?", id, sign) if err != nil { return } diff --git a/leanworkOut.go b/leanworkOut.go new file mode 100644 index 0000000..c9ecbf5 --- /dev/null +++ b/leanworkOut.go @@ -0,0 +1,2 @@ +package main + diff --git a/purchase.go b/purchase.go index 9776b56..3b3ce52 100644 --- a/purchase.go +++ b/purchase.go @@ -43,13 +43,13 @@ func StartPay(w http.ResponseWriter, r *http.Request) { } -func askForPaymentSelection(w http.ResponseWriter, row LeanworkRequest) { +func askForPaymentSelection(w http.ResponseWriter, row LeanworkIn) { t := template.Must(template.ParseFiles("PG/StartPay.html")) //tmpl.ExecuteTemplate(w, "StartPay", row) t.Execute(w, row) } -func askForPaymentInfo(w http.ResponseWriter, row LeanworkRequest, rpn_type string) { +func askForPaymentInfo(w http.ResponseWriter, row LeanworkIn, rpn_type string) { var data struct { Id int64 Sign string diff --git a/ref/w.php b/ref/w.php new file mode 100644 index 0000000..f967ded --- /dev/null +++ b/ref/w.php @@ -0,0 +1,46 @@ +'200310160057TW002184000000000001', + 'order_time'=> date('YmdHis'), + 'order_amount'=> '120000', + 'deal_id' => "deal" + date('YmdHis'), + 'deal_time' => date('YmdHis'), + 'pay_amount' => '120000', + 'pay_result' => '3', +); + + +$params = array(); +foreach ($data as $field => $value) { +if( $value == '' ) continue; + $params[] = "$field=$value"; +} +$params[] = "key=p1j4A3mEMj+ft0xkSfVULQ"; //must to use your key + +$comp = implode('|', $params); +$data['signature'] = md5(implode('|', $params)); +?> + + + + + + + https://deposit.paylomo.net/pay.php?r=payEasy
+ http://debug.biukop.com:8080/rpn_notify +
+ $val) { + echo ''; + } + ?> + +
+ + +some text + + + \ No newline at end of file diff --git a/rpn.go b/rpn.go index 1110ebe..4b1d397 100644 --- a/rpn.go +++ b/rpn.go @@ -19,7 +19,7 @@ func rpnNotify(w http.ResponseWriter, r *http.Request) { ro, _ := getRpnOutByOrderId(ri.Order_id) ri.Leanwork = ro.Leanwork - ri1, err := ri.add2db() //TODO:check error add + _, err = ri.add2db() //TODO:check error add if err != nil { log.Printf("failed to add rpnIn %+v , error is %s", ri, err.Error()) } @@ -56,9 +56,9 @@ func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { ro.Ip4 = getClientIPLong(r) ro.Leanwork = row.Id if rpn_type == "rpnp2p" { - ro.buildReqByLeanworkRequestP2P(row, user_name, user_card) + ro.buildReqByLeanworkINP2P(row, user_name, user_card) } else { - ro.buildReqByLeanworkRequestFAT(row, user_name, user_card) + ro.buildReqByLeanworkINFAT(row, user_name, user_card) } //create db record db.addRpnOut(ro) diff --git a/rpnIn.go b/rpnIn.go index 55ba14b..0f0735a 100644 --- a/rpnIn.go +++ b/rpnIn.go @@ -85,7 +85,7 @@ func (m *RpnIn) add2db() (ret RpnIn, err error) { return } -func (m *RpnIn) signature() string { +func (m *RpnIn) signature() (sig string) { s := "order_id=" + m.Order_id s += "|order_time=" + m.Order_time s += "|order_amount=" + m.Order_amount @@ -94,7 +94,9 @@ func (m *RpnIn) signature() string { s += "|pay_amount=" + m.Pay_amount s += "|pay_result=" + m.Pay_result s += "|key=" + m.md5key() - return md5str(s) + sig = md5str(s) + //log.Println("signature of rpnIn = " + sig + " using key " + m.md5key()) + return } func (m *RpnIn) md5key() string { diff --git a/rpnOut.go b/rpnOut.go index ca7ca42..b244f5d 100644 --- a/rpnOut.go +++ b/rpnOut.go @@ -34,7 +34,7 @@ type RpnOut struct { Ts mysql.NullTime } -func (m *RpnOut) buildReqByLeanworkRequestP2P(row LeanworkRequest, user_name string, user_cardno string) RpnOut { +func (m *RpnOut) buildReqByLeanworkINP2P(row LeanworkIn, user_name string, user_cardno string) RpnOut { m.Version = "1.1" m.Sign_type = "MD5" @@ -52,7 +52,7 @@ func (m *RpnOut) buildReqByLeanworkRequestP2P(row LeanworkRequest, user_name str return *m } -func (m *RpnOut) buildReqByLeanworkRequestFAT(row LeanworkRequest, user_name string, user_cardno string) RpnOut { +func (m *RpnOut) buildReqByLeanworkINFAT(row LeanworkIn, user_name string, user_cardno string) RpnOut { m.Version = "1.1" m.Sign_type = "MD5" m.Mid = Config.Rpn.MIDFAT @@ -98,7 +98,7 @@ func (m *RpnOut) encode() string { return s } -func (m *RpnOut) sendRedirect(w http.ResponseWriter, row LeanworkRequest) { +func (m *RpnOut) sendRedirect(w http.ResponseWriter, row LeanworkIn) { //execute redirect m.Url = Config.Rpn.Url tmpl.ExecuteTemplate(w, "rpnCallOutRedirect", *m)