| @@ -1,13 +1,140 @@ | |||
| package main | |||
| import "net/url" | |||
| import ( | |||
| "net/http" | |||
| "net/url" | |||
| "strconv" | |||
| "strings" | |||
| "time" | |||
| ) | |||
| // var url = "https://deposit.paylomo.net/pay.php?r=payEasy" //production | |||
| // var url = "https://deposit-mac.chinapaytech.com/pay.php?r=payEasy" //test | |||
| // var md5p2p = "370296119874502" | |||
| // var md5fat = "207841502473198" | |||
| type RpnReq struct { | |||
| version string | |||
| sign_type string | |||
| mid string | |||
| notify_url string | |||
| order_id string | |||
| order_amount string | |||
| order_time string //YYYYMMDDHHMMSS | |||
| user_id string | |||
| user_name string | |||
| user_cardno string | |||
| signature string | |||
| } | |||
| //build request from leanwork request forms | |||
| func (m *RpnReq) buildReqByForm(form url.Values) RpnReq { | |||
| r := RpnReq{} | |||
| r.version = "1.1" | |||
| r.sign_type = "MD5" | |||
| r.mid = "EU85201311P2P" | |||
| r.notify_url = "http://rpn.supertraderfx.ayvwd8em49pvoa3g.com/rpn_notify" | |||
| r.order_id = form["orderNo"][0] | |||
| r.order_amount = form["orderAmount"][0] //cents | |||
| r.order_time = m.now() | |||
| r.user_id = form["customerId"][0] | |||
| r.user_name = "SuperForex" | |||
| r.user_cardno = "6212262002002377849" | |||
| r.signature = md4RpnFormP2P(r) | |||
| *m = r | |||
| return r | |||
| } | |||
| func (m *RpnReq) now() string { | |||
| t := time.Now() | |||
| return t.Format("20060102150405") | |||
| } | |||
| //send request to RPN to initiate transaction | |||
| func sendReq(form url.Values) { | |||
| func (m *RpnReq) SendReq(form url.Values) (*http.Response, error) { | |||
| r := m.buildReqByForm(form) | |||
| hc := http.Client{Timeout: 15 * time.Second} | |||
| myForm := url.Values{} | |||
| myForm.Set("version", r.version) | |||
| myForm.Set("sign_type", r.sign_type) | |||
| myForm.Set("mid", r.mid) | |||
| myForm.Set("notify_url", r.notify_url) | |||
| myForm.Set("order_id", r.order_id) | |||
| myForm.Set("order_amount", r.order_amount) | |||
| myForm.Set("order_time", r.order_time) | |||
| myForm.Set("user_id", r.user_id) | |||
| myForm.Set("user_name", r.user_name) | |||
| myForm.Set("user_cardno", r.user_cardno) | |||
| myForm.Set("signature", r.signature) | |||
| //req, err := http.NewRequest("POST", "https://lawipac.com/dumprequest.php", strings.NewReader(myForm.Encode())) | |||
| req, err := http.NewRequest("POST", Config.Rpn.UrlTest, strings.NewReader(m.encode())) | |||
| if err != nil { | |||
| panic("wrong") | |||
| } | |||
| req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | |||
| req.Header.Add("content-Length", strconv.Itoa(len(form.Encode()))) | |||
| return hc.Do(req) | |||
| //Config.Rpn.UrlTest | |||
| // return http.PostForm(Config.Rpn.UrlTest, myForm) | |||
| //return http.PostForm("https://lawipac.com/dumprequest.php", myForm) | |||
| } | |||
| //encode without disturbing it's original order | |||
| func (m *RpnReq) encode() string { | |||
| s := "version=" + m.version | |||
| s += "&sign_type=" + m.sign_type | |||
| s += "&mid=" + m.mid | |||
| s += "¬ify_url=" + url.QueryEscape(m.notify_url) | |||
| s += "&order_id=" + m.order_id | |||
| s += "&order_amount=" + m.order_amount | |||
| s += "&order_time=" + m.order_time | |||
| s += "&user_id=" + m.user_id | |||
| s += "&user_name=" + m.user_name | |||
| s += "&user_cardno=" + m.user_cardno | |||
| s += "&signature=" + m.signature | |||
| return s | |||
| } | |||
| // <?php | |||
| // $data = array( | |||
| // 'version'=>'1.1', | |||
| // 'sign_type'=> 'MD5', | |||
| // 'mid' => 'EU85201311P2P', //must to use your mid | |||
| // 'notify_url' => 'https://lawipac.com/dumprequest.php', | |||
| // 'order_id' => "demo-" . date('YmdHis'), | |||
| // 'order_amount' => 120000 , //round($_POST['amount']*100), | |||
| // 'order_time' => date('YmdHis'), | |||
| // 'user_id'=> 'supertraderP2P', //$_POST['user_id'], | |||
| // 'user_name'=>"zhang3", //urlencode($_POST['user_name']), | |||
| // 'user_cardno'=>"6212262002002377849" //$_POST['user_cardno'], | |||
| // ); | |||
| // $params = array(); | |||
| // foreach ($data as $field => $value) { | |||
| // if( $value == '' ) continue; | |||
| // $params[] = "$field=$value"; | |||
| // } | |||
| // $params[] = "key=p1j4A3mEMj+ft0xkSfVULQ"; //must to use your key | |||
| // $data['signature'] = md5(implode('|', $params)); | |||
| // ?> | |||
| // <html> | |||
| // <head> | |||
| // <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |||
| // </head> | |||
| // <body> | |||
| // <form id="payment" name="payment" action="https://deposit.paylomo.net/pay.php?r=payEasy" 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 | |||