-
Notifications
You must be signed in to change notification settings - Fork 361
/
v2ray.js
42 lines (40 loc) · 1.54 KB
/
v2ray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var qrcode = require('qrcode-terminal');
var fs = require('fs');
fs.readFile('sebs.js', 'utf8', function (err, data) {
if (err) throw err;
node = JSON.parse(data);
console.log('-----------------iOS小火箭链接--------------------')
console.log(ios(node).toString())
console.log('-----------------安卓 v2rayNG链接-----------------')
console.log(android(node).toString())
qrcode.generate(ios(node).toString(), {small: true},function (qrcode) {
console.log('-----------------iOS 小火箭二维码------------------')
console.log(qrcode);
});
});
function ios(node) {
!node.method ? node.method = 'chacha20-poly1305' : ''
let v2rayBase = '' + node.method + ':' + node.id + '@' + node.add + ':' + node.port
let remarks = ''
// let obfsParam = ''
let path = ''
let obfs = ''
let tls = ''
!node.ps ? remarks = 'remarks=oneSubscribe' : remarks = `remarks=${node.ps}`
!node.path ? '' : path = `&path=${node.path}`
node.net == 'ws' ? obfs = `&obfs=websocket` : ''
node.net == 'h2' ? obfs = `&obfs=http` : ''
node.tls == 'tls' ? tls = `&tls=1` : ''
let query = remarks + path + obfs + tls
let baseV2ray = Buffer.from(v2rayBase).toString('base64')
let server = Buffer.from('vmess://' + baseV2ray + '?' + query)
return server
}
function android(node) {
node.v = "2"
// node.path = node.path.replace(/\//, '')
delete node.method
let baseV2ray = Buffer.from(JSON.stringify(node)).toString('base64')
let server = Buffer.from('vmess://' + baseV2ray)
return server
}