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.

61 lines
1.4 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. class WxPaymentController extends CommonController
  15. {
  16. public $modelClass = 'backend\modules\shop\models\ars\Order';
  17. public $className = 'api\logic\WxPaymentLogic';
  18. public function behaviors()
  19. {
  20. return ArrayHelper::merge(parent::behaviors(), [
  21. 'authenticatior' => [
  22. 'class' => HttpBearerAuth::className(),
  23. 'except' => ['notify'],
  24. ]
  25. ]);
  26. }
  27. public function actions()
  28. {
  29. $action = parent::actions();
  30. unset($action['index']);
  31. unset($action['update']);
  32. unset($action['view']);
  33. unset($action['delete']);
  34. $action['options'] = [
  35. 'class' => 'yii\rest\OptionsAction',
  36. 'collectionOptions' => ['PUT', 'GET', 'OPTIONS']
  37. ];
  38. return $action;
  39. }
  40. public function actionWeb()
  41. {
  42. return $this->object->wxPayment(WxPaymentLogic::PAY_TYPE_WEB);
  43. }
  44. public function actionMiniProgram()
  45. {
  46. return $this->object->wxPayment(WxPaymentLogic::PAY_TYPE_MINI_PROGRAM);
  47. }
  48. public function actionNotify()
  49. {
  50. Yii::$app->response->format = Response::FORMAT_XML;
  51. return $this->object->notify();
  52. }
  53. }