Abstract.php
4.83 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Created by PhpStorm.
* User: ziy
* Date: 14-7-8
* Time: 下午6:09
*/
abstract class YOHOPay_Package_Abstract implements YOHOPay_Package_Interface
{
/**
* 用于存储通知回调的基础url
* @var string
*/
public $baseNoticeUrl = "http://www.yhfair.com/pay/";
/**
* 测试的回调地址
* @var string
*/
public $testBaseNoticeUrl = "http://www.yohomarket.cn/pay/";
/**
* 支付配置
* @var YOHOPay_Package_payConfig
*/
protected $payConfig;
/**
* 通知
* @param array $notifyData
* @return string
*/
function notify(array $notifyData)
{
return '';
}
/**
* 获取参数
* @return $this
*/
function getParameters()
{
/* GET */
foreach ($_GET as $k => $v) {
$this->setParameter($k, $v);
}
/* POST */
foreach ($_POST as $k => $v) {
$this->setParameter($k, $v);
}
return $this;
}
/**
* 设置参数值
* @param $parameter
* @param $parameterValue
*/
function setParameter($parameter, $parameterValue)
{
$this->parameters[$parameter] = $parameterValue;
}
/**
* 实现多种字符编码方式
* @param $input 需要编码的字符串
* @param $_output_charset 输出的编码格式
* @param $_input_charset 输入的编码格式
* return 编码后的字符串
*/
function charsetEncode($input, $_output_charset, $_input_charset)
{
if (!isset($_output_charset)) $_output_charset = $_input_charset;
if ($_input_charset == $_output_charset || $input == null) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input, $_output_charset, $_input_charset);
} elseif (function_exists("iconv")) {
$output = iconv($_input_charset, $_output_charset, $input);
} else die("sorry, you have no libs support for charset change.");
return $output;
}
/**
* 实现多种字符解码方式
* @param $input 需要解码的字符串
* @param $_output_charset 输出的解码格式
* @param $_input_charset 输入的解码格式
* return 解码后的字符串
*/
function charsetDecode($input, $_input_charset, $_output_charset)
{
if (!isset($_input_charset)) $_input_charset = $_input_charset;
if ($_input_charset == $_output_charset || $input == null) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input, $_output_charset, $_input_charset);
} elseif (function_exists("iconv")) {
$output = iconv($_input_charset, $_output_charset, $input);
} else die("sorry, you have no libs support for charset changes.");
return $output;
}
/**
* 排序参数
* @param array $package
* @return array
*/
function packageSort(array $package)
{
ksort($package);
reset($package);
return $package;
}
/**
* 订单通知
* @param YOHOPay_Package_Response $responseData
*/
function orderNotify(YOHOPay_Package_Response $responseData)
{
if (empty($responseData->orderCode)) {
return false;
}
$checkStatus = YHMOrders_Models_Status_Client::getRepeatStatusByOrderCode($responseData->orderCode, 300);
if (empty($checkStatus)) {
YHMOrders_Models_Orders_Client::updateOrderPayInfo($responseData->orderCode, $responseData->paymentID, $responseData->tradeCode, $responseData->buyerUser, $responseData->bankName);
YHMOrders_Models_Status_Client::setOrderstatus($responseData->orderCode, 300, 0);
YHMIm_Messages::pay($responseData->orderCode);
}
}
/**
* 订单通知
* @param YOHOPay_Package_Response $responseData
*/
function orderNotifyTodo($orderCode)
{
$checkStatus = YHMOrders_Models_Status_Client::getRepeatStatusByOrderCode($orderCode, 300);
if (empty($checkStatus)) {
YHMOrders_Models_Orders_Client::updateOrderPayInfo($orderCode, 1, '', '');
YHMOrders_Models_Status_Client::setOrderstatus($orderCode, 300, 0);
}
}
function makeResponseParameters(array $parametersData)
{
$response = new YOHOPay_Package_Response();
$response->orderCode = $parametersData['out_trade_no'];
$response->totalFee = $parametersData['total_fee'];
$response->buyerUser = $parametersData['buyer_email'];
$response->paymentID = 1;
$response->paymentTime = empty($parametersData['gmt_payment']) ? 0 : strtotime($parametersData['gmt_payment']);
$response->tradeCode = $parametersData['trade_no'];
return $response;
}
}