Service.php
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?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;
}
}