OnlineScanPayment.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Biz\Pay\Payment;
  3. /**
  4. * 汇付天下接口
  5. */
  6. class OnlineScanPayment extends \Biz\Pay\BasePayment {
  7. function init() {
  8. $this->sellerInfo = array(
  9. 'busKey' => "1E09D11FB5A71BED5D21B79FC2FD9E95",
  10. 'busAccount' => '666310144570001',
  11. );
  12. # code...
  13. }
  14. protected $getWay = "http://p.1wpay.com/a/passivePay";
  15. protected $paymentName = "OnlineScan";
  16. function toPay() {
  17. $paymentTypes = $this->getPaymentType();
  18. if (array_key_exists($this->dataAccess->payType, $paymentTypes)) {
  19. $payType = $paymentTypes[$this->dataAccess->payType];
  20. } else {
  21. $payType = 1;
  22. }
  23. $data = array(
  24. 'amount' => $this->dataAccess->money, //交易金额
  25. 'goodsName' => 'OnlineScan', //商品名称,可选
  26. 'merchno' => $this->sellerInfo['busAccount'], //商户号
  27. 'notifyUrl' => $this->notifyUrl, //支付结果异步通知地址,可选
  28. 'payType' => $payType, //支付类型
  29. 'traceno' => $this->dataAccess->orderSn, //商户订单号
  30. );
  31. $sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
  32. $data['signature'] = $sign;
  33. $data = $this->goPayCurl($this->getWay, $data);
  34. $data = iconv('gb2312', 'utf-8', $data);
  35. $row = json_decode($data, true);
  36. if ($row['respCode'] == '00') {
  37. $uri = $row['barCode'];
  38. if ($this->returnType == 'json') {
  39. JsonReturn(array('qrcode' => 'http://' . WEB_URI . '/Home/PayNotify/showQr?value=' . urldecode($uri)), 1, 'success');
  40. }
  41. $qrcode_url = 'http://' . WEB_URI . '/Home/PayNotify/showQr?value=' . urldecode($uri);
  42. $orderSn = $this->dataAccess->orderSn;
  43. include View();
  44. return;
  45. }
  46. if ($this->returnType == 'json') {
  47. JsonReturn(array(), -2, $row['msg'] . "-支付异常请联系管理员");
  48. }
  49. exit($row['msg'] . "-支付异常请联系管理员");
  50. }
  51. function md5mcrypt($data, $key) {
  52. $str = http_build_query($data) . '&' . $key;
  53. $str = urldecode($str);
  54. return md5($str);
  55. }
  56. public function notify($order) {
  57. $re = $this->check($order);
  58. return $re;
  59. }
  60. public function redirect($order) {
  61. $re = $this->check($order);
  62. return $re;
  63. }
  64. public function check($order) {
  65. $data = array();
  66. $data['amount'] = $_POST['amount']; //交易金额
  67. $data['channelOrderno'] = $_POST['channelOrderno']; //渠道订单号
  68. $data['channelTraceno'] = $_POST['channelTraceno']; //渠道流水号
  69. if (isset($_POST['customerno']) && (!empty($_POST['customerno']))) {$data['customerno'] = $_POST['customerno'];} //客户号
  70. $data['merchName'] = $_POST['merchName']; //商户名称
  71. $data['merchno'] = $_POST['merchno']; //商户号
  72. if (isset($_POST['openId']) && (!empty($_POST['openId']))) {$data['openId'] = $_POST['openId'];} //用户OpenId
  73. $data['orderno'] = $_POST['orderno']; //系统订单号
  74. $data['payType'] = $_POST['payType']; //支付方式
  75. if (isset($_POST['remark']) && (!empty($_POST['remark']))) {$data['remark'] = $_POST['remark'];} //备注
  76. $data['status'] = $_POST['status']; //交易状态
  77. $data['traceno'] = $_POST['traceno']; //商户流水号
  78. $data['transDate'] = $_POST['transDate']; //交易日期
  79. $data['transTime'] = $_POST['transTime']; //交易时间
  80. $this->dataAccess->orderSn = $data['traceno'];
  81. $this->dataAccess->money = $data['amount'];
  82. $this->dataAccess->goodsName = '';
  83. $sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
  84. $data['signature'] = $_POST['signature']; //数据签名
  85. if ($sign == $data['signature']) {
  86. if ($data['status'] == '1') {
  87. return 1;
  88. } else {
  89. return 0;
  90. }
  91. }
  92. return 0;
  93. }
  94. function notifyMsg($key) {
  95. if ($key > 0) {
  96. echo 'ok';
  97. } else {
  98. echo '';
  99. }
  100. }
  101. public function getPaymentType() {
  102. return array(
  103. "alipay" => "1", //"支付宝",
  104. "weixin" => "2", //"微信",
  105. // "baidupay" => "3", //百度钱包
  106. // "qqpay" => "4 ", //QQ钱包",
  107. // 'jdpay' => '5', //京东钱包
  108. );
  109. }
  110. public function checkMoney($money) {
  111. if ($this->dataAccess->payType == 'qqpay') {
  112. if ($this->dataAccess->money < 10) {
  113. $this->showNotice('QQ钱包最小10元起付', -4);
  114. }
  115. }
  116. }
  117. }