payment gateway for rpn cn
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

141 lignes
4.2KB

  1. package main
  2. import (
  3. "net/http"
  4. "net/url"
  5. "strconv"
  6. "strings"
  7. "time"
  8. )
  9. // var url = "https://deposit.paylomo.net/pay.php?r=payEasy" //production
  10. // var url = "https://deposit-mac.chinapaytech.com/pay.php?r=payEasy" //test
  11. // var md5p2p = "370296119874502"
  12. // var md5fat = "207841502473198"
  13. type RpnReq struct {
  14. version string
  15. sign_type string
  16. mid string
  17. notify_url string
  18. order_id string
  19. order_amount string
  20. order_time string //YYYYMMDDHHMMSS
  21. user_id string
  22. user_name string
  23. user_cardno string
  24. signature string
  25. }
  26. //build request from leanwork request forms
  27. func (m *RpnReq) buildReqByForm(form url.Values) RpnReq {
  28. r := RpnReq{}
  29. r.version = "1.1"
  30. r.sign_type = "MD5"
  31. r.mid = "EU85201311P2P"
  32. r.notify_url = "http://rpn.supertraderfx.ayvwd8em49pvoa3g.com/rpn_notify"
  33. r.order_id = form["orderNo"][0]
  34. r.order_amount = form["orderAmount"][0] //cents
  35. r.order_time = m.now()
  36. r.user_id = form["customerId"][0]
  37. r.user_name = "SuperForex"
  38. r.user_cardno = "6212262002002377849"
  39. r.signature = md4RpnFormP2P(r)
  40. *m = r
  41. return r
  42. }
  43. func (m *RpnReq) now() string {
  44. t := time.Now()
  45. return t.Format("20060102150405")
  46. }
  47. //send request to RPN to initiate transaction
  48. func (m *RpnReq) SendReq(form url.Values) (*http.Response, error) {
  49. r := m.buildReqByForm(form)
  50. hc := http.Client{Timeout: 15 * time.Second}
  51. myForm := url.Values{}
  52. myForm.Set("version", r.version)
  53. myForm.Set("sign_type", r.sign_type)
  54. myForm.Set("mid", r.mid)
  55. myForm.Set("notify_url", r.notify_url)
  56. myForm.Set("order_id", r.order_id)
  57. myForm.Set("order_amount", r.order_amount)
  58. myForm.Set("order_time", r.order_time)
  59. myForm.Set("user_id", r.user_id)
  60. myForm.Set("user_name", r.user_name)
  61. myForm.Set("user_cardno", r.user_cardno)
  62. myForm.Set("signature", r.signature)
  63. //req, err := http.NewRequest("POST", "https://lawipac.com/dumprequest.php", strings.NewReader(myForm.Encode()))
  64. req, err := http.NewRequest("POST", Config.Rpn.UrlTest, strings.NewReader(m.encode()))
  65. if err != nil {
  66. panic("wrong")
  67. }
  68. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  69. req.Header.Add("content-Length", strconv.Itoa(len(form.Encode())))
  70. return hc.Do(req)
  71. //Config.Rpn.UrlTest
  72. // return http.PostForm(Config.Rpn.UrlTest, myForm)
  73. //return http.PostForm("https://lawipac.com/dumprequest.php", myForm)
  74. }
  75. //encode without disturbing it's original order
  76. func (m *RpnReq) encode() string {
  77. s := "version=" + m.version
  78. s += "&sign_type=" + m.sign_type
  79. s += "&mid=" + m.mid
  80. s += "&notify_url=" + url.QueryEscape(m.notify_url)
  81. s += "&order_id=" + m.order_id
  82. s += "&order_amount=" + m.order_amount
  83. s += "&order_time=" + m.order_time
  84. s += "&user_id=" + m.user_id
  85. s += "&user_name=" + m.user_name
  86. s += "&user_cardno=" + m.user_cardno
  87. s += "&signature=" + m.signature
  88. return s
  89. }
  90. // <?php
  91. // $data = array(
  92. // 'version'=>'1.1',
  93. // 'sign_type'=> 'MD5',
  94. // 'mid' => 'EU85201311P2P', //must to use your mid
  95. // 'notify_url' => 'https://lawipac.com/dumprequest.php',
  96. // 'order_id' => "demo-" . date('YmdHis'),
  97. // 'order_amount' => 120000 , //round($_POST['amount']*100),
  98. // 'order_time' => date('YmdHis'),
  99. // 'user_id'=> 'supertraderP2P', //$_POST['user_id'],
  100. // 'user_name'=>"zhang3", //urlencode($_POST['user_name']),
  101. // 'user_cardno'=>"6212262002002377849" //$_POST['user_cardno'],
  102. // );
  103. // $params = array();
  104. // foreach ($data as $field => $value) {
  105. // if( $value == '' ) continue;
  106. // $params[] = "$field=$value";
  107. // }
  108. // $params[] = "key=p1j4A3mEMj+ft0xkSfVULQ"; //must to use your key
  109. // $data['signature'] = md5(implode('|', $params));
  110. // ?>
  111. // <html>
  112. // <head>
  113. // <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  114. // </head>
  115. // <body>
  116. // <form id="payment" name="payment" action="https://deposit.paylomo.net/pay.php?r=payEasy" method="POST">
  117. // <?php
  118. // foreach ($data as $key => $val) {
  119. // echo '<input type="hidden" name="'.$key.'" value="'.$val.'" />';
  120. // }
  121. // ?>
  122. // <input type="submit" value="submit">
  123. // </form>
  124. // </body>
  125. // <script type="text/javascript">
  126. // // document.getElementById('payment').submit();
  127. // </script>
  128. // some text