These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the overtrue/wechat. |
||
5 | * |
||
6 | * (c) overtrue <[email protected]> |
||
7 | * |
||
8 | * This source file is subject to the MIT license that is bundled |
||
9 | * with this source code in the file LICENSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * API.php. |
||
14 | * |
||
15 | * @author AC <[email protected]> |
||
16 | * @copyright 2015 overtrue <[email protected]> |
||
17 | * |
||
18 | * @link https://github.com/overtrue |
||
19 | * @link http://overtrue.me |
||
20 | */ |
||
21 | namespace EasyWeChat\Payment\MerchantPay; |
||
22 | |||
23 | use EasyWeChat\Core\AbstractAPI; |
||
24 | use EasyWeChat\Payment\Merchant; |
||
25 | use EasyWeChat\Support\Collection; |
||
26 | use EasyWeChat\Support\XML; |
||
27 | use Psr\Http\Message\ResponseInterface; |
||
28 | |||
29 | /** |
||
30 | * Class API. |
||
31 | */ |
||
32 | class API extends AbstractAPI |
||
33 | { |
||
34 | /** |
||
35 | * Merchant instance. |
||
36 | * |
||
37 | * @var Merchant |
||
38 | */ |
||
39 | protected $merchant; |
||
40 | |||
41 | // api |
||
42 | const API_SEND = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; |
||
43 | const API_QUERY = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo'; |
||
44 | |||
45 | /** |
||
46 | * API constructor. |
||
47 | * |
||
48 | * @param \EasyWeChat\Payment\Merchant $merchant |
||
49 | */ |
||
50 | public function __construct(Merchant $merchant) |
||
51 | { |
||
52 | $this->merchant = $merchant; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Query MerchantPay. |
||
57 | * |
||
58 | * @param string $mchBillNo |
||
59 | * |
||
60 | * @return \EasyWeChat\Support\Collection |
||
61 | * |
||
62 | * @notice mch_id when query, but mchid when send |
||
63 | */ |
||
64 | public function query($mchBillNo) |
||
65 | { |
||
66 | $params = [ |
||
67 | 'appid' => $this->merchant->app_id, |
||
68 | 'mch_id' => $this->merchant->merchant_id, |
||
69 | 'partner_trade_no' => $mchBillNo, |
||
70 | ]; |
||
71 | |||
72 | return $this->request(self::API_QUERY, $params); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Send MerchantPay. |
||
77 | * |
||
78 | * @param array $params |
||
79 | * @param string $type |
||
0 ignored issues
–
show
|
|||
80 | * |
||
81 | * @return \EasyWeChat\Support\Collection |
||
82 | */ |
||
83 | public function send(array $params) |
||
84 | { |
||
85 | $params['mchid'] = $this->merchant->merchant_id; |
||
86 | $params['mch_appid'] = $this->merchant->app_id; |
||
87 | |||
88 | return $this->request(self::API_SEND, $params); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Merchant setter. |
||
93 | * |
||
94 | * @param Merchant $merchant |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setMerchant(Merchant $merchant) |
||
99 | { |
||
100 | $this->merchant = $merchant; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Merchant getter. |
||
105 | * |
||
106 | * @return Merchant |
||
107 | */ |
||
108 | public function getMerchant() |
||
109 | { |
||
110 | return $this->merchant; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Make a API request. |
||
115 | * |
||
116 | * @param string $api |
||
117 | * @param array $params |
||
118 | * @param string $method |
||
119 | * |
||
120 | * @return \EasyWeChat\Support\Collection |
||
121 | */ |
||
122 | View Code Duplication | protected function request($api, array $params, $method = 'post') |
|
123 | { |
||
124 | $params['nonce_str'] = uniqid(); |
||
125 | $params['sign'] = \EasyWeChat\Payment\generate_sign($params, $this->merchant->key, 'md5'); |
||
126 | |||
127 | $options = [ |
||
128 | 'body' => XML::build($params), |
||
129 | 'cert' => $this->merchant->get('cert_path'), |
||
130 | 'ssl_key' => $this->merchant->get('key_path'), |
||
131 | ]; |
||
132 | |||
133 | return $this->parseResponse($this->getHttp()->request($api, $method, $options)); |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Parse Response XML to array. |
||
138 | * |
||
139 | * @param \Psr\Http\Message\ResponseInterface|string $response |
||
140 | * |
||
141 | * @return \EasyWeChat\Support\Collection |
||
142 | */ |
||
143 | protected function parseResponse($response) |
||
144 | { |
||
145 | if ($response instanceof ResponseInterface) { |
||
146 | $response = $response->getBody(); |
||
147 | } |
||
148 | |||
149 | return new Collection((array) XML::parse($response)); |
||
150 | } |
||
151 | } |
||
152 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.