1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nilnice\Payment\Wechat; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Nilnice\Payment\Constant; |
7
|
|
|
use Nilnice\Payment\Log; |
8
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
|
11
|
|
|
class AppPayment extends AbstractWechat |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Use app to pay for order. |
15
|
|
|
* |
16
|
|
|
* @param string $gateway |
17
|
|
|
* @param array $payload |
18
|
|
|
* |
19
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
20
|
|
|
* |
21
|
|
|
* @throws \InvalidArgumentException |
22
|
|
|
* @throws \Nilnice\Payment\Exception\GatewayException |
23
|
|
|
* @throws \Nilnice\Payment\Exception\InvalidKeyException |
24
|
|
|
* @throws \Nilnice\Payment\Exception\InvalidSignException |
25
|
|
|
* @throws \RuntimeException |
26
|
|
|
*/ |
27
|
|
|
public function toPay(string $gateway, array $payload) : Response |
28
|
|
|
{ |
29
|
|
|
$payload['trade_type'] = Constant::WX_PAY_APP_TYPE; |
30
|
|
|
$object = $this->prepare(Constant::WX_PAY_PREPARE, $payload, 'app'); |
|
|
|
|
31
|
|
|
$key = $this->config->get('key'); |
32
|
|
|
$parameter = [ |
33
|
|
|
'appid' => $payload['appid'], |
34
|
|
|
'partnerid' => $payload['mch_id'], |
35
|
|
|
'prepayid' => $object->get('prepay_id'), |
36
|
|
|
'timestamp' => (string)time(), |
37
|
|
|
'noncestr' => Str::random(), |
38
|
|
|
'package' => 'Sign=WXPay', |
39
|
|
|
]; |
40
|
|
|
$parameter['sign'] = self::generateSign($parameter, $key); |
41
|
|
|
|
42
|
|
|
Log::debug('App order:', [$gateway, $payload]); |
43
|
|
|
|
44
|
|
|
return JsonResponse::create($parameter); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.