ETongBaoPayment.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace Biz\Pay\Payment;
  3. /**
  4. * 赢通宝支付
  5. */
  6. class ETongBaoPayment extends \Biz\Pay\BasePayment {
  7. protected $getWay = "http://api.ytbao.net/passivePay";
  8. protected $paymentName = "ETongBao";
  9. protected $charset = "GBK";
  10. function init() {
  11. $this->sellerInfo = array(
  12. 'busKey' => "C7388B4909B19274E219DECE40FD6E42",
  13. 'busAccount' => '900371455510001', //360cd.cn
  14. );
  15. }
  16. public function toPay() {
  17. $payType = 0;
  18. $payment_list = $this->getPaymentType();
  19. if (isset($payment_list[$this->dataAccess->payType])) {
  20. $payType = $payment_list[$this->dataAccess->payType];
  21. } else {
  22. JsonReturn('', -3, '支付类型不正确');
  23. }
  24. $data = array();
  25. $data['merchno'] = $this->sellerInfo['busAccount'];
  26. $data['amount'] = $this->dataAccess->money;
  27. $data['traceno'] = $this->dataAccess->orderSn;
  28. $data['payType'] = $payType;
  29. $data['goodsName'] = iconv('utf-8', 'gbk', $this->dataAccess->goodsName);
  30. $data['notifyUrl'] = $this->notifyUrl;
  31. $data['signature'] = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
  32. // print_r($data);
  33. $data = $this->goPayCurl($this->getWay, $data);
  34. $data = iconv('gb2312', 'utf-8', $data);
  35. if (empty($data)) {
  36. JsonReturn(array(), -1, "支付异常请联系管理员");
  37. }
  38. $data = json_decode($data, 1);
  39. if ($data['respCode'] == '00') {
  40. $uri = $data['barCode'];
  41. if ($this->returnType == 'json') {
  42. JsonReturn(array('qrcode' => 'http://' . WEB_URI . '/Home/PayNotify/showQr?value=' . urldecode($uri)), 1, 'success');
  43. }
  44. $qrcode_url = 'http://' . WEB_URI . '/Home/PayNotify/showQr?value=' . urldecode($uri);
  45. $orderSn = $this->dataAccess->orderSn;
  46. include View();
  47. return;
  48. }
  49. if ($this->returnType == 'json') {
  50. JsonReturn(array(), -2, $data['message'] . "-支付异常请联系管理员");
  51. }
  52. exit($data['message'] . "-支付异常请联系管理员");
  53. }
  54. public function notify($order) {
  55. # code...
  56. $re = $this->check($order);
  57. return $re;
  58. }
  59. public function redirect($order) {
  60. $re = $this->check($order);
  61. return $re;
  62. }
  63. function check() {
  64. $data = array();
  65. $data['transDate'] = $_POST['transDate'];
  66. $data['transTime'] = $_POST['transTime'];
  67. $data['merchno'] = $_POST['merchno'];
  68. $data['merchName'] = $_POST['merchName'];
  69. $data['amount'] = $_POST['amount'];
  70. $data['traceno'] = $_POST['traceno'];
  71. $data['payType'] = $_POST['payType'];
  72. $data['orderno'] = $_POST['orderno'];
  73. $data['channelOrderno'] = $_POST['channelOrderno'];
  74. $data['channelTraceno'] = $_POST['channelTraceno'];
  75. $data['status'] = $_POST['status'];
  76. $md5sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
  77. $data['customerno'] = $_POST['customerno'];
  78. $data['openId'] = $_POST['openId'];
  79. $this->dataAccess->money = $data['amount'];
  80. $this->dataAccess->orderSn = $data['traceno'];
  81. $this->dataAccess->payType = $data['payType'];
  82. $this->dataAccess->goodsName = '';
  83. $data['signature'] = $_POST['signature'];
  84. if ($data['signature'] == $md5sign) {
  85. return 1;
  86. }
  87. return 0;
  88. }
  89. function md5mcrypt($data, $key) {
  90. $str = array();
  91. if (is_array($data) && count($data) > 0) {
  92. ksort($data);
  93. foreach ($data as $k => $v) {
  94. if (empty($v)) {
  95. unset($data[$k]);
  96. }
  97. $str[] = "{$k}={$v}";
  98. }
  99. }
  100. if (is_array($str) && count($str) > 0) {
  101. $str = implode('&', $str) . '&' . $key;
  102. //toLog($str);
  103. return md5($str);
  104. }
  105. }
  106. public function getPaymentType() {
  107. # code...
  108. return array(
  109. "alipay" => "1", //"支付宝",
  110. "weixin" => "2", //"微信",
  111. "baidupay" => "4", //"百度钱包",
  112. "qqpay" => "8", //QQ钱包",
  113. "jdpay" => "16", //京东钱包",
  114. "union" => "32", //"银联钱包",
  115. );
  116. }
  117. function notifyMsg($key) {
  118. if ($key > 0) {
  119. echo 'success';
  120. } else {
  121. echo 'fail';
  122. }
  123. }
  124. }
  125. ?>