PayController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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,$this->userInfo['terminal']);
  44. outFileLog($order,'prepay','order');
  45. if (false === $order) {
  46. return $this->fail(PaymentLogic::getError(), $params);
  47. }
  48. //支付流程
  49. $result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo['terminal']);
  50. if (false === $result) {
  51. return $this->fail(PaymentLogic::getError(), $params);
  52. }
  53. return $this->success('', $result);
  54. }
  55. /**
  56. * @notes 小程序支付回调
  57. * @return \Symfony\Component\HttpFoundation\Response
  58. * @author 段誉
  59. * @date 2021/8/13 14:17
  60. */
  61. public function notifyMnp()
  62. {
  63. return (new WeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
  64. }
  65. /**
  66. * @notes 公众号支付回调
  67. * @return \Symfony\Component\HttpFoundation\Response
  68. * @author 段誉
  69. * @date 2021/8/13 14:17
  70. */
  71. public function notifyOa()
  72. {
  73. return (new WeChatPayService(UserTerminalEnum::WECHAT_OA))->notify();
  74. }
  75. /**
  76. * @notes app支付回调
  77. * @author 段誉
  78. * @date 2021/8/13 14:16
  79. */
  80. public function notifyApp()
  81. {
  82. return (new WeChatPayService(UserTerminalEnum::IOS))->notify();
  83. }
  84. /**
  85. * @notes 支付宝回调
  86. * @return bool
  87. * @author 段誉
  88. * @date 2021/8/13 14:16
  89. */
  90. public function aliNotify()
  91. {
  92. $params = $this->request->post();
  93. $result = (new AliPayService())->notify($params);
  94. if (true === $result) {
  95. echo 'success';
  96. } else {
  97. echo 'fail';
  98. }
  99. }
  100. /**
  101. * @notes 头条支付回调(字节小程序)
  102. * @return mixed
  103. * @author Tab
  104. * @date 2021/11/17 11:40
  105. */
  106. public function toutiaoNotify()
  107. {
  108. $params = $this->request->post();
  109. $result = (new ToutiaoPayService())->notify($params);
  110. return $result;
  111. }
  112. /**
  113. * @notes 支付方式列表
  114. * @return \think\response\Json
  115. * @author 段誉
  116. * @date 2021/8/13 14:33
  117. */
  118. public function payway()
  119. {
  120. $params = (new PayValidate())->goCheck('payway');
  121. $result = PaymentLogic::getPayWay($this->userId, $this->userInfo['terminal'], $params);
  122. if ($result === false) {
  123. return $this->fail(PaymentLogic::getError());
  124. }
  125. return $this->data($result);
  126. }
  127. public function payStatus()
  128. {
  129. $params = (new PayValidate())->goCheck('paystatus');
  130. $result = PaymentLogic::getPayStatus($params);
  131. if ($result === false) {
  132. return $this->fail(PaymentLogic::getError());
  133. }
  134. return $this->data($result);
  135. }
  136. /**
  137. * @notes 获取支付结果
  138. * @return \think\response\Json
  139. * @author 段誉
  140. * @date 2022/4/6 15:23
  141. */
  142. public function payResult()
  143. {
  144. $params = (new PayValidate())->goCheck('payresult');
  145. $result = PaymentLogic::getPayResult($params);
  146. if ($result === false) {
  147. return $this->fail(PaymentLogic::getError());
  148. }
  149. return $this->data($result);
  150. }
  151. }