WxPayResults.php
2.1 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
95
96
97
98
99
100
101
102
<?php
/**
* Created by PhpStorm.
* User: DELL
* Date: 2015/12/23
* Time: 17:51
*/
namespace WebPlugin\Pay\weixin\lib;
use WebPlugin\PhpLog;
/**
*
* 接口调用结果类
* @author widyhu
*
*/
class WxPayResults extends WxPayDataBase
{
// 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志
const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
// 日志等级,2表示记录信息等级的日志
const LOG_LEVEL = 2;
/**
*
* 检测签名
*/
public function CheckSign()
{
//fix异常
if (!$this->IsSignSet()) {
throw new WxPayException("签名错误!");
}
$sign = $this->MakeSign();
if ($this->GetSign() == $sign) {
return true;
}
throw new WxPayException("签名错误!");
}
/**
*
* 使用数组初始化
* @param array $array
*/
public function FromArray($array)
{
$this->values = $array;
}
/**
*
* 使用数组初始化对象
* @param array $array
* @param 是否检测签名 $noCheckSign
*/
public static function InitFromArray($array, $noCheckSign = false)
{
$obj = new self();
$obj->FromArray($array);
if ($noCheckSign == false) {
$obj->CheckSign();
}
return $obj;
}
/**
*
* 设置参数
* @param string $key
* @param string $value
*/
public function SetData($key, $value)
{
$this->values[$key] = $value;
}
/**
* 将xml转为array
* @param string $xml
* @throws WxPayException
*/
public static function Init($xml)
{
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('begin WxPayResults::notify');
$obj = new self();
$obj->FromXml($xml);
//fix bug 2015-06-29
if ($obj->values['return_code'] != 'SUCCESS') {
return $obj->GetValues();
}
$obj->CheckSign();
return $obj->GetValues();
}
}