PayHandler.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace common\pay\aotu;
  3. use backend\models\Deposit;
  4. use common\helpers\Utils;
  5. use common\pay\BasePayHandler;
  6. use Yii;
  7. class PayHandler extends BasePayHandler
  8. {
  9. public $payUrl;
  10. public $MerchantID;
  11. public $secretKey;
  12. /**
  13. * @inheritdoc
  14. */
  15. public function init()
  16. {
  17. parent::init();
  18. if ($this->payUrl == null) {
  19. $this->payUrl = Yii::$app->params['aotu.payUrl'];
  20. }
  21. if ($this->MerchantID == null) {
  22. $this->MerchantID = Yii::$app->params['aotu.MerchantID'];
  23. }
  24. if ($this->secretKey == null) {
  25. $this->secretKey = Yii::$app->params['aotu.secretKey'];
  26. }
  27. }
  28. /**
  29. * @param array $deposit
  30. * @param array $params
  31. * @return string
  32. */
  33. public function outPay($deposit, $params = [])
  34. {
  35. $data = [];
  36. $data['TradeType'] = 'bis.pay.submit'; // 交易类型
  37. $data['OperatorID'] = $this->MerchantID; // 操作员 默认商户编号
  38. $data['PayType'] = '0202'; // 支付类型
  39. $data['TerminalType'] = 'PC'; // 终端类型
  40. // $data['MemberID'] = ''; // 用户编号 快捷支付必填
  41. $data['MerchantID'] = $this->MerchantID; // 商户编号
  42. // $data['AppID'] = ''; // 公众号appid
  43. // $data['OpenID'] = ''; // 微信openid
  44. $data['BankID'] = isset($params['bankCode']) ? $params['bankCode'] : ''; // 银行代码
  45. $data['OrderID'] = $deposit['id']; // 订单号
  46. // $data['DeviceID'] = ''; // 设备号
  47. $data['Subject'] = 'RJ' . $deposit['id']; // 商品名称
  48. $data['MachineIP'] = isset($params['ip']) ? $params['ip'] : Utils::getClientIp(); // 终端IP
  49. $data['NotifyUrl'] = $this->notifyUrl; // 通知地址
  50. $data['ReturnUrl'] = $this->returnUrl; // 返回地址
  51. $data['SubmitTime'] = date('YmdHis'); // 订单提交时间
  52. // $data['OrderValidity'] = ''; // 订单有效截止时间
  53. $data['CreditLimit'] = '1'; // 信用卡限制使用标识
  54. $data['Amt'] = $deposit['rmb'] * 100; // 交易金额 单位为分,不含小数点
  55. // $data['Summary'] = ''; // 交易附言
  56. $data['Sign'] = PayUtils::makeSign($data, $this->secretKey); // 签名
  57. return static::createHtml($data, $this->payUrl);
  58. }
  59. /**
  60. * @param array $data
  61. * @return bool
  62. */
  63. public function handleNotify($data)
  64. {
  65. if (PayUtils::checkSign($data, $this->secretKey)) {
  66. if (isset($data['RetStatus']) && $data['RetStatus'] == 0 && isset($data['DealStatus']) && $data['DealStatus'] == 0
  67. && isset($data['Status']) && $data['Status'] == '02'
  68. ) {
  69. $merOrderId = trim($data['OrderID']);
  70. /** @var Deposit $model */
  71. $model = Deposit::find()->where(['id' => $merOrderId])->asArray()->limit(1)->one();
  72. if ($model) {
  73. // $model->type = 1;
  74. // $model->save(false);
  75. return true;
  76. }
  77. }
  78. }
  79. return false;
  80. }
  81. public function outNotify($success)
  82. {
  83. if ($success == true) {
  84. return "SUCCESS";
  85. } else {
  86. return "FAIL";
  87. }
  88. }
  89. /**
  90. * @param array $data
  91. * @return bool
  92. */
  93. public function handleReturn($data)
  94. {
  95. if (PayUtils::checkSign($data, $this->secretKey)) {
  96. if (isset($data['RetStatus']) && $data['RetStatus'] == 0 && isset($data['DealStatus']) && $data['DealStatus'] == 0) {
  97. $merOrderId = trim($data['OrderID']);
  98. /** @var Deposit $model */
  99. $model = Deposit::find()->where(['id' => $merOrderId])->asArray()->limit(1)->one();
  100. if ($model) {
  101. return true;
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. public function outReturn($success)
  108. {
  109. }
  110. }