增加腾讯云推送
This commit is contained in:
16
pom.xml
16
pom.xml
@@ -136,28 +136,28 @@
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!--异步处理-->
|
||||
<!--阿里云短信异步-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>alibabacloud-dysmsapi20170525</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
|
||||
<!--同步-->
|
||||
<!--阿里云短信同步-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>3.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--异步推送-->
|
||||
<!--阿里云推送异步-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>alibabacloud-push20160801</artifactId>
|
||||
<version>1.0.13</version>
|
||||
</dependency>
|
||||
|
||||
<!--同步推送-->
|
||||
<!--阿里云推送同步-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>push20160801</artifactId>
|
||||
@@ -182,12 +182,18 @@
|
||||
<version>0.12.3</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 腾讯云短信服务 -->
|
||||
<dependency>
|
||||
<groupId>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
||||
<version>3.1.499</version> <!-- 推荐稳定版本 -->
|
||||
</dependency>
|
||||
<!-- 腾讯云推送 -->
|
||||
<dependency>
|
||||
<groupId>io.github.tpnsPush</groupId>
|
||||
<artifactId>xinge</artifactId>
|
||||
<version>1.2.4.22</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<String> accountList = new ArrayList<>();
|
||||
// 添加绑定账号
|
||||
accountList.add(sn);
|
||||
// 设置账号列表
|
||||
pushAppRequest.setAccount_list(accountList);
|
||||
|
||||
JSONObject ret = xingeApp.pushApp(pushAppRequest);
|
||||
System.out.println(ret);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user