|
|
|
|
|
|
|
|
"github.com/go-sql-driver/mysql" |
|
|
"github.com/go-sql-driver/mysql" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type RpnReq struct { |
|
|
|
|
|
|
|
|
type RpnOut struct { |
|
|
Version string |
|
|
Version string |
|
|
Sign_type string |
|
|
Sign_type string |
|
|
Mid string |
|
|
Mid string |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// //build request from leanwork request forms |
|
|
// //build request from leanwork request forms |
|
|
// func (m *RpnReq) buildReqByForm(form url.Values) RpnReq { |
|
|
|
|
|
// r := RpnReq{} |
|
|
|
|
|
|
|
|
// func (m *RpnOut) buildReqByForm(form url.Values) RpnOut { |
|
|
|
|
|
// r := RpnOut{} |
|
|
// r.version = "1.1" |
|
|
// r.version = "1.1" |
|
|
// r.sign_type = "MD5" |
|
|
// r.sign_type = "MD5" |
|
|
// r.mid = "EU85201311P2P" |
|
|
// r.mid = "EU85201311P2P" |
|
|
|
|
|
|
|
|
// return r |
|
|
// return r |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
func (m *RpnReq) buildReqByLeanworkRequestP2P(row LeanworkRequest, user_name string, user_cardno string) RpnReq { |
|
|
|
|
|
|
|
|
func (m *RpnOut) buildReqByLeanworkRequestP2P(row LeanworkRequest, user_name string, user_cardno string) RpnOut { |
|
|
|
|
|
|
|
|
m.Version = "1.1" |
|
|
m.Version = "1.1" |
|
|
m.Sign_type = "MD5" |
|
|
m.Sign_type = "MD5" |
|
|
|
|
|
|
|
|
return *m |
|
|
return *m |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (m *RpnReq) buildReqByLeanworkRequestFAT(row LeanworkRequest, user_name string, user_cardno string) RpnReq { |
|
|
|
|
|
|
|
|
func (m *RpnOut) buildReqByLeanworkRequestFAT(row LeanworkRequest, user_name string, user_cardno string) RpnOut { |
|
|
m.Version = "1.1" |
|
|
m.Version = "1.1" |
|
|
m.Sign_type = "MD5" |
|
|
m.Sign_type = "MD5" |
|
|
m.Mid = Config.Rpn.MIDFAT |
|
|
m.Mid = Config.Rpn.MIDFAT |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//from 0.1 to 10 cents |
|
|
//from 0.1 to 10 cents |
|
|
func (m *RpnReq) translateAmountFromLeanwork(from string) string { |
|
|
|
|
|
|
|
|
func (m *RpnOut) translateAmountFromLeanwork(from string) string { |
|
|
f, _ := strconv.ParseFloat(from, 32) |
|
|
f, _ := strconv.ParseFloat(from, 32) |
|
|
f = f * 100 //convert to cents |
|
|
f = f * 100 //convert to cents |
|
|
t := int(math.Ceil(f)) |
|
|
t := int(math.Ceil(f)) |
|
|
|
|
|
|
|
|
return s |
|
|
return s |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (m *RpnReq) now() string { |
|
|
|
|
|
|
|
|
func (m *RpnOut) now() string { |
|
|
t := time.Now() |
|
|
t := time.Now() |
|
|
return t.Format("20060102150405") |
|
|
return t.Format("20060102150405") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//send request to RPN to initiate transaction |
|
|
//send request to RPN to initiate transaction |
|
|
func (m *RpnReq) SendReq(form url.Values) (*http.Response, error) { |
|
|
|
|
|
|
|
|
func (m *RpnOut) SendReq(form url.Values) (*http.Response, error) { |
|
|
return nil, nil |
|
|
return nil, nil |
|
|
// r := m.buildReqByForm(form) |
|
|
// r := m.buildReqByForm(form) |
|
|
// hc := http.Client{Timeout: 15 * time.Second} |
|
|
// hc := http.Client{Timeout: 15 * time.Second} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//encode without disturbing it's original order |
|
|
//encode without disturbing it's original order |
|
|
func (m *RpnReq) encode() string { |
|
|
|
|
|
|
|
|
func (m *RpnOut) encode() string { |
|
|
s := "version=" + m.Version |
|
|
s := "version=" + m.Version |
|
|
s += "&sign_type=" + m.Sign_type |
|
|
s += "&sign_type=" + m.Sign_type |
|
|
s += "&mid=" + m.Mid |
|
|
s += "&mid=" + m.Mid |
|
|
|
|
|
|
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ro := RpnReq{} |
|
|
|
|
|
|
|
|
ro := RpnOut{} |
|
|
ro.Ip4 = getClientIPLong(r) |
|
|
ro.Ip4 = getClientIPLong(r) |
|
|
ro.Leanwork = row.Id |
|
|
ro.Leanwork = row.Id |
|
|
if rpn_type == "rpnp2p" { |
|
|
if rpn_type == "rpnp2p" { |
|
|
|
|
|
|
|
|
ro.sendRedirect(w, row) |
|
|
ro.sendRedirect(w, row) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (m *RpnReq) sendRedirect(w http.ResponseWriter, row LeanworkRequest) { |
|
|
|
|
|
|
|
|
func (m *RpnOut) sendRedirect(w http.ResponseWriter, row LeanworkRequest) { |
|
|
//execute redirect |
|
|
//execute redirect |
|
|
m.Url = Config.Rpn.Url |
|
|
m.Url = Config.Rpn.Url |
|
|
tmpl.ExecuteTemplate(w, "rpnCallOutRedirect", *m) |
|
|
tmpl.ExecuteTemplate(w, "rpnCallOutRedirect", *m) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func getRpnOutByOrderId(order_id string) (ret RpnReq, err error) { |
|
|
|
|
|
|
|
|
func getRpnOutByOrderId(order_id string) (ret RpnOut, err error) { |
|
|
if err = db.conn(Config); err != nil { |
|
|
if err = db.conn(Config); err != nil { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |