OnlinePayment.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Biz\Payment;
  3. /**
  4. * 汇付天下接口
  5. */
  6. class OnlinePayment extends \Biz\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/wapPay";
  15. protected $paymentName = "Online";
  16. function toPay() {
  17. $data = array(
  18. 'amount' => $this->dataAccess->money, //交易金额
  19. 'goodsName' => 'Online', //商品名称,可选
  20. 'merchno' => $this->sellerInfo['busAccount'], //商户号
  21. 'notifyUrl' => $this->notifyUrl, //支付结果异步通知地址,可选
  22. 'payType' => 2, //微信
  23. 'traceno' => $this->dataAccess->orderSn, //商户订单号
  24. );
  25. $sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
  26. $data['signature'] = $sign;
  27. $data = $this->goPayCurl($this->getWay, 'POST', $data);
  28. $data = iconv('gb2312', 'utf-8', $data);
  29. $row = json_decode($data);
  30. if ($row->respCode == '00') {
  31. $this->getWay = $row->barCode;
  32. $this->goPay($data);
  33. }
  34. }
  35. function md5mcrypt($data, $key) {
  36. $str = http_build_query($data) . '&' . $key;
  37. $str = urldecode($str);
  38. return md5($str);
  39. }
  40. public function notify($order) {
  41. $re = $this->check($order);
  42. return $re;
  43. }
  44. public function redirect($order) {
  45. $re = $this->check($order);
  46. return $re;
  47. }
  48. public function check($order) {
  49. $data = array();
  50. $data['amount'] = $_POST['amount']; //交易金额
  51. $data['channelOrderno'] = $_POST['channelOrderno']; //渠道订单号
  52. $data['channelTraceno'] = $_POST['channelTraceno']; //渠道流水号
  53. if (!empty($_POST['customerno'])) {$data['customerno'] = $_POST['customerno'];} //客户号
  54. $data['merchName'] = $_POST['merchName']; //商户名称
  55. $data['merchno'] = $_POST['merchno']; //商户号
  56. if (!empty($_POST['openId'])) {$data['openId'] = $_POST['openId'];} //用户OpenId
  57. $data['orderno'] = $_POST['orderno']; //系统订单号
  58. $data['payType'] = $_POST['payType']; //支付方式
  59. if (!empty($_POST['remark'])) {$data['remark'] = $_POST['remark'];} //备注
  60. $data['status'] = $_POST['status']; //交易状态
  61. $data['traceno'] = $_POST['traceno']; //商户流水号
  62. $data['transDate'] = $_POST['transDate']; //交易日期
  63. $data['transTime'] = $_POST['transTime']; //交易时间
  64. $this->dataAccess->orderSn = $data['orderno'];
  65. $this->dataAccess->money = $data['amount'];
  66. $this->dataAccess->goodsName = '';
  67. $sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
  68. $data['signature'] = $_POST['signature']; //数据签名
  69. if ($sign == $data['signature']) {
  70. if ($data['status'] == '1') {
  71. return 1;
  72. } else {
  73. return 0;
  74. }
  75. }
  76. }
  77. function notifyMsg($key) {
  78. if ($key > 0) {
  79. echo 'ok';
  80. } else {
  81. echo '';
  82. }
  83. }
  84. public function getPaymentType() {
  85. return array(
  86. "alipay" => "1", //"支付宝",
  87. "weixin" => "2", //"微信",
  88. // "baidupay" => "3", //百度钱包
  89. // "qqpay" => "4 ", //QQ钱包",
  90. // 'jdpay' => '5', //京东钱包
  91. );
  92. }
  93. public function checkMoney($money) {
  94. if ($this->dataAccess->payType == 'qqpay') {
  95. if ($this->dataAccess->money < 10) {
  96. $this->showNotice('QQ钱包最小10元起付', -4);
  97. }
  98. }
  99. }
  100. }