PayController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace backend\controllers;
  3. use common\pay\BasePayHandler;
  4. use common\pay\PayForm;
  5. use Yii;
  6. class PayController extends BaseController
  7. {
  8. /**
  9. * 支付
  10. * @return \yii\web\Response
  11. */
  12. public function actionOutpay()
  13. {
  14. $model = new PayForm();
  15. $data = Yii::$app->getRequest()->post();
  16. $model->setAttributes($data);
  17. if ($model->outPay()) {
  18. $result['type'] = 'html';
  19. $result['html'] = $model->getOutPayResult();
  20. return $this->outJson(1, $result, 'OK');
  21. } else {
  22. return $this->outJson(0, [], $model->getErrors());
  23. }
  24. }
  25. /**
  26. * 异步回调
  27. * @return \yii\web\Response
  28. */
  29. public function actionNotify()
  30. {
  31. $model = new PayForm();
  32. $data = Yii::$app->getRequest()->post();
  33. if ($model->handleNotify($data)) {
  34. return $this->outJson(1, $model->getOutNotifyResult());
  35. } else {
  36. return $this->outJson(0, $model->getOutNotifyResult());
  37. }
  38. }
  39. /**
  40. * 同步回调
  41. * @return \yii\web\Response
  42. */
  43. public function actionReturn()
  44. {
  45. $model = new PayForm();
  46. $data = Yii::$app->getRequest()->post();
  47. if ($model->handleReturn($data)) {
  48. return $this->outJson(1, $model->getOutReturnResult());
  49. } else {
  50. return $this->outJson(0, $model->getOutReturnResult());
  51. }
  52. }
  53. /**
  54. * 退款
  55. * @return \yii\web\Response
  56. */
  57. public function actionRefund()
  58. {
  59. $payType = 3;
  60. $handler = BasePayHandler::getPayHandlerByPayType($payType);
  61. $res = $handler->outRefund();
  62. return $this->outJson(1, $res);
  63. }
  64. }