105 lines
3.0 KiB
Python
105 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
测试Clash节点转换为SS格式功能
|
||
"""
|
||
|
||
import base64
|
||
import urllib.parse
|
||
from app import SubscriptionService
|
||
|
||
def test_clash_to_ss_conversion():
|
||
"""测试节点转换功能"""
|
||
service = SubscriptionService()
|
||
|
||
# 测试不同类型的节点
|
||
test_proxies = [
|
||
{
|
||
'name': '🇭🇰HongKong 01',
|
||
'type': 'trojan',
|
||
'server': 'taptap.sffyn.com',
|
||
'port': 48333,
|
||
'password': '474627a7-b6e2-4452-86a1-2519f27cc3e6'
|
||
},
|
||
{
|
||
'name': '剩余流量:183.54 GB',
|
||
'type': 'trojan',
|
||
'server': 'taptap.sffyn.com',
|
||
'port': 48333,
|
||
'password': '474627a7-b6e2-4452-86a1-2519f27cc3e6'
|
||
},
|
||
{
|
||
'name': 'Test SS Node',
|
||
'type': 'ss',
|
||
'server': 'example.com',
|
||
'port': 8388,
|
||
'cipher': 'aes-256-gcm',
|
||
'password': 'test-password'
|
||
}
|
||
]
|
||
|
||
print("测试Clash节点转换为SS格式:")
|
||
print("=" * 50)
|
||
|
||
for proxy in test_proxies:
|
||
ss_url = service.clash_to_ss_url(proxy)
|
||
print(f"原始节点: {proxy['name']}")
|
||
print(f"类型: {proxy['type']}")
|
||
print(f"转换结果: {ss_url}")
|
||
print("-" * 50)
|
||
|
||
def test_url_encoding():
|
||
"""测试URL编码功能"""
|
||
test_names = [
|
||
'🇭🇰HongKong 01',
|
||
'剩余流量:183.54 GB',
|
||
'🇸🇬Singapore 02',
|
||
'🇺🇸USA 03'
|
||
]
|
||
|
||
print("\n测试URL编码:")
|
||
print("=" * 50)
|
||
|
||
for name in test_names:
|
||
encoded = urllib.parse.quote(name, safe='')
|
||
print(f"原始: {name}")
|
||
print(f"编码: {encoded}")
|
||
print("-" * 30)
|
||
|
||
def test_base64_decoding():
|
||
"""测试Base64解码查看结果"""
|
||
try:
|
||
service = SubscriptionService()
|
||
|
||
# 模拟生成订阅内容
|
||
print("\n测试生成SS订阅内容:")
|
||
print("=" * 50)
|
||
|
||
# 创建一些示例SS URLs
|
||
sample_urls = [
|
||
"trojan://474627a7-b6e2-4452-86a1-2519f27cc3e6@taptap.sffyn.com:48333#%F0%9F%87%AD%F0%9F%87%B0HongKong%2001",
|
||
"trojan://474627a7-b6e2-4452-86a1-2519f27cc3e6@taptap.sffyn.com:45613#%F0%9F%87%B8%F0%9F%87%ACSingapore%2001",
|
||
"trojan://474627a7-b6e2-4452-86a1-2519f27cc3e6@taptap.sffyn.com:27306#%F0%9F%87%BA%F0%9F%87%B8USA%2001"
|
||
]
|
||
|
||
# 合并为字符串
|
||
content = '\n'.join(sample_urls)
|
||
print("SS URLs内容:")
|
||
print(content)
|
||
|
||
# Base64编码
|
||
encoded = base64.b64encode(content.encode('utf-8')).decode('utf-8')
|
||
print(f"\nBase64编码结果:")
|
||
print(encoded)
|
||
|
||
# 验证解码
|
||
decoded = base64.b64decode(encoded).decode('utf-8')
|
||
print(f"\n解码验证:")
|
||
print(decoded)
|
||
|
||
except Exception as e:
|
||
print(f"测试失败: {e}")
|
||
|
||
if __name__ == "__main__":
|
||
test_clash_to_ss_conversion()
|
||
test_url_encoding()
|
||
test_base64_decoding() |