UsdtpayController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2019/4/24
  5. * Time: 下午3:10
  6. */
  7. namespace app\payment\controllers;
  8. use app\common\helpers\Url;
  9. use app\common\models\AccountWechats;
  10. use app\common\services\Pay;
  11. use app\payment\PaymentController;
  12. use Yunshop\Usdtpay\services\UsdtpayNotifyService;
  13. class UsdtpayController extends PaymentController
  14. {
  15. private $attach = [];
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. if (empty(\YunShop::app()->uniacid)) {
  20. $this->attach = explode(':', $_POST['orderNo']);
  21. \Setting::$uniqueAccountId = \YunShop::app()->uniacid = $this->attach[1];
  22. AccountWechats::setConfig(AccountWechats::getAccountByUniacid(\YunShop::app()->uniacid));
  23. }
  24. }
  25. public function notifyUrl()
  26. {
  27. $parameter = $_POST;
  28. $this->log($parameter);
  29. if($this->getSignResult()) {
  30. if ($_POST['status'] == 'success') {
  31. \Log::debug('------验证成功-----');
  32. $data = [
  33. 'total_fee' => floatval($parameter['orderAmount']),
  34. 'out_trade_no' => $this->attach[0],
  35. 'trade_no' => $parameter['transactionId'],
  36. 'unit' => 'yuan',
  37. 'pay_type' => 'USDT支付',
  38. 'pay_type_id' => 27
  39. ];
  40. $this->payResutl($data);
  41. \Log::debug('----结束----');
  42. echo 'success';
  43. } else {
  44. //其他错误
  45. echo 'fail';
  46. }
  47. } else {
  48. //签名验证失败
  49. echo 'fail1';
  50. }
  51. }
  52. public function returnUrl()
  53. {
  54. $trade = \Setting::get('shop.trade');
  55. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  56. return redirect($trade['redirect_url'])->send();
  57. }
  58. if (0 == $_GET['state'] && $_GET['errorDetail'] == '成功') {
  59. redirect(Url::absoluteApp('member/payYes', ['i' => $_GET['attach']]))->send();
  60. } else {
  61. redirect(Url::absoluteApp('member/payErr', ['i' => $_GET['attach']]))->send();
  62. }
  63. }
  64. /**
  65. * 签名验证
  66. *
  67. * @return bool
  68. */
  69. public function getSignResult()
  70. {
  71. $pay = \Setting::get('plugin.usdtpay_set');
  72. $notify = new UsdtpayNotifyService();
  73. $notify->setKey($pay['key']);
  74. return $notify->verifySign();
  75. }
  76. /**
  77. * 支付日志
  78. *
  79. * @param $post
  80. */
  81. public function log($data)
  82. {
  83. $orderNo = explode(':', $data['orderNo']);
  84. //访问记录
  85. Pay::payAccessLog();
  86. //保存响应数据
  87. Pay::payResponseDataLog($orderNo[0], 'Usdt支付', json_encode($data));
  88. }
  89. }