PHP code example of tourze / shadowsocksr-config-php
1. Go to this page and download the library: Download tourze/shadowsocksr-config-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tourze / shadowsocksr-config-php example snippets
use ShadowsocksR\Config\ServerConfig;
use ShadowsocksR\Config\ClientConfig;
use ShadowsocksR\Config\SsrUri;
// Create a server configuration
$serverConfig = new ServerConfig(
'server-uuid',
'example.com',
8388,
'password',
'chacha20-ietf-poly1305',
'auth_chain_a',
'tls1.2_ticket_auth'
);
// Generate SSR URI
$ssrUri = SsrUri::encode($serverConfig);
echo $ssrUri; // ssr://...
// Decode SSR URI back to server config
$decodedConfig = SsrUri::decode($ssrUri);
use ShadowsocksR\Config\ServerConfig;
// Create a server configuration
$serverConfig = new ServerConfig(
'server-uuid',
'example.com',
8388,
'password',
'chacha20-ietf-poly1305',
'auth_chain_a',
'tls1.2_ticket_auth'
);
// Set protocol parameter and obfuscation parameter
$serverConfig->setProtocolParam('32');
$serverConfig->setObfsParam('cloudflare.com');
// Set remarks
$serverConfig->setRemarks('Example Server');
// Convert to JSON
$json = $serverConfig->toJson();
// Create server config from JSON
$configFromJson = ServerConfig::fromJson($json);
use ShadowsocksR\Config\ClientConfig;
// Create a client configuration
$clientConfig = new ClientConfig(
'example.com',
8388,
1080,
'password',
'chacha20-ietf-poly1305'
);
// Set protocol and obfuscation
$clientConfig->setProtocol('auth_chain_a');
$clientConfig->setObfs('tls1.2_ticket_auth');
// Set protocol parameter and obfuscation parameter
$clientConfig->setProtocolParam('32');
$clientConfig->setObfsParam('cloudflare.com');
// Convert to SSR URI
$ssrUri = $clientConfig->toSsrUri();
// Create client config from SSR URI
$configFromUri = ClientConfig::fromSsrUri($ssrUri);
use ShadowsocksR\Config\SsrUri;
use ShadowsocksR\Config\ServerConfig;
// Generate SSR URI from server config
$serverConfig = new ServerConfig(
'server-uuid',
'example.com',
8388,
'password',
'chacha20-ietf-poly1305',
'auth_chain_a',
'tls1.2_ticket_auth'
);
$serverConfig->setRemarks('Example Server');
$ssrUri = SsrUri::encode($serverConfig);
echo $ssrUri; // ssr://...
// Decode SSR URI back to server config
$decodedConfig = SsrUri::decode($ssrUri);
// Handle multiple configurations
$servers = [
$serverConfig,
// ... more server configs
];
$uris = SsrUri::encodeMultiple($servers);
$decodedServers = SsrUri::decodeMultiple($uris);
use ShadowsocksR\Config\SsrUri;
use ShadowsocksR\Config\ServerConfig;
use Shadowsocks\Config\SIP008;
// Create SSR server configurations
$ssrServer1 = new ServerConfig(
'uuid-1',
'server1.example.com',
8388,
'password1',
'chacha20-ietf-poly1305',
'auth_chain_a',
'tls1.2_ticket_auth'
);
$ssrServer1->setRemarks('Server 1');
$ssrServer2 = new ServerConfig(
'uuid-2',
'server2.example.com',
8389,
'password2',
'aes-256-gcm',
'auth_aes128_md5',
'http_simple'
);
$ssrServer2->setRemarks('Server 2');
// Convert SSR servers to standard servers
$standardServers = SsrUri::convertToStandardServers([$ssrServer1, $ssrServer2]);
// Create standard SIP008 configuration
$sip008 = new SIP008();
foreach ($standardServers as $server) {
$sip008->addServer($server);
}
// Output standard SIP008 JSON
$json = $sip008->toJson();
echo $json;
// Convert from standard SIP008 back to SSR configurations
$standardSip008 = SIP008::fromJson($json);
$ssrServers = SsrUri::convertFromSIP008(
$standardSip008,
'auth_chain_a', // Default protocol
'tls1.2_ticket_auth' // Default obfuscation
);