Ver código fonte

LeanworkReqeust to LeanworkIn

master
patrick 5 anos atrás
pai
commit
47de486fb4
8 arquivos alterados com 68 adições e 18 exclusões
  1. +4
    -4
      db.go
  2. +4
    -4
      leanworkIn.go
  3. +2
    -0
      leanworkOut.go
  4. +2
    -2
      purchase.go
  5. +46
    -0
      ref/w.php
  6. +3
    -3
      rpn.go
  7. +4
    -2
      rpnIn.go
  8. +3
    -3
      rpnOut.go

+ 4
- 4
db.go Ver arquivo

@@ -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
}


leanwork_request.go → leanworkIn.go Ver arquivo

@@ -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
}

+ 2
- 0
leanworkOut.go Ver arquivo

@@ -0,0 +1,2 @@
package main


+ 2
- 2
purchase.go Ver arquivo

@@ -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

+ 46
- 0
ref/w.php Ver arquivo

@@ -0,0 +1,46 @@
<?php
$data = array(
'order_id'=>'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));
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
https://deposit.paylomo.net/pay.php?r=payEasy <br>
http://debug.biukop.com:8080/rpn_notify
<form id="payment" name="payment" action="http://debug.biukop.com:8080/rpn_notify" method="POST">
<?php
foreach ($data as $key => $val) {
echo '<input type="hidden" name="'.$key.'" value="'.$val.'" />';
}
?>
<input type="submit" value="submit">
</form>
</body>
<script type="text/javascript">
// document.getElementById('payment').submit();
</script>
some text
<?php echo "$comp ------" ?>
<?php echo $data['signature'] ?>
</html>

+ 3
- 3
rpn.go Ver arquivo

@@ -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)

+ 4
- 2
rpnIn.go Ver arquivo

@@ -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 {

+ 3
- 3
rpnOut.go Ver arquivo

@@ -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)

Carregando…
Cancelar
Salvar