Notice.php 10.4 KB
<?php

use Action\WebAction;
use Shopping\PayModel;
use WebPlugin\Pay\PayFactory;
use WebPlugin\Pay\Rspparams;
use WebPlugin\Pay\weixin\PayNotifyCallBack;

/**
 * 支付Notice
 */
class NoticeController extends WebAction
{
    /**
     * 支付宝后台服务器返回,主要是用于补单
     */
    public function alipaynoticeAction()
    {
        $payment = PayModel::getPaymentById(2);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $this->payResultProc($res, 2);
            echo "success";
        }
        exit();
    }

    /**
     * 支付宝浏览器端返回
     */
    public function alipayreturnAction()
    {
        $payment = PayModel::getPaymentById(2);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_GET);
        $dealResult = $this->payResultProc($res, 2);
        $dealResult['payData'] = array('payWay' => '支付宝');
        $this->commonShowResult($dealResult);
    }

    /**
     * 支付宝二维码支付
     */
    public function alibarcodenoticeAction()
    {
        $payment = PayModel::getPaymentById(17);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $this->payResultProc($res, 17);
            echo "success";
        }
        exit();
    }

    /**
     * 支付宝二维码支付浏览器端返回
     */
    public function alibarcodereturnAction()
    {
        $payment = PayModel::getPaymentById(17);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_GET);
        $dealResult = $this->payResultProc($res, 17);
        $dealResult['payData'] = array('payWay' => '支付宝');
        $this->commonShowResult($dealResult);
    }

    /**
     * 通联支付
     */
    public function allinpaynoticeAction()
    {
        $payment = PayModel::getPaymentById(16);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST);
        if ($res->payResult != -1) {
            $this->payResultProc($res, 16);
            echo "success";
        }
        exit();
    }

    /**
     * 通联支付返回
     */
    public function allinpayreturnAction()
    {
        $payment = PayModel::getPaymentById(16);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST);
        $dealResult = $this->payResultProc($res, 16);
        $dealResult['payData'] = array('payWay' => '通联支付');
        $this->commonShowResult($dealResult);
    }

    /**
     * 支付宝快捷网关浏览器回复
     */
    public function aliexpressgatewayreturnAction()
    {
        $payment = PayModel::getPaymentById(13);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_GET);
        $dealResult = $this->payResultProc($res, 13);
        $dealResult['payData'] = array('payWay' => '支付宝');
        $this->commonShowResult($dealResult);
    }

    /**
     * 支付宝快捷网关自动对账回复
     */
    public function aliexpressgatewaynoticeAction()
    {
        $payment = PayModel::getPaymentById(13);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $this->payResultProc($res, 13);
            echo "success";
        }
        exit();
    }

    /*
     * 支付宝支付回调
     */
    public function alibanknoticeAction()
    {
        $payment = PayModel::getPaymentById(12);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST);

        if ($res->payResult != -1) {
            $this->payResultProc($res, 12);
            echo "success";
        }

        exit();
    }

    public function alibankreturnAction()
    {
        $payment = PayModel::getPaymentById(12);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_GET);
        $dealResult = $this->payResultProc($res, 12);
        $dealResult['payData'] = array('payWay' => '银行卡');
        $this->commonShowResult($dealResult);
    }

    /**
     * 网银信用卡
     */
    public function chinabankAction()
    {
        $payment = PayModel::getPaymentById(4);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST);
        $dealResult = $this->payResultProc($res, 4);
        $dealResult['payData'] = array('payWay' => '网银在线');
        $this->commonShowResult($dealResult);
    }

    /**
     * 网银在线自动接收
     */
    public function chinabankautorevAction()
    {
        $payment = PayModel::getPaymentById(4);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST);
        if ($res->payResult != -1) {
            $this->payResultProc($res, 4);
            echo "ok";
        } else {
            echo 'error';
        }
        exit();
    }

    /**
     * 腾讯财付通的回应
     */
    public function tenpayAction()
    {
        $payment = PayModel::getPaymentById(1);
        $payService = PayFactory::factory($payment);
        $rspParams = $payService->parseResponse($_GET); //财付通是以get方式回复的。
        $this->payResultProc($rspParams, 1);
    }

    /**
     * 盛付通浏览器返回
     * Enter description here ...
     */
    public function shengpayreturnAction()
    {
//        	$strData = '{"Amount":"0.01","PayAmount":"0.01","OrderNo":"1070021504","serialno":"B000110726001873577","Status":"01","MerchantNo":"408258","PayChannel":"04","Discount":"1","SignType":"2","PayTime":"20110726162126","CurrencyType":"RMB","ProductNo":"","ProductDesc":"","Remark1":"","Remark2":"","ExInfo":"bankid:SDTBNK","Branch":"SHB","MAC":"8ABC0FBAA3EE3202F16A915B42571B58"}';
        //	$pars = json_decode($strData, true);
        $payment = PayModel::getPaymentById(11);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST);
        $dealResult = $this->payResultProc($res, 11);
        $dealResult['payData'] = array('payWay' => '盛付通');
        $this->commonShowResult($dealResult);
    }

    /**
     * 盛付通服务器端返回
     */
    public function shengpaynoticeAction()
    {
        $payment = PayModel::getPaymentById(11);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_POST);
        if ($res->payResult != -1) {
            $this->payResultProc($res, 11);
            echo "OK";
        }
        exit();
    }

    /**
     * jsonPcallback响应订单支付状态
     */
    public function wechatcallbackAction()
    {
        $callback = $this->get('callback');
        $orderCode = $this->get('ordercode');

        $uid = $this->getUid(true);
        $response = PayModel::checkWechatPayStatus($uid, $orderCode);

        $this->helpJsonCallbackResult($callback, $response['code'], $response['message']);
    }

    /**
     * 微信扫码支付结果商户通知地址
     */
    public function wechatqrcodenotifyAction()
    {
        $notify = new PayNotifyCallBack();
        $notify->handle(false);
    }

    /**
     * 微信扫码支付返回
     */
    public function wechatqrcodereturnAction()
    {
        $dealResult = array(
            'code' => 500,
            'message' => '支付失败'
        );

        do {
            $orderCode = isset($_GET['order_code']) ? $_GET['order_code'] : 0;
            if (empty($orderCode)) {
                break;
            }

            $payment = PayModel::getPaymentById(21);
            $payService = PayFactory::factory($payment);
            $res = $payService->parseResponse(array('orderCode' => $orderCode));
            $dealResult = $this->payResultProc($res, 21);
            $dealResult['payData'] = array('payWay' => '微信扫码支付');
        } while (false);

        $this->commonShowResult($dealResult);
    }

    /**
     * 银联web支付返回
     */
    public function unionpaywebreturnAction()
    {
        $payment = PayModel::getPaymentById(25);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_REQUEST);
        $dealResult = $this->payResultProc($res, 25);
        $dealResult['payData'] = array('payWay' => '银联在线支付');
        $this->commonShowResult($dealResult);
    }

    /**
     * 银联支付成功后台回调响应
     */
    public function unionpaywebnoticeAction()
    {
        $payment = PayModel::getPaymentById(25);
        $payService = PayFactory::factory($payment);
        $res = $payService->parseResponse($_GET);
        if ($res->payResult != -1) {
            $this->payResultProc($res, 25);
            echo "OK";
        }
        exit();
    }


    /**
     * 通用显示结果的方法
     * @param array $dealResult
     */
    private function commonShowResult($dealResult)
    {
        $code = $dealResult['code'];
        $view = 'wechatqrcodereturn';
        $data = array(
            'headerData' => true,
            'payData' => $dealResult['payData']
        );

        if ($code == 200) {
            $view = 'index';
            $data = array('payNotice' => $dealResult['data']);
        }

        //头部导航
        $this->setSimpleHeader();
        $this->_view->display($view, $data);
    }

    /**
     * 处理支付返回的数据
     *
     * @param Rspparams $payResult 支付返回的结果
     * @param $payment 支付方式id
     * @return array
     */
    private function payResultProc($payResult, $payment)
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();

        $result = array(
            'code' => 500,
            'message' => '支付失败'
        );

        if ($payResult->payResult == 200) {
            //支付成功
            $result = PayModel::procOrderData($uid, $payResult, $payment);
        }

        return $result;
    }
}