PayHandler.php 4.5 KB

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