From 16fe54b9624f7beee8f2eec4f7d313a2c058c89a Mon Sep 17 00:00:00 2001 From: liangzai-alt Date: Sat, 18 Jan 2025 05:26:44 +0800 Subject: [PATCH 1/3] Create maven-publish.yml --- .github/workflows/maven-publish.yml | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/maven-publish.yml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 00000000..64b848b6 --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,34 @@ +# 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 + +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 }} From d13e969c11afe963d624377be41988471f2cf545 Mon Sep 17 00:00:00 2001 From: liangzai-alt Date: Wed, 29 Jan 2025 08:31:09 +0800 Subject: [PATCH 2/3] Update GenerateTestUserSig.java --- .../qcloud/tim/demo/signature/GenerateTestUserSig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Demo/app/src/main/java/com/tencent/qcloud/tim/demo/signature/GenerateTestUserSig.java b/Demo/app/src/main/java/com/tencent/qcloud/tim/demo/signature/GenerateTestUserSig.java index a467277d..fe30bd3d 100644 --- a/Demo/app/src/main/java/com/tencent/qcloud/tim/demo/signature/GenerateTestUserSig.java +++ b/Demo/app/src/main/java/com/tencent/qcloud/tim/demo/signature/GenerateTestUserSig.java @@ -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 @@ -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 From 6adb3d8c34c0da2e964576bde30baf6ea3b4dfef Mon Sep 17 00:00:00 2001 From: liangzai-alt Date: Wed, 29 Jan 2025 12:19:50 +0800 Subject: [PATCH 3/3] Update maven-publish.yml --- .github/workflows/maven-publish.yml | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 64b848b6..8af24b10 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,5 +1,68 @@ # 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