You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: travis
  5. * Date: 2019/12/12
  6. * Time: 15:59
  7. */
  8. namespace api\controllers;
  9. use api\logic\WxPaymentLogic;
  10. use yii\filters\auth\HttpBearerAuth;
  11. use yii\helpers\ArrayHelper;
  12. use yii\web\Response;
  13. use Yii;
  14. use yii\web\BadRequestHttpException;
  15. class WxPaymentController extends CommonController
  16. {
  17. public $modelClass = 'backend\modules\shop\models\ars\Order';
  18. public $className = 'api\logic\WxPaymentLogic';
  19. public function behaviors()
  20. {
  21. return ArrayHelper::merge(parent::behaviors(), [
  22. 'authenticatior' => [
  23. 'class' => HttpBearerAuth::className(),
  24. 'except' => ['notify'],
  25. ]
  26. ]);
  27. }
  28. public function actions()
  29. {
  30. $action = parent::actions();
  31. unset($action['index']);
  32. unset($action['update']);
  33. unset($action['view']);
  34. unset($action['delete']);
  35. $action['options'] = [
  36. 'class' => 'yii\rest\OptionsAction',
  37. 'collectionOptions' => ['PUT', 'GET', 'OPTIONS']
  38. ];
  39. return $action;
  40. }
  41. public function actionWeb()
  42. {
  43. return $this->object->wxPayment(WxPaymentLogic::PAY_TYPE_WEB);
  44. }
  45. public function actionMiniProgram()
  46. {
  47. return $this->object->wxPayment(WxPaymentLogic::PAY_TYPE_MINI_PROGRAM);
  48. }
  49. /**
  50. * @return array|bool
  51. * @throws BadRequestHttpException
  52. * @throws \yii\base\InvalidConfigException
  53. * @throws \yii\httpclient\Exception
  54. * 异步回调
  55. */
  56. public function actionNotify()
  57. {
  58. Yii::$app->response->format = Response::FORMAT_XML;
  59. return $this->object->notify();
  60. }
  61. /**
  62. * @return bool
  63. * @throws BadRequestHttpException
  64. * @throws \yii\db\Exception
  65. * @throws \yii\web\NotFoundHttpException
  66. * 申请退款
  67. */
  68. public function actionApplyRefund()
  69. {
  70. return $this->object->applyRefund();
  71. }
  72. }