AlipayController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\apple\controller;
  13. use api\common\controller\AppleApiBaseController;
  14. use huo\controller\pay\Notify;
  15. use huo\controller\pay\SdkPayCache;
  16. use huolib\pay\Pay;
  17. use think\Config;
  18. class AlipayController extends AppleApiBaseController {
  19. function _initialize() {
  20. parent::_initialize();
  21. \think\Log::write($this->request->getContent(), 'error');
  22. Config::set('default_return_type', 'html');
  23. }
  24. /**
  25. * 支付宝支付回调地址
  26. * alipay/notify
  27. */
  28. public function notifyUrl() {
  29. $_class = new Notify();
  30. $_product_id = $_REQUEST['body'];
  31. $_class->notifyUrl('alipay', $_product_id);
  32. }
  33. /**
  34. * 支付宝支付通知地址
  35. * alipay/return
  36. *
  37. * @return mixed
  38. * @throws \think\Exception
  39. */
  40. public function returnUrl() {
  41. $_order_id = $this->request->param('order_id/s', '');
  42. $_pay_class = Pay::ins()->get('alipay');
  43. $_pay_class->setOrderId($_order_id);
  44. $_pay_rs = $_pay_class->returnUrl();
  45. $this->assign('info', $_pay_rs);
  46. $_apple_id = $this->request->param('apple_id/s', '');
  47. $_msg = "支付成功!";
  48. $_return_token = '';
  49. if (!empty($_apple_id)) {
  50. //$_return_token = 'htsdk.com633403350://qo?oi='.$_pay_rs['order_id'].'&bt=1&st=2';
  51. $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_pay_rs['order_id'].'&st=2&bt=CHECK_SAVESUCCESS';
  52. }
  53. if ("3" == $_pay_rs['status']) {
  54. $_msg = "支付失败!";
  55. $this->assign('msg', $_msg);
  56. if (!empty($_apple_id)) {
  57. $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_pay_rs['order_id'].'&bt=CHECK_SAVEFAILED&st=1';
  58. }
  59. $this->assign('return_url', $_return_token);
  60. return $this->fetch('order/failed');
  61. }
  62. $this->assign('msg', $_msg);
  63. $this->assign('return_url', $_return_token);
  64. return $this->fetch('order/success');
  65. }
  66. /**
  67. * 支付宝支付显示地址
  68. * alipay/show
  69. *
  70. * @return mixed
  71. */
  72. public function showUrl() {
  73. $_order_id = $this->request->param('order_id/s', '');
  74. $_apple_id = $this->request->param('apple_id/s', '');
  75. $_return_token = '';
  76. if (!empty($_apple_id)) {
  77. $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_order_id.'&bt=CHECK_SAVEFAILED&st=1';
  78. }
  79. $this->assign('return_url', $_return_token);
  80. if (empty($_order_id)) {
  81. $_msg = '未支付';
  82. $this->assign('msg', $_msg);
  83. return $this->fetch('order/failed');
  84. }
  85. $_msg = '玩家取消支付,请重新下单';
  86. $this->assign('msg', $_msg);
  87. return $this->fetch('order/failed');
  88. }
  89. /**
  90. * IOS支付切换 支付url
  91. */
  92. public function submitUrl() {
  93. $_order_id = $this->request->param('order_id/s', '');
  94. $_pay_token = $this->request->param('pay_token/s', '');
  95. $_apple_id = $this->request->param('apple_id/s', '');
  96. $_pay_data = SdkPayCache::ins()->getInfoByOrderId($_order_id);
  97. $_return_token = '';
  98. if (empty($_apple_id)) {
  99. $_return_token = 'h'.DOCDOMAIN.$_apple_id.'://qo?oi='.$_order_id.'&bt=CHECK_SAVEFAILED&st=1';
  100. }
  101. if (empty($_order_id) || empty($_pay_token)) {
  102. $_msg = "亲,您支付失败了,请点击关闭按钮重试!";
  103. $this->assign('return_url', $_return_token);
  104. $this->assign('msg', $_msg);
  105. return $this->fetch('order/submit');
  106. }
  107. if ($_pay_token != $_pay_data['pay_token']) {
  108. $_msg = "亲,您支付失败了,请点击关闭按钮重试!";
  109. $this->assign('return_url', $_return_token);
  110. $this->assign('msg', $_msg);
  111. return $this->fetch('order/submit');
  112. }
  113. $_html = $_pay_data['token'];
  114. $_html = $_html."<script>document.forms['alipaysubmit'].submit();</script>";
  115. echo $_html;
  116. exit;
  117. }
  118. }