AlipayController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * AlipayController.php UTF-8
  4. * 支付宝对外处理页面
  5. *
  6. * @date : 2018/2/8 15:42
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace api\sdk\controller;
  13. use api\common\controller\V2ApiBaseController;
  14. use huo\controller\conf\PaywayConf;
  15. use huo\controller\pay\Notify;
  16. use huo\controller\pay\SdkOrderCache;
  17. use huo\controller\pay\SdkPayCache;
  18. use huolib\pay\Pay;
  19. use think\Config;
  20. class AlipayController extends V2ApiBaseController {
  21. function _initialize() {
  22. parent::_initialize();
  23. \think\Log::write($this->request->getContent(), 'error');
  24. Config::set('default_return_type', 'html');
  25. }
  26. /**
  27. * 支付宝支付回调地址
  28. * alipay/notify
  29. */
  30. public function notifyUrl() {
  31. $_class = new Notify();
  32. $_product_id = get_val($_REQUEST, 'body', '');
  33. $_order_id = get_val($_REQUEST, 'out_trade_no', '');
  34. $_class->notifyUrl('alipay', $_product_id, 0, $_order_id);
  35. }
  36. /**
  37. * 支付宝支付通知地址
  38. * alipay/return
  39. *
  40. * @return mixed
  41. * @throws \think\Exception
  42. */
  43. public function returnUrl() {
  44. $_order_id = $this->request->param('order_id/s', '');
  45. $_pay_class = Pay::ins()->get('alipay');
  46. $_pay_class->setOrderId($_order_id);
  47. /* 读取支付宝配置 start */
  48. $_order_data = SdkOrderCache::ins()->getInfoByOrderId($_order_id);
  49. $_app_id = $_order_data['app_id'] ?? 0;
  50. $_config = (new PaywayConf())->getConfByAppPayway($_app_id, 'alipay');
  51. $_pay_class->setConf($_config);
  52. /* 读取支付宝配置 end */
  53. $_pay_rs = $_pay_class->returnUrl();
  54. $this->assign('info', $_pay_rs);
  55. $_apple_id = $this->request->param('apple_id/s', '');
  56. $_msg = "支付成功!";
  57. $_return_token = '';
  58. if (!empty($_apple_id)) {
  59. //$_return_token = 'htsdk.com633403350://qo?oi='.$_pay_rs['order_id'].'&bt=1&st=2';
  60. $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_pay_rs['order_id'].'&st=2&bt=CHECK_SAVESUCCESS';
  61. }
  62. if ("3" == $_pay_rs['status']) {
  63. $_msg = "支付失败!";
  64. $this->assign('msg', $_msg);
  65. if (!empty($_apple_id)) {
  66. $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_pay_rs['order_id'].'&bt=CHECK_SAVEFAILED&st=1';
  67. }
  68. $this->assign('return_url', $_return_token);
  69. return $this->fetch('order/failed');
  70. }
  71. $this->assign('msg', $_msg);
  72. $this->assign('return_url', $_return_token);
  73. return $this->fetch('order/success');
  74. }
  75. /**
  76. * 支付宝支付显示地址
  77. * alipay/show
  78. *
  79. * @return mixed
  80. */
  81. public function showUrl() {
  82. $_order_id = $this->request->param('order_id/s', '');
  83. $_apple_id = $this->request->param('apple_id/s', '');
  84. $_return_token = '';
  85. if (!empty($_apple_id)) {
  86. $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_order_id.'&bt=CHECK_SAVEFAILED&st=1';
  87. }
  88. $this->assign('return_url', $_return_token);
  89. if (empty($_order_id)) {
  90. $_msg = '未支付';
  91. $this->assign('msg', $_msg);
  92. return $this->fetch('order/failed');
  93. }
  94. $_msg = '玩家取消支付,请重新下单';
  95. $this->assign('msg', $_msg);
  96. return $this->fetch('order/failed');
  97. }
  98. /**
  99. * IOS支付切换 支付url
  100. */
  101. public function submitUrl() {
  102. $_order_id = $this->request->param('order_id/s', '');
  103. $_pay_token = $this->request->param('pay_token/s', '');
  104. $_apple_id = $this->request->param('apple_id/s', '');
  105. $_pay_data = SdkPayCache::ins()->getInfoByOrderId($_order_id);
  106. $_return_token = '';
  107. if (empty($_apple_id)) {
  108. $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_order_id.'&bt=CHECK_SAVEFAILED&st=1';
  109. }
  110. if (empty($_order_id) || empty($_pay_token)) {
  111. $_msg = "亲,您支付失败了,请点击关闭按钮重试!";
  112. $this->assign('return_url', $_return_token);
  113. $this->assign('msg', $_msg);
  114. return $this->fetch('order/submit');
  115. }
  116. if ($_pay_token != $_pay_data['pay_token']) {
  117. $_msg = "亲,您支付失败了,请点击关闭按钮重试!";
  118. $this->assign('return_url', $_return_token);
  119. $this->assign('msg', $_msg);
  120. return $this->fetch('order/submit');
  121. }
  122. $_html = $_pay_data['token'];
  123. $_html = $_html."<script>document.forms['alipaysubmit'].submit();</script>";
  124. echo $_html;
  125. exit;
  126. }
  127. }