Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
import hashlib
import hmac
import time
import requests

# 你的腾讯云 API 密钥(请使用新的 SecretId 和 SecretKey)
SECRET_ID = "你的SecretId"
SECRET_KEY = "你的SecretKey"

# API 请求参数
service = "cvm" # 服务名称
host = "cvm.tencentcloudapi.com"
action = "DescribeRegions" # API 动作
version = "2017-03-12"
region = "ap-guangzhou"
timestamp = int(time.time()) # 当前时间戳
algorithm = "TC3-HMAC-SHA256"

# 请求体(一般是 JSON 字符串)
payload = "{}"
hashed_payload = hashlib.sha256(payload.encode("utf-8")).hexdigest()

# 计算 CanonicalRequest
canonical_request = f"POST\n/\n\ncontent-type:application/json\nhost:{host}\n\ncontent-type;host\n{hashed_payload}"

# 计算 StringToSign
date = time.strftime("%Y-%m-%d", time.gmtime(timestamp))
credential_scope = f"{date}/{service}/tc3_request"
hashed_canonical_request = hashlib.sha256(canonical_request.encode("utf-8")).hexdigest()
string_to_sign = f"{algorithm}\n{timestamp}\n{credential_scope}\n{hashed_canonical_request}"

# 计算签名
def sign(key, msg):
return hmac.new(key, msg.encode("utf-8"), hashlib.sha256).digest()

secret_date = sign(("TC3" + SECRET_KEY).encode("utf-8"), date)
secret_service = sign(secret_date, service)
secret_signing = sign(secret_service, "tc3_request")
signature = hmac.new(secret_signing, string_to_sign.encode("utf-8"), hashlib.sha256).hexdigest()

# 生成 Authorization 头
authorization = (
f"TC3-HMAC-SHA256 Credential={SECRET_ID}/{credential_scope}, "
f"SignedHeaders=content-type;host, Signature={signature}"
)

# 发送请求
headers = {
"Authorization": authorization,
"Content-Type": "application/json",
"Host": host,
"X-TC-Action": action,
"X-TC-Version": version,
"X-TC-Timestamp": str(timestamp),
"X-TC-Region": region,
"X-TC-Language": "zh-CN"
}

url = f"https://{host}"
response = requests.post(url, headers=headers, data=payload)

# 输出结果
print(response.json())

name: Maven Package

on:
release:
types: [created]

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Publish to GitHub Packages Apache Maven
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class GenerateTestUserSig {
* You can view your SDKAppID after creating an application in the [Tencent Cloud IM console](https://console.intl.cloud.tencent.com/im).
* SDKAppID uniquely identifies a Tencent Cloud account.
*/
public static final int SDKAPPID = 0;
public static final int SDKAPPID = 1600071170=1;

/**
* Signature validity period, which should not be set too short
Expand All @@ -61,7 +61,7 @@ public class GenerateTestUserSig {
* Note: this method is for testing only. Before commercial launch, please migrate the UserSig calculation code and key to your backend server to prevent key disclosure and traffic stealing.
* Reference: https://intl.cloud.tencent.com/document/product/1047/34385
*/
private static final String SECRETKEY = "";
private static final String SECRETKEY = "eJyrVgrxCdYrSy1SslIy0jNQ0gHzM1NS80oy0zLBwoZmBgYG5oaG5jDZ4pTsxIKCzBQlK4QURCa1oiCzKBUobmpqagSUgoiWZOaCxMyNLQwNDUwNLKCmZKYDDdf2dfUMLfByr0wKyTbNNfEuL3ApCUtJrSyN0Y*0KClJSc7MKrXQTvFxL0hxtVWqBQCL9zIy"=1;

/**
* Calculate UserSig
Expand Down