CloudController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2017/8/4
  5. * Time: 下午4:04
  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\CloudPay\services\CloudPayNotifyService;
  13. class CloudController extends PaymentController
  14. {
  15. private $attach = [];
  16. public function preAction()
  17. {
  18. parent::preAction();
  19. if (empty(\YunShop::app()->uniacid)) {
  20. $this->attach = explode(':', $_GET['attach']);
  21. \Setting::$uniqueAccountId = \YunShop::app()->uniacid = $this->attach[0];
  22. AccountWechats::setConfig(AccountWechats::getAccountByUniacid(\YunShop::app()->uniacid));
  23. }
  24. }
  25. public function notifyUrl()
  26. {
  27. $this->log($_GET);
  28. if ($this->getSignResult() && '00' == $_GET['respcd'] && $_GET['errorDetail'] == "SUCCESS") {
  29. \Log::debug('------验证成功-----');
  30. $data = [
  31. 'total_fee' => floatval($_GET['txamt']),
  32. 'out_trade_no' => $_GET['orderNum'],
  33. 'trade_no' => $_GET['channelOrderNum'],
  34. 'unit' => 'fen',
  35. 'pay_type' => '云微信支付',
  36. 'pay_type_id' => 6
  37. ];
  38. $this->payResutl($data);
  39. \Log::debug('----结束----');
  40. echo "success";
  41. } else {
  42. echo "fail";
  43. }
  44. }
  45. public function notifyAliPayUrl()
  46. {
  47. $this->log($_GET);
  48. if ($this->getSignResult() && '00' == $_GET['respcd'] && $_GET['errorDetail'] == "SUCCESS") {
  49. \Log::debug('------验证成功-----');
  50. $data = [
  51. 'total_fee' => floatval($_GET['txamt']),
  52. 'out_trade_no' => $_GET['orderNum'],
  53. 'trade_no' => $_GET['channelOrderNum'],
  54. 'unit' => 'fen',
  55. 'pay_type' => '云支付宝支付',
  56. 'pay_type_id' => 7
  57. ];
  58. $this->payResutl($data);
  59. \Log::debug('----结束----');
  60. echo "success";
  61. } else {
  62. echo "fail";
  63. }
  64. }
  65. public function returnUrl()
  66. {
  67. $trade = \Setting::get('shop.trade');
  68. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  69. return redirect($trade['redirect_url'])->send();
  70. }
  71. if (0 == $_GET['state'] && $_GET['errorDetail'] == '成功') {
  72. redirect(Url::absoluteApp('member/payYes', ['i' => $_GET['attach']]))->send();
  73. } else {
  74. redirect(Url::absoluteApp('member/payErr', ['i' => $_GET['attach']]))->send();
  75. }
  76. }
  77. public function frontUrl()
  78. {
  79. $trade = \Setting::get('shop.trade');
  80. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  81. return redirect($trade['redirect_url'])->send();
  82. }
  83. if (0 == $_GET['state'] && $_GET['errorDetail'] == '成功') {
  84. redirect(Url::absoluteApp('member', ['i' => $_GET['attach']]))->send();
  85. } else {
  86. redirect(Url::absoluteApp('home', ['i' => $_GET['attach']]))->send();
  87. }
  88. }
  89. /**
  90. * 签名验证
  91. *
  92. * @return bool
  93. */
  94. public function getSignResult()
  95. {
  96. $pay = \Setting::get('plugin.cloud_pay_set');
  97. $notify = new CloudPayNotifyService();
  98. $notify->setKey($pay['key']);
  99. return $notify->verifySign();
  100. }
  101. /**
  102. * 支付日志
  103. *
  104. * @param $post
  105. */
  106. public function log($data)
  107. {
  108. //访问记录
  109. Pay::payAccessLog();
  110. //保存响应数据
  111. Pay::payResponseDataLog($data['orderNum'], '云收银微信支付', json_encode($data));
  112. }
  113. }