Service.php 2.32 KB
<?php

namespace WebPlugin\Pay\Alimobilemini;

use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Rspparams;
use WebPlugin\UdpLog;

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

    private $utils;

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


    /**
     * 处理支付宝极简支付的结果
     *
     * @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);
//         ##################################
        UdpLog::info("【{$this->logProjectPrefix}-支付宝极简支付】,function:parseResponse,参数", $arrResponse);
        $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 = "";
        } else {
            //不成功
            $rsp->payResult = -1;
        }
        UdpLog::info("【{$this->logProjectPrefix}-支付宝极简支付】,function:parseResponse,处理结果", $rsp);
        return $rsp;
    }

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

        return -1;
    }


}