1 | <?php |
||
32 | class Payment |
||
33 | { |
||
34 | /** |
||
35 | * Scheme base path. |
||
36 | */ |
||
37 | const SCHEME_PATH = 'weixin://wxpay/bizpayurl'; |
||
38 | |||
39 | /** |
||
40 | * @var API |
||
41 | */ |
||
42 | protected $api; |
||
43 | |||
44 | /** |
||
45 | * Merchant instance. |
||
46 | * |
||
47 | * @var \EasyWeChat\Payment\Merchant |
||
48 | */ |
||
49 | protected $merchant; |
||
50 | |||
51 | /** |
||
52 | * Constructor. |
||
53 | * |
||
54 | * @param Merchant $merchant |
||
55 | */ |
||
56 | 9 | public function __construct(Merchant $merchant) |
|
60 | |||
61 | /** |
||
62 | * Build payment scheme for product. |
||
63 | * |
||
64 | * @param string $productId |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | 1 | public function scheme($productId) |
|
82 | |||
83 | /** |
||
84 | * Handle payment notify. |
||
85 | * |
||
86 | * @param callable $callback |
||
87 | * |
||
88 | * @return Response |
||
89 | */ |
||
90 | 2 | public function handleNotify(callable $callback) |
|
117 | |||
118 | /** |
||
119 | * [WeixinJSBridge] Generate js config for payment. |
||
120 | * |
||
121 | * <pre> |
||
122 | * WeixinJSBridge.invoke( |
||
123 | * 'getBrandWCPayRequest', |
||
124 | * ... |
||
125 | * ); |
||
126 | * </pre> |
||
127 | * |
||
128 | * @param string $prepayId |
||
129 | * @param bool $json |
||
130 | * |
||
131 | * @return string|array |
||
132 | */ |
||
133 | 2 | public function configForPayment($prepayId, $json = true) |
|
134 | { |
||
135 | $params = [ |
||
136 | 2 | 'appId' => $this->merchant->app_id, |
|
137 | 2 | 'timeStamp' => strval(time()), |
|
138 | 2 | 'nonceStr' => uniqid(), |
|
139 | 2 | 'package' => "prepay_id=$prepayId", |
|
140 | 2 | 'signType' => 'MD5', |
|
141 | 2 | ]; |
|
142 | |||
143 | 2 | $params['paySign'] = generate_sign($params, $this->merchant->key, 'md5'); |
|
144 | |||
145 | 2 | return $json ? json_encode($params) : $params; |
|
146 | } |
||
147 | |||
148 | /** |
||
149 | * [JSSDK] Generate js config for payment. |
||
150 | * |
||
151 | * <pre> |
||
152 | * wx.chooseWXPay({...}); |
||
153 | * </pre> |
||
154 | * |
||
155 | * @param string $prepayId |
||
156 | * @param bool $json |
||
|
|||
157 | * |
||
158 | * @return array|string |
||
159 | */ |
||
160 | 1 | public function configForJSSDKPayment($prepayId) |
|
161 | { |
||
162 | 1 | $config = $this->configForPayment($prepayId, false); |
|
163 | |||
164 | 1 | $config['timestamp'] = $config['timeStamp']; |
|
165 | 1 | unset($config['timeStamp']); |
|
166 | |||
167 | 1 | return $config; |
|
168 | } |
||
169 | |||
170 | /** |
||
171 | * Generate app payment parameters. |
||
172 | * |
||
173 | * @param string $prepayId |
||
174 | * |
||
175 | * @return array |
||
176 | */ |
||
177 | 1 | public function configForAppPayment($prepayId) |
|
192 | |||
193 | /** |
||
194 | * Generate js config for share user address. |
||
195 | * |
||
196 | * @param string|\Overtrue\Socialite\AccessTokenInterface $accessToken |
||
197 | * @param bool $json |
||
198 | * |
||
199 | * @return string|array |
||
200 | */ |
||
201 | 1 | public function configForShareAddress($accessToken, $json = true) |
|
202 | { |
||
203 | 1 | if ($accessToken instanceof AccessTokenInterface) { |
|
204 | 1 | $accessToken = $accessToken->getToken(); |
|
205 | 1 | } |
|
206 | |||
207 | $params = [ |
||
208 | 1 | 'appId' => $this->merchant->app_id, |
|
209 | 1 | 'scope' => 'jsapi_address', |
|
210 | 1 | 'timeStamp' => strval(time()), |
|
211 | 1 | 'nonceStr' => uniqid(), |
|
212 | 1 | 'signType' => 'SHA1', |
|
213 | 1 | ]; |
|
214 | |||
215 | $signParams = [ |
||
216 | 1 | 'appid' => $params['appId'], |
|
217 | 1 | 'url' => UrlHelper::current(), |
|
218 | 1 | 'timestamp' => $params['timeStamp'], |
|
219 | 1 | 'noncestr' => $params['nonceStr'], |
|
220 | 1 | 'accesstoken' => strval($accessToken), |
|
221 | 1 | ]; |
|
222 | |||
223 | 1 | ksort($signParams); |
|
224 | |||
225 | 1 | $params['addrSign'] = sha1(urldecode(http_build_query($signParams))); |
|
226 | |||
227 | 1 | return $json ? json_encode($params) : $params; |
|
228 | } |
||
229 | |||
230 | /** |
||
231 | * Merchant setter. |
||
232 | * |
||
233 | * @param Merchant $merchant |
||
234 | */ |
||
235 | 1 | public function setMerchant(Merchant $merchant) |
|
236 | { |
||
237 | 1 | $this->merchant = $merchant; |
|
238 | 1 | } |
|
239 | |||
240 | /** |
||
241 | * Merchant getter. |
||
242 | * |
||
243 | * @return Merchant |
||
244 | */ |
||
245 | 1 | public function getMerchant() |
|
246 | { |
||
247 | 1 | return $this->merchant; |
|
248 | } |
||
249 | |||
250 | /** |
||
251 | * Return Notify instance. |
||
252 | * |
||
253 | * @return \EasyWeChat\Payment\Notify |
||
254 | */ |
||
255 | 1 | public function getNotify() |
|
256 | { |
||
257 | 1 | return new Notify($this->merchant); |
|
258 | } |
||
259 | |||
260 | /** |
||
261 | * API setter. |
||
262 | * |
||
263 | * @param API $api |
||
264 | */ |
||
265 | 1 | public function setAPI(API $api) |
|
266 | { |
||
267 | 1 | $this->api = $api; |
|
268 | 1 | } |
|
269 | |||
270 | /** |
||
271 | * Return API instance. |
||
272 | * |
||
273 | * @return API |
||
274 | */ |
||
275 | 1 | public function getAPI() |
|
276 | { |
||
277 | 1 | return $this->api ?: $this->api = new API($this->getMerchant()); |
|
278 | } |
||
279 | |||
280 | /** |
||
281 | * Magic call. |
||
282 | * |
||
283 | * @param string $method |
||
284 | * @param array $args |
||
285 | * |
||
286 | * @return mixed |
||
287 | * |
||
288 | * @codeCoverageIgnore |
||
289 | */ |
||
290 | public function __call($method, $args) |
||
296 | } |
||
297 |
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.