DinPayScanPayment.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace Biz\Pay\Payment;
  3. /**
  4. * 智付接口
  5. */
  6. class DinPayScanPayment extends \Biz\Pay\BasePayment {
  7. function init() {
  8. $this->privateCertPath = '';
  9. $this->publicCertPath = '';
  10. $this->sellerInfo = array(
  11. 'busKey' => openssl_get_privatekey($this->privateCertPath),
  12. 'busAccount' => '987858', //
  13. );
  14. # code...
  15. }
  16. protected $getWay = "https://api.dinpay.com/gateway/api/weixin";
  17. protected $paymentName = "DinPayScan";
  18. function toPay() {
  19. $data = array(
  20. 'merchant_code' => $this->sellerInfo['busAccount'],
  21. 'service_type' => 'wxpay',
  22. 'interface_version' => 'V3.0',
  23. 'notify_url' => $this->notifyUrl,
  24. 'order_no' => $this->dataAccess->orderSn,
  25. 'order_time' => date('Y-m-d H:i:s', time()), //
  26. 'order_amount' => $this->dataAccess->money, //
  27. 'product_name' => '在线充值支付', //
  28. );
  29. $sign = $this->sslMcrypt($data, $this->sellerInfo['busKey']);
  30. $data['sign'] = $sign;
  31. $data['sign_type'] = 'RSA-S';
  32. $ch = curl_init();
  33. curl_setopt($ch, CURLOPT_URL, $this->getWay);
  34. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  35. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  36. curl_setopt($ch, CURLOPT_POST, true);
  37. curl_setopt($ch, CURLOPT_HEADER, false);
  38. curl_setopt($ch, CURLOPT_POSTFIELDS, urldecode(http_build_query($postdata)));
  39. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  40. $response = curl_exec($ch);
  41. curl_close($ch);
  42. $res = simplexml_load_string($response);
  43. $resp_code = $res->response->resp_code;
  44. if ($resp_code == "SUCCESS") {
  45. $qrcode = $res->response->trade->qrcode;
  46. $uri = $qrcode;
  47. if ($this->returnType == 'json') {
  48. JsonReturn(array('qrcode' => 'http://' . WEB_URI . '/Home/PayNotify/showQr?value=' . urldecode($uri)), 1, 'success');
  49. }
  50. $qrcode_url = 'http://' . WEB_URI . '/Home/PayNotify/showQr?value=' . urldecode($uri);
  51. $orderSn = $this->dataAccess->orderSn;
  52. include View();
  53. return;
  54. } else {
  55. if ($this->returnType == 'json') {
  56. JsonReturn('', -2, $resp_code . '-支付错误,联系管理员');
  57. }
  58. }
  59. }
  60. function sslMcrypt($data, $key) {
  61. $data = $this->fileterData($data);
  62. $str = http_build_query($data);
  63. $str = urldecode($str);
  64. openssl_sign($str, $sign_info, $key, OPENSSL_ALGO_MD5);
  65. $sign = urlencode(base64_encode($sign_info));
  66. return $sign;
  67. }
  68. function sslcrypt($data, $sign, $key) {
  69. $data = $this->fileterData($data);
  70. $str = http_build_query($data);
  71. $str = urldecode($str);
  72. return openssl_verify($str, $sign, $key, OPENSSL_ALGO_MD5);
  73. }
  74. function fileterData($data) {
  75. if (is_array($data) && count($data) > 0) {
  76. ksort($data);
  77. foreach ($data as $k => $v) {
  78. if (empty($v)) {
  79. unset($data[$k]);
  80. }
  81. }
  82. }
  83. return $data;
  84. }
  85. public function notify($order) {
  86. # code...
  87. $re = $this->check($order);
  88. return $re;
  89. }
  90. public function redirect($order) {
  91. $re = $this->check($order);
  92. return $re;
  93. }
  94. public function check($order) {
  95. $data = array();
  96. $this->dataAccess->orderSn = $data['order_no'] = $_POST['order_no'];
  97. $data['order_time'] = $_POST['order_time'];
  98. $this->dataAccess->money = $data['order_amount'] = $_POST['order_amount'];
  99. $data['trade_no'] = $_POST['trade_no'];
  100. $data['trade_time'] = $_POST['trade_time'];
  101. $data['trade_status'] = $_POST['trade_status'];
  102. $data['notify_id'] = $_POST['notify_id'];
  103. $data['notify_type'] = $_POST['notify_type'];
  104. $data['interface_version'] = $_POST['interface_version'];
  105. $data['merchant_code'] = $_POST['merchant_code'];
  106. $sign = base64_decode($_POST["sign"]);
  107. $data['bank_seq_no'] = $_POST["bank_seq_no"];
  108. $data['extra_return_param'] = $_POST["extra_return_param"];
  109. // $data['sign_type'] = $_POST['sign_type'];
  110. if ($this->sslcrypt($data, $sign, openssl_get_publickey($this->publicCertPath), OPENSSL_ALGO_MD5)) {
  111. return 1;
  112. } else {
  113. return 0;
  114. }
  115. }
  116. function notifyMsg($key) {
  117. if ($key > 0) {
  118. echo 'SUCCESS';
  119. } else {
  120. echo '';
  121. }
  122. }
  123. public function getPaymentType() {
  124. # code...
  125. return array(
  126. 'weixin' => 'weixin',
  127. );
  128. }
  129. }