1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kaylyu\Alipay\F2fpay\Notify; |
4
|
|
|
|
5
|
|
|
use Closure; |
6
|
|
|
use Exception; |
7
|
|
|
use Kaylyu\Alipay\F2fpay\Kernel\AopClient; |
8
|
|
|
use Kaylyu\Alipay\Kernel\Support\Arr; |
9
|
|
|
|
10
|
|
|
class Paid extends Handler |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* 入口 |
14
|
|
|
* @param Closure $closure |
15
|
|
|
* @author kaylv <[email protected]> |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
|
|
public function handle(Closure $closure) |
19
|
|
|
{ |
20
|
|
|
$this->strict( |
21
|
|
|
\call_user_func($closure, $this->getMessage(), [$this, 'fail']) |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
return $this->toResponse(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* 验签过程 |
29
|
|
|
* @param $message |
30
|
|
|
* @author kaylv <[email protected]> |
31
|
|
|
* @return bool |
32
|
|
|
* @throws Exception |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
public function validate($message) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
//获取当面付配置 |
37
|
|
|
$f2fpay = $this->app->getF2fpay(); |
38
|
|
|
|
39
|
|
|
//获取配置参数 |
40
|
|
|
$gatewayUrl = $f2fpay['gateway_url']; |
41
|
|
|
$appId = $f2fpay['app_id']; |
42
|
|
|
$signType = $f2fpay['sign_type']; |
43
|
|
|
$rsaPrivateKey = $f2fpay['merchant_private_key']; |
44
|
|
|
$alipayPublicKey = $f2fpay['alipay_public_key']; |
45
|
|
|
$charset = $f2fpay['charset']; |
46
|
|
|
$notifyUrl = $f2fpay['notify_url']; |
47
|
|
|
|
48
|
|
|
if (empty($appId) || trim($appId) == "") { |
49
|
|
|
throw new Exception("appid should not be NULL!"); |
50
|
|
|
} |
51
|
|
|
if (empty($rsaPrivateKey) || trim($rsaPrivateKey) == "") { |
52
|
|
|
throw new Exception("merchant_private_key should not be NULL!"); |
53
|
|
|
} |
54
|
|
|
if (empty($alipayPublicKey) || trim($alipayPublicKey) == "") { |
55
|
|
|
throw new Exception("alipay_public_key should not be NULL!"); |
56
|
|
|
} |
57
|
|
|
if (empty($charset) || trim($charset) == "") { |
58
|
|
|
throw new Exception("charset should not be NULL!"); |
59
|
|
|
} |
60
|
|
|
if (empty($notifyUrl) || trim($notifyUrl) == "") { |
61
|
|
|
throw new Exception("sign_type should not be NULL"); |
62
|
|
|
} |
63
|
|
|
if (empty($gatewayUrl) || trim($gatewayUrl) == "") { |
64
|
|
|
throw new Exception("gateway_url should not be NULL"); |
65
|
|
|
} |
66
|
|
|
if (empty($signType) || trim($signType) == "") { |
67
|
|
|
throw new Exception("sign_type should not be NULL"); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
//组装请求数据 |
71
|
|
|
$aop = new AopClient(); |
72
|
|
|
$aop->gatewayUrl = $gatewayUrl; |
73
|
|
|
$aop->appId =$appId; |
74
|
|
|
$aop->signType = $signType; |
75
|
|
|
$aop->rsaPrivateKey = $rsaPrivateKey; |
76
|
|
|
$aop->alipayrsaPublicKey = $alipayPublicKey; |
77
|
|
|
$aop->apiVersion = "1.0"; |
78
|
|
|
$aop->charset = $charset; |
|
|
|
|
79
|
|
|
$aop->format = 'json'; |
80
|
|
|
|
81
|
|
|
//验签 |
82
|
|
|
return $aop->rsaCheckV2($message, null); |
83
|
|
|
} |
84
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.