|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the wannanbigpig/alipay. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) wannanbigpig <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the MIT license that is bundled |
|
8
|
|
|
* with this source code in the file LICENSE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace EasyAlipay\Payment\Kernel; |
|
12
|
|
|
|
|
13
|
|
|
use EasyAlipay\Kernel\Support\Support; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class BaseClient |
|
17
|
|
|
* |
|
18
|
|
|
* @author liuml <[email protected]> |
|
19
|
|
|
* @DateTime 2019-07-24 14:25 |
|
20
|
|
|
*/ |
|
21
|
|
|
class BaseClient extends Support |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* sdkExecute. |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $endpoint |
|
27
|
|
|
* @param array $params |
|
28
|
|
|
* |
|
29
|
|
|
* @return string |
|
30
|
|
|
* |
|
31
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function sdkExecute(string $endpoint, array $params = []) |
|
34
|
|
|
{ |
|
35
|
|
|
// Get api system parameters |
|
36
|
1 |
|
$sysParams = $this->app->apiCommonConfig($endpoint); |
|
37
|
|
|
// Filter system parameters |
|
38
|
1 |
|
$sysParams = array_filter($sysParams, function ($value) { |
|
39
|
1 |
|
return !($this->checkEmpty($value)); |
|
40
|
1 |
|
}); |
|
41
|
1 |
|
$params = array_merge($sysParams, $this->json($params)); |
|
42
|
|
|
// Set the signature |
|
43
|
1 |
|
$params['sign'] = $this->generateSign($params, $sysParams['sign_type']); |
|
44
|
|
|
|
|
45
|
1 |
|
ksort($params); |
|
46
|
|
|
|
|
47
|
1 |
|
return http_build_query($params); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* pageExecute. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $endpoint |
|
54
|
|
|
* @param array $params |
|
55
|
|
|
* @param string $httpMethod |
|
56
|
|
|
* |
|
57
|
|
|
* @return string |
|
58
|
|
|
* |
|
59
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException |
|
60
|
|
|
*/ |
|
61
|
3 |
|
public function pageExecute(string $endpoint, array $params = [], string $httpMethod = "POST") |
|
62
|
|
|
{ |
|
63
|
|
|
|
|
64
|
|
|
// Get api system parameters |
|
65
|
3 |
|
$sysParams = $this->app->apiCommonConfig($endpoint); |
|
66
|
|
|
// Filter system parameters |
|
67
|
3 |
|
$sysParams = array_filter($sysParams, function ($value) { |
|
68
|
3 |
|
return !($this->checkEmpty($value)); |
|
69
|
3 |
|
}); |
|
70
|
3 |
|
$params = array_merge($sysParams, $this->json($params)); |
|
71
|
|
|
// Set the signature |
|
72
|
3 |
|
$params['sign'] = $this->generateSign($params, $sysParams['sign_type']); |
|
73
|
|
|
|
|
74
|
3 |
|
if ("GET" === strtoupper($httpMethod)) { |
|
75
|
|
|
// value urlencode |
|
76
|
|
|
$preString = $this->getSignContentUrlencode($params); |
|
77
|
|
|
// Stitching GET request string |
|
78
|
|
|
$requestUrl = $this->app->getGateway()."?".$preString; |
|
79
|
|
|
|
|
80
|
|
|
return $requestUrl; |
|
81
|
|
|
} else { |
|
82
|
|
|
// Stitching form string |
|
83
|
3 |
|
return $this->buildRequestForm($params); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* buildRequestForm. |
|
89
|
|
|
* |
|
90
|
|
|
* @param array $paraTemp |
|
91
|
|
|
* |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
3 |
|
protected function buildRequestForm(array $paraTemp) |
|
95
|
|
|
{ |
|
96
|
|
|
$sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='". |
|
97
|
3 |
|
$this->app->getGateway()."?charset=".trim($paraTemp['charset']). |
|
98
|
3 |
|
"' method='POST'>"; |
|
99
|
|
|
|
|
100
|
3 |
|
foreach ($paraTemp as $key => $val) { |
|
101
|
3 |
|
if (false === $this->checkEmpty($val)) { |
|
102
|
3 |
|
$val = str_replace("'", "'", $val); |
|
103
|
3 |
|
$sHtml .= "<input type='hidden' name='".$key."' value='".$val."'/>"; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
// Submit button control please do not include the name attribute |
|
108
|
3 |
|
$sHtml = $sHtml."<input type='submit' value='ok' style='display:none;''></form>"; |
|
109
|
|
|
|
|
110
|
3 |
|
$sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>"; |
|
111
|
|
|
|
|
112
|
3 |
|
return $sHtml; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|