Chinabank.class.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. if (isset($set_modules) && $set_modules == TRUE)
  4. {
  5. $i = isset($modules) ? count($modules) : 0;
  6. $modules[$i]['code'] = basename(__FILE__, '.class.php');
  7. $modules[$i]['name'] = L('chinabank', '', 'pay');
  8. $modules[$i]['desc'] = L('chinabank_tip', '', 'pay');
  9. $modules[$i]['is_cod'] = '0';
  10. $modules[$i]['is_online'] = '1';
  11. $modules[$i]['author'] = 'PHPCMS开发团队';
  12. $modules[$i]['website'] = 'http://www.chinabank.com.cn';
  13. $modules[$i]['version'] = '1.0.0';
  14. $modules[$i]['config'] = array(
  15. array('name' => 'chinabank_account','type' => 'text','value' => ''),
  16. array('name' => 'chinabank_key','type' => 'text','value' => ''),
  17. );
  18. return;
  19. }
  20. pc_base::load_app_class('pay_abstract','','0');
  21. class Chinabank extends paymentabstract{
  22. public function __construct($config = array()) {
  23. if (!empty($config)) $this->set_config($config);
  24. $this->config['gateway_url'] = 'https://pay3.chinabank.com.cn/PayGate';
  25. $this->config['gateway_method'] = 'POST';
  26. $this->config['return_url'] = return_url('chinabank');
  27. pc_base::load_app_func('alipay');
  28. }
  29. public function getpreparedata() {
  30. $prepare_data['v_mid'] = $this->config['chinabank_account'];
  31. $prepare_data['v_url'] = $this->config['return_url'];
  32. $prepare_data['v_moneytype'] = 'CNY';
  33. $prepare_data['return_url'] = $this->config['return_url'];
  34. // 商品信息
  35. $prepare_data['v_rcvname'] = $this->product_info['name'];
  36. $prepare_data['v_amount'] = $this->product_info['price'];
  37. //订单信息
  38. $prepare_data['v_oid'] = $this->order_info['id'];
  39. //买家信息
  40. $prepare_data['v_rcvmobile'] = $this->customer_info['telephone'];
  41. $prepare_data['v_rcvemail'] = $this->order_info['buyer_email'];
  42. //备注
  43. $prepare_data['remark1'] = $this->product_info['body'];
  44. $data =$prepare_data['v_amount'].$prepare_data['v_moneytype'].$prepare_data['v_oid'].$prepare_data['v_mid'].$prepare_data['v_url'].$this->config['chinabank_key'];
  45. // 数字签名
  46. $prepare_data['v_md5info'] = strtoupper(md5($data));
  47. return $prepare_data;
  48. }
  49. /**
  50. * 客户端接收数据
  51. * 状态码说明 (0 交易完成 1 交易失败 2 交易超时 3 交易处理中 4 交易未支付)
  52. */
  53. public function receive() {
  54. $receive_data = $this->filterParameter($_POST);
  55. $receive_data = arg_sort($receive_data);
  56. if ($receive_data) {
  57. $v_oid =trim($receive_data['v_oid']);
  58. $v_pmode =trim($receive_data['v_pmode']);
  59. $v_pstatus =trim($receive_data['v_pstatus']);
  60. $v_pstring =trim($receive_data['v_pstring']);
  61. $v_amount =trim($receive_data['v_amount']);
  62. $v_moneytype =trim($receive_data['v_moneytype']);
  63. $remark1 =trim($receive_data['remark1' ]);
  64. $remark2 =trim($receive_data['remark2' ]);
  65. $v_md5str =trim($receive_data['v_md5str' ]);
  66. $md5string=strtoupper(md5($v_oid.$v_pstatus.$v_amount.$v_moneytype.$this->config['chinabank_key']));
  67. if ($v_md5str==$md5string) {
  68. $return_data['order_id'] = $v_oid;
  69. $return_data['order_total'] = $v_amount;
  70. $return_data['price'] = $v_amount;
  71. if($v_pstatus=="20") {
  72. $return_data['order_status'] = 0;
  73. return $return_data;
  74. } else {
  75. error_log(date('m-d H:i:s',SYS_TIME).'| chinabank GET: order_status=30 |'."\r\n", 3, CACHE_PATH.'pay_error_log.php');
  76. return false;
  77. }
  78. } else {
  79. showmessage(L('illegal_sign'));
  80. return false;
  81. }
  82. } else {
  83. error_log(date('m-d H:i:s',SYS_TIME).'| GET: no return |'."\r\n", 3, CACHE_PATH.'pay_error_log.php');
  84. showmessage(L('illegal_return'));
  85. return false;
  86. }
  87. }
  88. /**
  89. * POST接收数据
  90. * 状态码说明 (0 交易完成 1 交易失败 2 交易超时 3 交易处理中 4 交易未支付)
  91. */
  92. public function notify() {
  93. $receive_data = $this->filterParameter($_POST);
  94. $receive_data = arg_sort($receive_data);
  95. if ($receive_data) {
  96. $v_oid =trim($receive_data['v_oid']);
  97. $v_pmode =trim($receive_data['v_pmode']);
  98. $v_pstatus =trim($receive_data['v_pstatus']);
  99. $v_pstring =trim($receive_data['v_pstring']);
  100. $v_amount =trim($receive_data['v_amount']);
  101. $v_moneytype =trim($receive_data['v_moneytype']);
  102. $remark1 =trim($receive_data['remark1' ]);
  103. $remark2 =trim($receive_data['remark2' ]);
  104. $v_md5str =trim($receive_data['v_md5str' ]);
  105. $md5string=strtoupper(md5($v_oid.$v_pstatus.$v_amount.$v_moneytype.$this->config['chinabank_key']));
  106. if ($v_md5str==$md5string) {
  107. $return_data['order_id'] = $v_oid;
  108. $return_data['order_total'] = $v_amount;
  109. $return_data['price'] = $v_amount;
  110. if($v_pstatus=="20") {
  111. $return_data['order_status'] = 0;
  112. } else {
  113. error_log(date('m-d H:i:s',SYS_TIME).'| chinabank notify: order_status=30 |'."\r\n", 3, CACHE_PATH.'pay_error_log.php');
  114. return false;
  115. }
  116. } else {
  117. return false;
  118. }
  119. } else {
  120. error_log(date('m-d H:i:s',SYS_TIME).'| notify: no return |'."\r\n", 3, CACHE_PATH.'pay_error_log.php');
  121. return false;
  122. }
  123. }
  124. /**
  125. * 相应服务器应答状态
  126. * @param $result
  127. */
  128. public function response($result) {
  129. if (FALSE == $result) echo 'ok';
  130. else echo 'success';
  131. }
  132. /**
  133. * 返回字符过滤
  134. * @param $parameter
  135. */
  136. private function filterParameter($parameter)
  137. {
  138. $para = array();
  139. foreach ($parameter as $key => $value)
  140. {
  141. if ('sign' == $key || 'sign_type' == $key || '' == $value || 'm' == $key || 'a' == $key || 'c' == $key || 'code' == $key ) continue;
  142. else $para[$key] = $value;
  143. }
  144. return $para;
  145. }
  146. }
  147. ?>