Pay.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\pay;
  12. use app\service\api\pay\PayService;
  13. use core\base\BaseApiController;
  14. use think\db\exception\DataNotFoundException;
  15. use think\db\exception\DbException;
  16. use think\db\exception\ModelNotFoundException;
  17. use think\Response;
  18. /**
  19. * 微信服务端通信以及网页授权
  20. */
  21. class Pay extends BaseApiController
  22. {
  23. /**
  24. * 接收消息并推送
  25. * @return void|null
  26. */
  27. public function notify($channel, $type, $action)
  28. {
  29. return (new PayService())->notify($channel, $type, $action);
  30. }
  31. /**
  32. * 去支付
  33. * @return Response
  34. */
  35. public function pay()
  36. {
  37. $data = $this->request->params([
  38. ['type', ''],
  39. ['trade_type', ''],//业务类型
  40. ['trade_id', ''],//业务id
  41. ['quit_url', ''],
  42. ['buyer_id', ''],
  43. ['return_url', ''],
  44. ['voucher', ''],
  45. ['openid', '']
  46. ]);
  47. return success('SUCCESS',(new PayService())->pay($data['type'], $data['trade_type'], $data['trade_id'], $data['return_url'], $data['quit_url'], $data['buyer_id'], $data['voucher'], $data['openid']));
  48. }
  49. /**
  50. * 支付
  51. * @param $trade_type
  52. * @param $trade_id
  53. * @return Response
  54. */
  55. public function info($trade_type, $trade_id)
  56. {
  57. return success((new PayService())->getInfoByTrade($trade_type, $trade_id));
  58. }
  59. /**
  60. * 获取可用的支付方法
  61. * @param $trade_type
  62. * @return Response
  63. * @throws DataNotFoundException
  64. * @throws DbException
  65. * @throws ModelNotFoundException
  66. */
  67. public function getPayType($trade_type){
  68. return success((new PayService())->getPayTypeByTrade($trade_type));
  69. }
  70. /**
  71. * 关闭支付
  72. * @return Response
  73. */
  74. public function close(){
  75. $data = $this->request->params([
  76. ['out_trade_no', ''],
  77. ['type', ''],
  78. ]);
  79. return success('SUCCESS',(new PayService())->close($data['type'], $data['out_trade_no']));
  80. }
  81. }