Skip to content

Commit d965b95

Browse files
committed
pay/refund instantly
1 parent db97a0f commit d965b95

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
# mixin_labs-php-bot
22
Php bot for Mixin Network
33

4+
on macOS
45
```bash
6+
brew update
7+
brew install php
58
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
69
php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
710
//install composer to /usr/local/opt/[email protected]/bin and give a brief name 'composer'
811
php composer-setup.php --install-dir=/usr/local/opt/[email protected]/bin --filename=composer
912
php -r "unlink('composer-setup.php');"
10-
1113
```
14+
on Ubuntu
15+
```bash
16+
apt update
17+
apt upgrade
18+
apt install php
19+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
20+
php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
21+
//install composer to /usr/local/bin and give a brief name 'composer'
22+
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
23+
php -r "unlink('composer-setup.php');"
24+
```
25+
1226
# 安装依赖包
1327
```bash
1428
composer install

app.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require __DIR__ . '/vendor/autoload.php';
44
use ExinOne\MixinSDK\Traits\MixinSDKTrait;
5+
use ExinOne\MixinSDK\MixinSDK;
56
use Ramsey\Uuid\Uuid;
67
use Ratchet\RFC6455\Messaging\Frame;
78

@@ -35,9 +36,7 @@ public function __construct()
3536
print_r($jsMsg);
3637
if ($jsMsg->action === 'CREATE_MESSAGE' and property_exists($jsMsg,'data')) {
3738
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);
4140
$msg = new Frame(gzencode(json_encode($RspMsg)),true,Frame::OP_BINARY);
4241
$conn->send($msg);
4342

@@ -62,8 +61,22 @@ public function __construct()
6261
$msg = new Frame(gzencode(json_encode($msgData)),true,Frame::OP_BINARY);
6362
$conn->send($msg);
6463
}//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+
6780
});
6881

6982
$conn->on('close', function($code = null, $reason = null) {
@@ -172,3 +185,23 @@ function sendAppCard($jsMsg):Array
172185
];
173186
return $msgPayButton;
174187
}
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

Comments
 (0)