2
2
3
3
require __DIR__ . '/vendor/autoload.php ' ;
4
4
use ExinOne \MixinSDK \Traits \MixinSDKTrait ;
5
+ use ExinOne \MixinSDK \MixinSDK ;
5
6
use Ramsey \Uuid \Uuid ;
6
7
use Ratchet \RFC6455 \Messaging \Frame ;
7
8
@@ -35,9 +36,7 @@ public function __construct()
35
36
print_r ($ jsMsg );
36
37
if ($ jsMsg ->action === 'CREATE_MESSAGE ' and property_exists ($ jsMsg ,'data ' )) {
37
38
echo "\nNeed reply server a receipt! \n" ;
38
- $ IncomingMsg = ["message_id " => $ jsMsg ->data ->message_id , "status " => "READ " ];
39
- $ RspMsg = ["id " => Uuid::uuid4 ()->toString (), "action " => "ACKNOWLEDGE_MESSAGE_RECEIPT " ,
40
- "params " => $ IncomingMsg ];
39
+ $ RspMsg = generateReceipt ($ jsMsg ->data ->message_id );
41
40
$ msg = new Frame (gzencode (json_encode ($ RspMsg )),true ,Frame::OP_BINARY );
42
41
$ conn ->send ($ msg );
43
42
@@ -62,8 +61,22 @@ public function __construct()
62
61
$ msg = new Frame (gzencode (json_encode ($ msgData )),true ,Frame::OP_BINARY );
63
62
$ conn ->send ($ msg );
64
63
}//end of pay2
65
- }
66
- }
64
+ if ($ isCmd === '3 ' ) {
65
+ transfer ();
66
+ }
67
+ } //end of PLAIN_TEXT
68
+ if ($ jsMsg ->data ->category === 'SYSTEM_ACCOUNT_SNAPSHOT ' ) {
69
+ // refundInstant
70
+ echo "user id: " .$ jsMsg ->data ->user_id ;
71
+ $ dtPay = json_decode (base64_decode ($ jsMsg ->data ->data ));
72
+ print_r ($ dtPay );
73
+ if ($ dtPay ->amount > 0 ) {
74
+ echo "paid! " .$ dtPay ->asset_id ;
75
+ refundInstant ($ dtPay ->asset_id ,$ dtPay ->amount ,$ jsMsg ->data ->user_id );
76
+ }
77
+ } //end of SYSTEM_ACCOUNT_SNAPSHOT
78
+ } //end of CREATE_MESSAGE
79
+
67
80
});
68
81
69
82
$ conn ->on ('close ' , function ($ code = null , $ reason = null ) {
@@ -172,3 +185,23 @@ function sendAppCard($jsMsg):Array
172
185
];
173
186
return $ msgPayButton ;
174
187
}
188
+
189
+ function transfer () {
190
+ $ mixinSdk = new MixinSDK (require './config.php ' );
191
+ print_r ($ mixinSdk ->getConfig ());
192
+ }
193
+
194
+ function generateReceipt ($ msgID ):Array {
195
+ $ IncomingMsg = ["message_id " => $ msgID , "status " => "READ " ];
196
+ $ RspMsg = ["id " => Uuid::uuid4 ()->toString (), "action " => "ACKNOWLEDGE_MESSAGE_RECEIPT " ,
197
+ "params " => $ IncomingMsg ];
198
+ return $ RspMsg ;
199
+ }
200
+
201
+ function refundInstant ($ _assetID ,$ _amount ,$ _opponent_id ) {
202
+ $ mixinSdk = new MixinSDK (require './config.php ' );
203
+ // print_r();
204
+ $ BotInfo = $ mixinSdk ->Wallet ()->transfer ($ _assetID ,$ _opponent_id ,
205
+ $ mixinSdk ->getConfig ()['default ' ]['pin ' ],$ _amount );
206
+ print_r ($ BotInfo );
207
+ }
0 commit comments