| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace addons\UnionPay\api\controllers;
- use addons\UnionPay\common\service\PayService;
- use common\models\common\PaymentTrade;
- use yii\db\Exception;
- use yii\web\Controller;
- class NotifyController extends Controller
- {
- public $enableCsrfValidation = false;
- public function actionNotify()
- {
- $params = $this->request->post();
- \Yii::error('通联支付回调:' . json_encode($params));
- // if(isset($params['trxid'])){
- // $trade = PaymentTrade::findOne(['third_trade_no' => $params['trxid']]);
- // }else{
- $trade = PaymentTrade::findOne(['out_trade_no' => $params['cusorderid']]);
- // }
- if (!$trade) return true;
- if ($params['trxamt'] != bcmul($trade->pay_fee, 100, 0)) {
- throw new Exception('支付金额与订单金额不一致');
- }
- $pay_service = new PayService($trade->mall_id);
- $res = $pay_service->notify($trade,$params);
- if ($res) {
- echo 'success';
- } else {
- echo "erro";
- }
- }
- public function actionQuery()
- {
- $out_trade_no = $this->request->get('out_trade_no');
- $pay_service = new PayService();
- $pay_service->query($out_trade_no);
- }
- }
|