From 5291e774ad35efe1ad440ccafb33007edbd4f461 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Mon, 11 Aug 2025 09:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=85=BE=E8=AE=AF=E4=BA=91?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 16 ++++-- sql/video_tablet_db.sql | 34 ++++++----- .../controller/BindSnController.java | 3 +- .../videotablet/utils/PushUtils.java | 57 ++++++++++++++++++- 4 files changed, 87 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index c46e33f..7230672 100644 --- a/pom.xml +++ b/pom.xml @@ -136,28 +136,28 @@ runtime - + com.aliyun alibabacloud-dysmsapi20170525 3.0.2 - + com.aliyun dysmsapi20170525 3.1.1 - + com.aliyun alibabacloud-push20160801 1.0.13 - + com.aliyun push20160801 @@ -182,12 +182,18 @@ 0.12.3 runtime - + com.tencentcloudapi tencentcloud-sdk-java-sms 3.1.499 + + + io.github.tpnsPush + xinge + 1.2.4.22 + diff --git a/sql/video_tablet_db.sql b/sql/video_tablet_db.sql index f912d13..5eb19e5 100644 --- a/sql/video_tablet_db.sql +++ b/sql/video_tablet_db.sql @@ -11,7 +11,7 @@ Target Server Version : 110702 (11.7.2-MariaDB-ubu2404) File Encoding : 65001 - Date: 07/08/2025 11:47:20 + Date: 11/08/2025 09:12:27 */ SET NAMES utf8mb4; @@ -22,6 +22,7 @@ SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- DROP TABLE IF EXISTS `devices_sn`; CREATE TABLE `devices_sn` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, `sn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '设备唯一标识', `device_model` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '设备型号', `device_alias` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '绑定用户给设备的备注', @@ -29,26 +30,29 @@ CREATE TABLE `devices_sn` ( `bind_phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '绑定用户的手机', `add_time` datetime NOT NULL COMMENT '添加时间', `activation_time` datetime NULL DEFAULT NULL COMMENT '激活时间', - PRIMARY KEY (`sn`) USING BTREE -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + `bind_time` datetime(6) NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for ordinary_users -- ---------------------------- DROP TABLE IF EXISTS `ordinary_users`; CREATE TABLE `ordinary_users` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `user_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, - `phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, - `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, - `nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, - `device_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, - `create_time` datetime NULL DEFAULT NULL, - `last_login_time` datetime(6) NOT NULL, - `update_time` datetime(6) NOT NULL, + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id自增', + `user_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户账号,类似于微信id', + `phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '绑定手机', + `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '密码', + `nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '昵称', + `device_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '设备id,登录校验', + `create_time` datetime NOT NULL COMMENT '创建时间', + `last_login_time` datetime(6) NULL DEFAULT NULL COMMENT '上次登录时间', + `update_time` datetime(6) NULL DEFAULT NULL COMMENT '用户信息更新时间', + `gender` int(11) NULL DEFAULT NULL COMMENT '性别', + `avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '头像', + `wx_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '绑定的微信id', PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `UKdu5v5sr43g5bfnji4vb8hg5s3`(`phone`) USING BTREE, - UNIQUE INDEX `UK2ty1xmrrgtn89xt7kyxx6ta7h`(`nickname`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + UNIQUE INDEX `UKdu5v5sr43g5bfnji4vb8hg5s3`(`phone`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/java/com/onekeycall/videotablet/controller/BindSnController.java b/src/main/java/com/onekeycall/videotablet/controller/BindSnController.java index 3837fb3..681e71a 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/BindSnController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/BindSnController.java @@ -56,7 +56,8 @@ public class BindSnController { try { String randomString = RandomStringUtils.randomAlphanumeric(32); - PushUtils.aliyunAsyncPush(randomString, userPhone, sn); +// PushUtils.aliyunAsyncPush(randomString, userPhone, sn); + PushUtils.tpnsPush(randomString, userPhone, sn); return Result.ok().message("send message success"); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/onekeycall/videotablet/utils/PushUtils.java b/src/main/java/com/onekeycall/videotablet/utils/PushUtils.java index 1fbe479..5c3f21c 100644 --- a/src/main/java/com/onekeycall/videotablet/utils/PushUtils.java +++ b/src/main/java/com/onekeycall/videotablet/utils/PushUtils.java @@ -6,13 +6,24 @@ import com.aliyun.sdk.service.push20160801.AsyncClient; import com.aliyun.sdk.service.push20160801.models.PushRequest; import com.aliyun.sdk.service.push20160801.models.PushResponse; import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.tencent.xinge.XingeApp; +import com.tencent.xinge.bean.AudienceType; +import com.tencent.xinge.bean.Message; +import com.tencent.xinge.bean.MessageAndroid; +import com.tencent.xinge.bean.MessageType; +import com.tencent.xinge.push.app.PushAppRequest; import darabonba.core.client.ClientOverrideConfiguration; +import org.glassfish.jaxb.core.v2.TODO; +import org.json.JSONObject; +import java.util.ArrayList; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; public class PushUtils { - public static void aliyunAsyncPush(String verifyKey, String phone,String sn) throws ExecutionException, InterruptedException { + + public static void aliyunAsyncPush(String verifyKey, String phone, String sn) throws ExecutionException, InterruptedException { // HttpClient Configuration /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder() .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds @@ -50,6 +61,10 @@ public class PushUtils { //.setConnectTimeout(Duration.ofSeconds(30)) ) .build(); + JsonObject params = new JsonObject(); + params.addProperty("verify_key", verifyKey); + params.addProperty("phone", phone); + params.addProperty("time", System.currentTimeMillis()); // Parameter settings for API request PushRequest pushRequest = PushRequest.builder() @@ -60,7 +75,7 @@ public class PushUtils { .targetValue(sn) .title("1") .storeOffline(true) - .body("{ \"perator\":\""+phone+"\",\"time\":\""+System.currentTimeMillis()+"\",\"verify_key\":\""+verifyKey+"\" }") + .body(params.toString()) // Request-level configuration rewrite, can set Http request parameters, etc. // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())) .build(); @@ -82,5 +97,43 @@ public class PushUtils { client.close(); } + public static void tpnsPush(String verifyKey, String phone, String sn) { + XingeApp xingeApp = new XingeApp.Builder() + .appId("1500043720") + .secretKey("1712af9e3079087447f4c35d2f622b89") + .domainUrl("https://api.tpns.tencent.com/") + .build(); + + PushAppRequest pushAppRequest = new PushAppRequest(); + // 选择推送目标类型 + pushAppRequest.setAudience_type(AudienceType.account); + // 消息类型:通知栏或透传消息 + pushAppRequest.setMessage_type(MessageType.message); + // 选择推送的账号类型 + //todo 为1时不能接收到不知什么原因 https://console.cloud.tencent.com/tpns/user-tools/1500043720/ap-guangzhou-1 + pushAppRequest.setAccount_push_type(0); + + JsonObject params = new JsonObject(); + params.addProperty("verify_key", verifyKey); + params.addProperty("phone", phone); + params.addProperty("time", System.currentTimeMillis()); + + Message message = new Message(); + // 推送标题 + message.setTitle("1"); + // 推送内容 + message.setContent(params.toString()); + MessageAndroid messageAndroid = new MessageAndroid(); + message.setAndroid(messageAndroid); + pushAppRequest.setMessage(message); + ArrayList accountList = new ArrayList<>(); + // 添加绑定账号 + accountList.add(sn); + // 设置账号列表 + pushAppRequest.setAccount_list(accountList); + + JSONObject ret = xingeApp.pushApp(pushAppRequest); + System.out.println(ret); + } }