PayHandler.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace common\pay\duisi;
  3. use backend\models\Config;
  4. use backend\models\Deposit;
  5. use backend\models\SyncDesposit;
  6. use common\pay\BasePayHandler;
  7. use Yii;
  8. use yii\helpers\VarDumper;
  9. class PayHandler extends BasePayHandler
  10. {
  11. public $payUrl;
  12. public $merId;
  13. /**
  14. * @inheritdoc
  15. */
  16. public function init()
  17. {
  18. parent::init();
  19. if ($this->payUrl == null) {
  20. $this->payUrl ='';
  21. }
  22. if ($this->merId == null) {
  23. $this->merId ='';
  24. }
  25. }
  26. /**
  27. * @param array $deposit
  28. * @param array $params
  29. * @return string
  30. */
  31. public function outPay($deposit, $params = [])
  32. {
  33. $data = [];
  34. $money = sprintf("%.2f",$deposit['amount']);
  35. return PayHandler::createGetHtml($money);
  36. }
  37. /**
  38. * @param array $data
  39. * @return bool
  40. */
  41. public function handleNotify($data)
  42. {
  43. // Yii::warning('支付异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
  44. if (isset($data['sign']) && trim($data['sign']) !== '') {
  45. if (PayUtils::verify($data, $this->publicKey)) {
  46. if ($data['status'] == '1') {
  47. $merOrderId = trim($data['orderNo']);
  48. $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
  49. if ($reuslt['type'] != 1) {
  50. $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId");
  51. $configData = Config::find()->asArray()->one();
  52. if ($configData['auto_deposit'] == 1 && $res) {
  53. $syncDespositModel = new SyncDesposit();
  54. $syncDespositModel->login = $reuslt['login'];
  55. $syncDespositModel->amount = $reuslt['amount'];
  56. $syncDespositModel->comment = 'Deposit';
  57. $syncDespositModel->memo = $merOrderId; //存储入金表的订单id
  58. $syncDespositModel->type = 2;
  59. $syncDespositModel->in_time = time();
  60. $syncDespositModel->save();
  61. }
  62. return success;
  63. }
  64. }
  65. }
  66. }
  67. return false;
  68. }
  69. public function outNotify($success)
  70. {
  71. if ($success == true) {
  72. return "success";
  73. } else {
  74. // 返回的数据格式
  75. return "FAIL";
  76. }
  77. }
  78. /**
  79. * @param array $data
  80. * @return bool
  81. */
  82. public function handleReturn($data)
  83. {
  84. //Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
  85. if (isset($data['sign']) && trim($data['sign']) !== '') {
  86. if (PayUtils::verify($data, $this->publicKey)) {
  87. if ($data['status'] == '1') {
  88. $merOrderId = trim($data['orderNo']);
  89. $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
  90. if ($reuslt) {
  91. return success;
  92. }
  93. }
  94. }
  95. }
  96. return false;
  97. }
  98. public function outReturn($success)
  99. {
  100. }
  101. // 生成html模板文件
  102. public static function createGetHtml($money)
  103. {
  104. $html = <<<eot
  105. <div style="border: 1px solid green;width:800px;height: 500px;margin:10% auto;text-align: center;border-radius:30px;padding-top:70px; ">
  106. <p>请转账到如下账户</p>
  107. <p>订单金额为:<span style="color:red;">{$money}</span></p>
  108. <img src="/ui/img/duisi.png" style="width:250px;"/>
  109. <p>USDT钱包地址:0xAEc30e013d4d701363402dbc6B2b6C96257A4a39</p>
  110. <p>请使用USDT钱包扫码转帐</p>
  111. </div>
  112. eot;
  113. return $html;
  114. }
  115. }