PayController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1;
  12. use app\Request;
  13. use crmeb\services\app\MiniProgramService;
  14. use crmeb\services\pay\Pay;
  15. /**
  16. * 支付回调
  17. * Class PayController
  18. * @package app\api\controller\v1
  19. */
  20. class PayController
  21. {
  22. /**
  23. * 支付回调
  24. * @param string $type
  25. * @return string|void
  26. * @throws \EasyWeChat\Core\Exceptions\FaultException
  27. */
  28. public function notify(string $type)
  29. {
  30. switch (urldecode($type)) {
  31. case 'alipay':
  32. /** @var Pay $pay */
  33. $pay = app()->make(Pay::class, ['ali_pay']);
  34. return $pay->handleNotify();
  35. case 'v3wechat':
  36. return app()->make(Pay::class, ['v3_wechat_pay'])->handleNotify()->getContent();
  37. case 'routine':
  38. return MiniProgramService::handleNotify();
  39. case 'wechat':
  40. if (sys_config('pay_wechat_type')) {
  41. /** @var Pay $pay */
  42. $pay = app()->make(Pay::class, ['v3_wechat_pay']);
  43. } else {
  44. /** @var Pay $pay */
  45. $pay = app()->make(Pay::class);
  46. }
  47. return $pay->handleNotify()->getContent();
  48. default:
  49. if (strstr($type, 'allin') !== false) {
  50. /** @var Pay $pay */
  51. $pay = app()->make(Pay::class, ['allin_pay']);
  52. return $pay->handleNotify($type);
  53. }
  54. }
  55. }
  56. /**
  57. * 支付配置
  58. * @param Request $request
  59. * @return mixed
  60. */
  61. public function config(Request $request)
  62. {
  63. $config = [
  64. [
  65. 'icon' => 'icon-weixinzhifu',
  66. 'name' => '微信支付',
  67. 'value' => 'weixin',
  68. 'title' => '使用微信快捷支付',
  69. 'number' => null,
  70. 'payStatus' => !!sys_config('pay_weixin_open', 0),
  71. ],
  72. [
  73. 'icon' => 'icon-zhifubao',
  74. 'name' => '支付宝支付',
  75. 'value' => 'alipay',
  76. 'title' => '使用线上支付宝支付',
  77. 'number' => null,
  78. 'payStatus' => !!sys_config('ali_pay_status', 0),
  79. ],
  80. [
  81. 'icon' => 'icon-yuezhifu',
  82. 'name' => '余额支付',
  83. 'value' => 'yue',
  84. 'title' => '当前可用余额',
  85. 'number' => $request->user('now_money'),
  86. 'payStatus' => (int)sys_config('yue_pay_status', 0) === 1,
  87. ],
  88. [
  89. 'icon' => 'icon-yuezhifu1',
  90. 'name' => '线下支付',
  91. 'value' => 'offline',
  92. 'title' => '选择线下付款方式',
  93. 'number' => null,
  94. 'payStatus' => (int)sys_config('offline_pay_status', 0) === 1,
  95. ],
  96. [
  97. 'icon' => 'icon-haoyoudaizhifu',
  98. 'name' => '好友代付',
  99. 'value' => 'friend',
  100. 'title' => '找微信好友支付',
  101. 'number' => null,
  102. 'payStatus' => !!sys_config('friend_pay_status', 0),
  103. ]
  104. ];
  105. return app('json')->success($config);
  106. }
  107. }