在 PHP 中提交带有嵌套数组的 WebSocket 请求

Submit WebSocket request with Nested Arrays in PHP

下面我有这个 WebSocket 请求;

{
  "id": 2,
  "command": "submit",
  "tx_json" : {
      "TransactionType" : "TrustSet",
      "Account" : "r████████████████████████████",
      "Amount" : {
         "currency" : "FLX",
         "value" : "100000000",
         "issuer" : "r████████████████████████████"
      }
   },
   "secret" : "s████████████████████████████",
   "offline": false,
   "fee_mult_max": 1000
}

我下面的是一个 PHP WebSocket 请求;

我正在努力的是你看到上面例子中的 tx_json 是多么像一个数组。

我将如何在下面的示例中复制它;另外 Amount 是数组中的数组。

然后还有像 Secret 这样的值,它在数组之外。

感谢您的帮助。

<?php
    $server = 'xrpl.ws';
    $submitTransaction = json_encode(array(
        'id' => 2,
        'command' => "submit",
        
?????
        
    ));
    
    if( $sp = websocket_open($server, 443,'',$errstr, 10,true) ) {
      websocket_write($sp,$submitTransaction);
      $result = websocket_read($sp,$errstr);
    }else {
      echo "Failed to connect to server\n";
      echo "Server responed with: $errstr\n";
    }
?>

将示例 json 转换为数组并发送:

$json = '{
  "id": 2,
  "command": "submit",
  "tx_json" : {
      "TransactionType" : "TrustSet",
      "Account" : "r████████████████████████████",
      "Amount" : {
         "currency" : "FLX",
         "value" : "100000000",
         "issuer" : "r████████████████████████████"
      }
   },
   "secret" : "s████████████████████████████",
   "offline": false,
   "fee_mult_max": 1000
}';
$jsonAsArray = json_decode($json, true);
// arrayAsVariable
var_export($jsonAsArray);