NotifyController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace addons\UnionPay\api\controllers;
  3. use addons\UnionPay\common\service\PayService;
  4. use common\models\common\PaymentTrade;
  5. use yii\db\Exception;
  6. use yii\web\Controller;
  7. class NotifyController extends Controller
  8. {
  9. public $enableCsrfValidation = false;
  10. public function actionNotify()
  11. {
  12. $params = $this->request->post();
  13. \Yii::error('通联支付回调:' . json_encode($params));
  14. // if(isset($params['trxid'])){
  15. // $trade = PaymentTrade::findOne(['third_trade_no' => $params['trxid']]);
  16. // }else{
  17. $trade = PaymentTrade::findOne(['out_trade_no' => $params['cusorderid']]);
  18. // }
  19. if (!$trade) return true;
  20. if ($params['trxamt'] != bcmul($trade->pay_fee, 100, 0)) {
  21. throw new Exception('支付金额与订单金额不一致');
  22. }
  23. $pay_service = new PayService($trade->mall_id);
  24. $res = $pay_service->notify($trade,$params);
  25. if ($res) {
  26. echo 'success';
  27. } else {
  28. echo "erro";
  29. }
  30. }
  31. public function actionQuery()
  32. {
  33. $out_trade_no = $this->request->get('out_trade_no');
  34. $pay_service = new PayService();
  35. $pay_service->query($out_trade_no);
  36. }
  37. }