Pay.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. $data = $this->request->params([
  58. ['scene', '']
  59. ]);
  60. return success((new PayService())->getInfoByTrade($trade_type, $trade_id, $data));
  61. }
  62. /**
  63. * 获取找朋友帮忙付支付信息
  64. * @return Response
  65. */
  66. public function friendspayInfo($trade_type, $trade_id)
  67. {
  68. return success((new PayService())->getFriendspayInfoByTrade($trade_type, $trade_id));
  69. }
  70. /**
  71. * 获取可用的支付方法
  72. * @param $trade_type
  73. * @return Response
  74. * @throws DataNotFoundException
  75. * @throws DbException
  76. * @throws ModelNotFoundException
  77. */
  78. public function getPayType($trade_type){
  79. return success((new PayService())->getPayTypeByTrade($trade_type));
  80. }
  81. /**
  82. * 关闭支付
  83. * @return Response
  84. */
  85. public function close(){
  86. $data = $this->request->params([
  87. ['out_trade_no', ''],
  88. ['type', ''],
  89. ]);
  90. return success('SUCCESS',(new PayService())->close($data['type'], $data['out_trade_no']));
  91. }
  92. }