File tree Expand file tree Collapse file tree 5 files changed +33
-3
lines changed Expand file tree Collapse file tree 5 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
3
Tất cả lịch sử tiến trình phát triển thư viện
4
+
5
+ ## 1.0.1
6
+
7
+ - Hổ trợ thiết lập kiểu mã hóa khi tạo chữ ký dự liệu thông qua parameter ` vnp_SecureHashType ` .
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ public function getData(): array
53
53
54
54
$ parameters = $ this ->getParameters ();
55
55
$ parameters ['vnp_SecureHash ' ] = $ this ->generateSignature (
56
- $ parameters ['vnp_SecureHashType ' ] = ' md5 '
56
+ $ parameters ['vnp_SecureHashType ' ] = $ this -> getSecureHashType () ?? ' sha256 '
57
57
);
58
58
59
59
unset($ parameters ['vnp_HashSecret ' ], $ parameters ['testMode ' ]);
@@ -189,4 +189,28 @@ public function setClientIp($value)
189
189
{
190
190
return $ this ->setParameter ('vnp_IpAddr ' , $ value );
191
191
}
192
+
193
+ /**
194
+ * Trả về phương thức mã hóa dùng để tạo chữ ký dự liệu (md5, sha256).
195
+ *
196
+ * @return null|string
197
+ * @since 1.0.1
198
+ */
199
+ public function getSecureHashType (): ?string
200
+ {
201
+ return $ this ->getParameter ('vnp_SecureHashType ' );
202
+ }
203
+
204
+ /**
205
+ * Thiết lập phương thức mã hóa dùng để tạo chữ ký dự liệu.
206
+ *
207
+ * @param null|string $secureHashType
208
+ *
209
+ * @return $this
210
+ * @since 1.0.1
211
+ */
212
+ public function setSecureHashType (?string $ secureHashType )
213
+ {
214
+ return $ this ->setParameter ('vnp_SecureHashType ' , $ secureHashType );
215
+ }
192
216
}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ trait RequestSignature
21
21
* @param string $hashType
22
22
* @return string
23
23
*/
24
- protected function generateSignature ($ hashType = 'md5 ' ): string
24
+ protected function generateSignature (string $ hashType = 'sha256 ' ): string
25
25
{
26
26
$ data = [];
27
27
$ signature = new Signature (
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ class Signature
36
36
* @param string $hashType
37
37
* @throws InvalidArgumentException
38
38
*/
39
- public function __construct (string $ hashSecret , string $ hashType = 'md5 ' )
39
+ public function __construct (string $ hashSecret , string $ hashType = 'sha256 ' )
40
40
{
41
41
if (! $ this ->isSupportHashType ($ hashType )) {
42
42
throw new InvalidArgumentException (sprintf ('Hash type: `%s` is not supported by VNPay ' , $ hashType ));
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ public function testGetData()
44
44
$ request ->setVnpReturnUrl (10 );
45
45
$ request ->setVnpTxnRef (11 );
46
46
$ request ->setVnpVersion (12 );
47
+ $ request ->setSecureHashType ('sha256 ' );
47
48
$ request ->setTestMode (true );
48
49
$ data = $ request ->getData ();
49
50
$ this ->assertEquals (14 , count ($ data ));
@@ -70,6 +71,7 @@ public function testGetData()
70
71
$ this ->assertEquals (10 , $ data ['vnp_ReturnUrl ' ]);
71
72
$ this ->assertEquals (11 , $ data ['vnp_TxnRef ' ]);
72
73
$ this ->assertEquals (12 , $ data ['vnp_Version ' ]);
74
+ $ this ->assertEquals ('sha256 ' , $ data ['vnp_SecureHashType ' ]);
73
75
$ this ->assertTrue (isset ($ data ['vnp_SecureHash ' ]));
74
76
$ this ->assertFalse (isset ($ data ['vnp_HashSecret ' ]));
75
77
}
You can’t perform that action at this time.
0 commit comments