PayController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LikeShop有特色的全开源社交分销电商系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 商业用途务必购买系统授权,以免引起不必要的法律纠纷
  7. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  8. // | 微信公众号:好象科技
  9. // | 访问官网:http://www.likemarket.net
  10. // | 访问社区:http://bbs.likemarket.net
  11. // | 访问手册:http://doc.likemarket.net
  12. // | 好象科技开发团队 版权所有 拥有最终解释权
  13. // +----------------------------------------------------------------------
  14. // | Author: LikeShopTeam-段誉
  15. // +----------------------------------------------------------------------
  16. namespace app\shopapi\controller;
  17. use app\common\enum\UserTerminalEnum;
  18. use app\common\logic\PaymentLogic;
  19. use app\common\service\pay\AliPayService;
  20. use app\common\service\pay\ToutiaoPayService;
  21. use app\common\service\pay\WeChatPayService;
  22. use app\shopapi\validate\PayValidate;
  23. use think\facade\Log;
  24. /**
  25. * 支付
  26. * Class PayController
  27. * @package app\shopapi\controller
  28. */
  29. class PayController extends BaseShopController
  30. {
  31. public array $notNeedLogin = ['notifyMnp', 'notifyOa', 'notifyApp', 'aliNotify', 'toutiaoNotify'];
  32. /**
  33. * @notes 预支付
  34. * @return \think\response\Json
  35. * @throws \Exception
  36. * @author 段誉
  37. * @date 2021/8/3 14:03
  38. */
  39. public function prepay()
  40. {
  41. $params = (new PayValidate())->post()->goCheck();
  42. //订单信息
  43. $order = PaymentLogic::getPayOrderInfo($params);
  44. if (false === $order) {
  45. return $this->fail(PaymentLogic::getError(), $params);
  46. }
  47. //支付流程
  48. $result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo['terminal']);
  49. if (false === $result) {
  50. return $this->fail(PaymentLogic::getError(), $params);
  51. }
  52. return $this->success('', $result);
  53. }
  54. /**
  55. * @notes 小程序支付回调
  56. * @return \Symfony\Component\HttpFoundation\Response
  57. * @author 段誉
  58. * @date 2021/8/13 14:17
  59. */
  60. public function notifyMnp()
  61. {
  62. return (new WeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
  63. }
  64. /**
  65. * @notes 公众号支付回调
  66. * @return \Symfony\Component\HttpFoundation\Response
  67. * @author 段誉
  68. * @date 2021/8/13 14:17
  69. */
  70. public function notifyOa()
  71. {
  72. return (new WeChatPayService(UserTerminalEnum::WECHAT_OA))->notify();
  73. }
  74. /**
  75. * @notes app支付回调
  76. * @author 段誉
  77. * @date 2021/8/13 14:16
  78. */
  79. public function notifyApp()
  80. {
  81. return (new WeChatPayService(UserTerminalEnum::IOS))->notify();
  82. }
  83. /**
  84. * @notes 支付宝回调
  85. * @return bool
  86. * @author 段誉
  87. * @date 2021/8/13 14:16
  88. */
  89. public function aliNotify()
  90. {
  91. $params = $this->request->post();
  92. $result = (new AliPayService())->notify($params);
  93. if (true === $result) {
  94. echo 'success';
  95. } else {
  96. echo 'fail';
  97. }
  98. }
  99. /**
  100. * @notes 头条支付回调(字节小程序)
  101. * @return mixed
  102. * @author Tab
  103. * @date 2021/11/17 11:40
  104. */
  105. public function toutiaoNotify()
  106. {
  107. $params = $this->request->post();
  108. $result = (new ToutiaoPayService())->notify($params);
  109. return $result;
  110. }
  111. /**
  112. * @notes 支付方式列表
  113. * @return \think\response\Json
  114. * @author 段誉
  115. * @date 2021/8/13 14:33
  116. */
  117. public function payway()
  118. {
  119. $params = (new PayValidate())->goCheck('payway');
  120. $result = PaymentLogic::getPayWay($this->userId, $this->userInfo['terminal'], $params);
  121. if ($result === false) {
  122. return $this->fail(PaymentLogic::getError());
  123. }
  124. return $this->data($result);
  125. }
  126. public function payStatus()
  127. {
  128. $params = (new PayValidate())->goCheck('paystatus');
  129. $result = PaymentLogic::getPayStatus($params);
  130. if ($result === false) {
  131. return $this->fail(PaymentLogic::getError());
  132. }
  133. return $this->data($result);
  134. }
  135. /**
  136. * @notes 获取支付结果
  137. * @return \think\response\Json
  138. * @author 段誉
  139. * @date 2022/4/6 15:23
  140. */
  141. public function payResult()
  142. {
  143. $params = (new PayValidate())->goCheck('payresult');
  144. $result = PaymentLogic::getPayResult($params);
  145. if ($result === false) {
  146. return $this->fail(PaymentLogic::getError());
  147. }
  148. return $this->data($result);
  149. }
  150. }