4
4
5
5
namespace Plugin \Douyin \V1 \Pay ;
6
6
7
+ use Yansongda \Artful \Exception \InvalidConfigException ;
7
8
use Yansongda \Artful \Rocket ;
9
+ use Yansongda \Pay \Exception \Exception ;
10
+ use Yansongda \Pay \Exception \InvalidSignException ;
8
11
use Yansongda \Pay \Plugin \Douyin \V1 \Pay \CallbackPlugin ;
9
12
use Yansongda \Pay \Tests \TestCase ;
10
13
@@ -19,7 +22,7 @@ protected function setUp(): void
19
22
$ this ->plugin = new CallbackPlugin ();
20
23
}
21
24
22
- public function testNotifyCallbackIncludePlus ()
25
+ public function testCallback ()
23
26
{
24
27
$ post = '{"msg":"{\"appid\":\"tt226e54d3bd581bf801\",\"cp_orderno\":\"202408041111312119\",\"cp_extra\":\"\",\"way\":\"2\",\"channel_no\":\"\",\"channel_gateway_no\":\"\",\"payment_order_no\":\"\",\"out_channel_order_no\":\"\",\"total_amount\":1,\"status\":\"SUCCESS\",\"seller_uid\":\"73744242495132490630\",\"extra\":\"\",\"item_id\":\"\",\"paid_at\":1722769986,\"message\":\"\",\"order_id\":\"7398108028895054107\"}","msg_signature":"840bdf067c1d6056becfe88735c8ebb7e1ab809c","nonce":"5280","timestamp":"1722769986","type":"payment"} ' ;
25
28
@@ -31,4 +34,46 @@ public function testNotifyCallbackIncludePlus()
31
34
self ::assertNotEmpty ($ result ->getPayload ()->all ());
32
35
self ::assertNotEmpty ($ result ->getDestination ()->all ());
33
36
}
37
+
38
+ public function testVerifyDouyinSignEmpty ()
39
+ {
40
+ $ post = '{"msg":"{\"appid\":\"tt226e54d3bd581bf801\",\"cp_orderno\":\"202408041111312119\",\"cp_extra\":\"\",\"way\":\"2\",\"channel_no\":\"\",\"channel_gateway_no\":\"\",\"payment_order_no\":\"\",\"out_channel_order_no\":\"\",\"total_amount\":1,\"status\":\"SUCCESS\",\"seller_uid\":\"73744242495132490630\",\"extra\":\"\",\"item_id\":\"\",\"paid_at\":1722769986,\"message\":\"\",\"order_id\":\"7398108028895054107\"}","msg_signature":"","nonce":"5280","timestamp":"1722769986","type":"payment"} ' ;
41
+
42
+ $ rocket = new Rocket ();
43
+ $ rocket ->setParams (json_decode ($ post , true ));
44
+
45
+ self ::expectException (InvalidSignException::class);
46
+ self ::expectExceptionCode (Exception::SIGN_EMPTY );
47
+
48
+ $ this ->plugin ->assembly ($ rocket , function ($ rocket ) {return $ rocket ;});
49
+ }
50
+
51
+ public function testVerifyDouyinSignError ()
52
+ {
53
+ $ post = '{"msg":"{\"appid\":\"tt226e54d3bd581bf801\",\"cp_orderno\":\"202408041111312119\",\"cp_extra\":\"\",\"way\":\"2\",\"channel_no\":\"\",\"channel_gateway_no\":\"\",\"payment_order_no\":\"\",\"out_channel_order_no\":\"\",\"total_amount\":1,\"status\":\"SUCCESS\",\"seller_uid\":\"73744242495132490630\",\"extra\":\"\",\"item_id\":\"\",\"paid_at\":1722769986,\"message\":\"\",\"order_id\":\"7398108028895054107\"}","msg_signature":"foo","nonce":"5280","timestamp":"1722769986","type":"payment"} ' ;
54
+
55
+ $ rocket = new Rocket ();
56
+ $ rocket ->setParams (json_decode ($ post , true ));
57
+
58
+ self ::expectException (InvalidSignException::class);
59
+ self ::expectExceptionCode (Exception::SIGN_ERROR );
60
+
61
+ $ this ->plugin ->assembly ($ rocket , function ($ rocket ) {return $ rocket ;});
62
+ }
63
+
64
+ public function testVerifyDouyinSignConfigError ()
65
+ {
66
+ $ post = '{"msg":"{\"appid\":\"tt226e54d3bd581bf801\",\"cp_orderno\":\"202408041111312119\",\"cp_extra\":\"\",\"way\":\"2\",\"channel_no\":\"\",\"channel_gateway_no\":\"\",\"payment_order_no\":\"\",\"out_channel_order_no\":\"\",\"total_amount\":1,\"status\":\"SUCCESS\",\"seller_uid\":\"73744242495132490630\",\"extra\":\"\",\"item_id\":\"\",\"paid_at\":1722769986,\"message\":\"\",\"order_id\":\"7398108028895054107\"}","msg_signature":"840bdf067c1d6056becfe88735c8ebb7e1ab809c","nonce":"5280","timestamp":"1722769986","type":"payment"} ' ;
67
+
68
+ $ params = json_decode ($ post , true );
69
+ $ params ['_config ' ] = 'empty_salt ' ;
70
+
71
+ $ rocket = new Rocket ();
72
+ $ rocket ->setParams ($ params );
73
+
74
+ self ::expectException (InvalidConfigException::class);
75
+ self ::expectExceptionCode (Exception::CONFIG_DOUYIN_INVALID );
76
+
77
+ $ this ->plugin ->assembly ($ rocket , function ($ rocket ) {return $ rocket ;});
78
+ }
34
79
}
0 commit comments