tencent cloud

Quick Connection

Download
フォーカスモード
フォントサイズ
最終更新日: 2026-05-21 16:55:57

socks5 Integration

1. Calling Mobile Rights and Interests Authentication (Optional)

For customers with mobile rights and interests supported for data-free access, first call /api/v2/client/enableCMCCRightsVerify to get the authentication code for data-free access.
Parameter configuration:
token: token provided by mobile
guid: used with token.
salt: salt value, used for encryption.
If successful, record the return value authCode and fill it in step 2.
If it fails, respond with a message based on requirements.

2. Configure Acceleration Parameters (Required)

First, retrieve the appId and app key from the Tencent Cloud console, then refer to the source code in the appendix to calculate the appSign.
Call /api/v2/client/mp-speeder (parameter interface for acceleration configuration).
Configure with the following parameters:
appId: fill in the application id retrieved from the Tencent Cloud console.
appSign: calculated based on the app key. For the algorithm, see the appendix.
scheduleMode:rtc
authCode (optional): fill in the authCode returned by the first step mobile rights and interests authentication API.
Other optional parameters can be filled in as needed.

3. Configure Forwarding Rules (Optional, Enable Only When T2 Acceleration Is Required)

Call /api/v2/client/multi-mode (stream forwarding policy configuration API), specify the forwarding policy:
Specified parameters:
area: Select the drop-off point in section T2 as shown in the API overview.
speedMode: Select 35.

4. Enable socks5 Service (Required)

Call /api/v2/client/socks5 (configure socks5 server interface) to enable socks5 server.
Specified parameters:
enable: true.
port: Customer specified.
userName: Customer specified.
passWord: Customer specified.

5. Enable Acceleration

After calling (enable acceleration API), the SDK will first connect to the nearby Tencent Cloud gateway.
curl -X POST "http://127.0.0.1:9801/api/v2/client/mp-speeder/start" -H "accept: */*" -H "Content-Type: application/json"

6. Directing Traffic to socks5

Business app traffic import Step 4 specifies the socks5 port, and traffic will be forwarded according to the configured rules.

Appendix: appSign Calculation Method

Python

import jwt
from datetime import datetime, timedelta
from typing import Tuple


class JWTGenerator:
@classmethod
def generate_sign(cls, secret_key, device_name: str) -> Tuple[str, int]:
Generate JWT signature
now = datetime.utcnow()

payload = {
"deviceName": device_name
}

token = jwt.encode(
payload,
secret_key,
algorithm="HS256"
)

return token

if __name__ == "__main__":
try:
# replace with the APP key retrieved from console
secret_key = "QGZzL0M6L3dpbmRvd3Mvd2luLmluaT9yYXc/aW1wb3J0Jg=="
# Replace with device name, each device please use a different device_name
device_name = "test"

sign = JWTGenerator.generate_sign(secret_key, device_name)
print(f"Signature: {sign}")
except Exception as e:
print(f"Error generating token: {str(e)}")

golang

package main

import (
"fmt"
"github.com/golang-jwt/jwt/v4"
)

type JWTGenerator struct{}

// GenerateSign generates JWT signature
func (g *JWTGenerator) GenerateSign(secretKey string, deviceName string) (string, error) {
// Create payload
claims := jwt.MapClaims{
"deviceName": deviceName,
}

// Create token
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)

// Use key signature
signedToken, err := token.SignedString([]byte(secretKey))
if err != nil {
return "", err
}

return signedToken, nil
}

func main() {
// replace with the APP key retrieved from console
secretKey := "QGZzL0M6L3dpbmRvd3Mvd2luLmluaT9yYXc/aW1wb3J0Jg=="
// Replace with device name, each device please use a different device_name
deviceName := "test"

generator := &JWTGenerator{}
sign, err := generator.GenerateSign(secretKey, deviceName)
if err != nil {
fmt.Printf("Error generating token: %v\\n", err)
return
}
fmt.Printf("Signature: %s\\n", sign)
}

Java

<dependencies>
<!-- JWT Library -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
</dependencies>
The above configuration shows a Java project adding dependency for the JWT tool library via Maven.
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import javax.crypto.SecretKey;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class JWTGenerator {
/**
* Generate JWT signature
* @param secretKey Key string
* @param deviceName Device name
* @return JWT token
*/
public static String generateSign(String secretKey, String deviceName) {
// Convert the key string to SecretKey
SecretKey key = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8));
// Create payload
Map<String, Object> claims = new HashMap<>();
claims.put("deviceName", deviceName);
// Build JWT
return Jwts.builder()
.setClaims(claims)
.signWith(key)
.compact();
}
public static void main(String[] args) {
try {
// replace with the APP key retrieved from console
String secretKey = "QGZzL0M6L3dpbmRvd3Mvd2luLmluaT9yYXc/aW1wb3J0Jg==";
// Replace with device name, each device please use a different device_name
String deviceName = "test";
String sign = generateSign(secretKey, deviceName);
System.out.println("Signature: " + sign);
} catch (Exception e) {
System.out.println("Error generating token: " + e.getMessage());
e.printStackTrace();
}
}
}

Appendix: encryptSign Calculation Method

golang

package main

import (
"crypto/sha256"
"fmt"
"golang.org/x/crypto/chacha20"
"net"
)

// share encryption and decryption
func encryptOrdecrypt(ip net.IP, psk []byte) ([]byte, error) {
if ip.To4() == nil {
return nil, fmt.Errorf("invalid ipv4 address")
}

key := sha256.Sum256(psk)
encryptKey := key[:32]
nonce := make([]byte, 12)
cipher, err := chacha20.NewUnauthenticatedCipher(encryptKey, nonce)
if err != nil {
return nil, err
}

// in-place encryption (32bit exact output)
ciphertext := make([]byte, net.IPv4len)
cipher.XORKeyStream(ciphertext, ip.To4())
return ciphertext, nil
}


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック