Service.php 2.49 KB
<?php

namespace WebPlugin\Pay\Alimobilemini;

use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;

/**
 * 手机支付返回
 * @author tongds
 *
 */
class Service extends PayAbstract
{
    public $config;
    private $log;

    private $utils;

    public function __construct(array $paymentParams)
    {
        $this->logProjectPrefix = 'alimobilemini';
        $this->utils = new Utils();
        $this->config = new Config();

        $this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
    }


    /**
     * 处理支付宝极简支付的结果
     *
     * @param array $arrResponse
     * @return Rspparams
     */
    public function parseResponse(array $arrResponse)
    {
        $rsp = new Rspparams();
//         ksort($arrResponse);
//         ##组织代签名字符串#################
//         $sign=$arrResponse['sign'];
//         foreach($arrResponse as $a =>$v)
//         {
//         	if(in_array($a,array('sign','sign_type')) || $v=="") continue;
//         	$data[]=$a.'='.$v;
//         }

//         $datastr=implode("&", $data);
//         ##################################

        $isVerify = $this->utils->getSignVeryfy($arrResponse);
        if ($isVerify) {
            //验证成功
            $rsp->bankName = "";
            $rsp->orderCode = $arrResponse['out_trade_no'];
            $rsp->payResult = $this->convertResult($arrResponse['trade_status']);
            $rsp->payTime = $arrResponse["gmt_create"];
            $rsp->totalFee = $arrResponse["total_fee"];
            $rsp->resultMsg = $arrResponse["trade_no"];
            //添加支付订单号和交易号
            $rsp->payOrderCode = $arrResponse['out_trade_no'];
            $rsp->tradeNo = $arrResponse['trade_no'];
            $rsp->bankBillNo = "";

            $this->log->LogInfo(var_export($arrResponse, true));
            $this->log->LogInfo('======alimobilemini成功===');
        } else {
            //不成功
            $rsp->payResult = -1;
            $this->log->LogInfo(var_export($arrResponse, true));
            $this->log->LogInfo('======alimobilemini失败===订单号----->' . $arrResponse['out_trade_no']);
        }

        return $rsp;
    }

    /**
     * 转换结果
     *
     * @param string $resultCode 返回码
     * @return int
     */
    protected function convertResult($resultCode)
    {
        if ($resultCode == "TRADE_SUCCESS" || $resultCode == "TRADE_FINISHED") {
            return 200;
        }

        return -1;
    }


}