PayController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1;
  12. use crmeb\services\AliPayService;
  13. use crmeb\services\wechat\Payment;
  14. /**
  15. * 支付相关回调
  16. * Class PayController
  17. * @package app\controller\api\v1
  18. */
  19. class PayController
  20. {
  21. /**
  22. * 支付回调
  23. * @param string $type
  24. * @return string|\think\Response
  25. * @throws \EasyWeChat\Kernel\Exceptions\Exception
  26. */
  27. public function notify(string $type)
  28. {
  29. switch (urldecode($type)) {
  30. case 'alipay':
  31. return AliPayService::handleNotify();
  32. break;
  33. case 'routine':
  34. return Payment::instance()->setAccessEnd(Payment::MINI)->handleNotify();
  35. break;
  36. case 'wechat':
  37. return Payment::instance()->setAccessEnd(Payment::WEB)->handleNotify();
  38. break;
  39. case 'app':
  40. return Payment::instance()->setAccessEnd(Payment::APP)->handleNotify();
  41. break;
  42. }
  43. }
  44. /**
  45. * 退款回调
  46. * @param string $type
  47. * @return \think\Response
  48. * @throws \EasyWeChat\Kernel\Exceptions\Exception
  49. */
  50. public function refund(string $type)
  51. {
  52. switch (urldecode($type)) {
  53. case 'alipay':
  54. break;
  55. case 'routine':
  56. return Payment::instance()->setAccessEnd(Payment::MINI)->handleRefundedNotify();
  57. break;
  58. case 'wechat':
  59. return Payment::instance()->setAccessEnd(Payment::WEB)->handleRefundedNotify();
  60. break;
  61. case 'app':
  62. return Payment::instance()->setAccessEnd(Payment::APP)->handleRefundedNotify();
  63. break;
  64. }
  65. }
  66. }