增加消息功能key

This commit is contained in:
menxipeng
2025-08-25 22:11:47 +08:00
parent 145462ea02
commit ddef5f2146
4 changed files with 74 additions and 12 deletions

View File

@@ -142,5 +142,9 @@ ali:
umApp: umApp:
appAliKey: 204918113 appAliKey: 204918113
appAliSecret: v4UrIhhLZlo0adpmevyCfvThGFbrRer0 appAliSecret: v4UrIhhLZlo0adpmevyCfvThGFbrRer0
androidSecret: vxq4qfnb3jbb3jahrcxpbtpjgcuu7dtm
androidKey: 68a9988ce563686f4288e26d androidKey: 68a9988ce563686f4288e26d
IOSKey: 68a99a66ec2b5b6f8825b8b1 IOSKey: 68a99a66ec2b5b6f8825b8b1
IOSSecret: tjbflqx0eoqjixtyrtbh0zgijawmvxfe
# androidKey: 687b2df479267e0210b79b6f
# IOSKey: 687b2e1679267e0210b79b70

View File

@@ -33,6 +33,11 @@ public class AliKeyConfig implements InitializingBean {
@Value("${umApp.IOSKey}") @Value("${umApp.IOSKey}")
public String umAppIOSKey; public String umAppIOSKey;
@Value("${umApp.androidSecret}")
public String androidSecret;
@Value("${umApp.IOSSecret}")
public String IOSSecret;
// 终端ID // 终端ID
public static String ACCESS_KEY_ID; public static String ACCESS_KEY_ID;
@@ -47,6 +52,10 @@ public class AliKeyConfig implements InitializingBean {
public static String UMApp_AliSecret; public static String UMApp_AliSecret;
public static String Android_SECRET;
public static String IOS_SECRET;
@Override @Override
public void afterPropertiesSet() { public void afterPropertiesSet() {
ACCESS_KEY_ID = this.accessKeyId; ACCESS_KEY_ID = this.accessKeyId;
@@ -55,6 +64,8 @@ public class AliKeyConfig implements InitializingBean {
UMApp_IOS_Key = this.umAppIOSKey; UMApp_IOS_Key = this.umAppIOSKey;
UMApp_AliKey = this.umAppAliKey; UMApp_AliKey = this.umAppAliKey;
UMApp_AliSecret = this.umAppAliSecret; UMApp_AliSecret = this.umAppAliSecret;
Android_SECRET = this.androidSecret;
IOS_SECRET = this.IOSSecret;
} }

View File

@@ -0,0 +1,14 @@
package com.ruoyi.common.core.domain.entity;
import lombok.Data;
@Data
public class PushMsgInfo {
private String alias;
private String alias_type = "phone";
private String title;
private String text;
private String ticker;
}

View File

@@ -4,11 +4,13 @@ import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.constant.AliKeyConfig; import com.ruoyi.common.constant.AliKeyConfig;
import com.ruoyi.common.core.domain.UmResp; import com.ruoyi.common.core.domain.UmResp;
import com.ruoyi.common.core.domain.entity.PushMsgInfo;
import com.ruoyi.common.enums.DeviceTypeEnum; import com.ruoyi.common.enums.DeviceTypeEnum;
import com.ruoyi.common.utils.uuid.UUID; import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.config.push.AndroidNotification; import com.ruoyi.system.config.push.AndroidNotification;
import com.ruoyi.system.config.push.PushClient; import com.ruoyi.system.config.push.PushClient;
import com.ruoyi.system.config.push.android.AndroidCustomizedcast; import com.ruoyi.system.config.push.android.AndroidCustomizedcast;
import com.ruoyi.system.config.push.ios.IOSCustomizedcast;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.Header; import org.apache.http.Header;
@@ -37,7 +39,7 @@ public class UmengConfig {
private static final Logger log = LoggerFactory.getLogger(UmengConfig.class); private static final Logger log = LoggerFactory.getLogger(UmengConfig.class);
private PushClient client = new PushClient(); private final PushClient client = new PushClient();
public UmResp send(String token,String deviceTypeUp){ public UmResp send(String token,String deviceTypeUp){
String umAppkey = null; String umAppkey = null;
@@ -53,7 +55,7 @@ public class UmengConfig {
// //
// } // }
// //687b2df479267e0210b79b6f // //687b2df479267e0210b79b6f
// String umAppkey = "687b2e1679267e0210b79b70"; // String umAppkey = "68a99a66ec2b5b6f8825b8b1";
// String appKey = "204918113"; // String appKey = "204918113";
// String appSecret = "v4UrIhhLZlo0adpmevyCfvThGFbrRer0"; // String appSecret = "v4UrIhhLZlo0adpmevyCfvThGFbrRer0";
// 下面的url要和阿里云云市场购买的商品对应 // 下面的url要和阿里云云市场购买的商品对应
@@ -103,6 +105,7 @@ public class UmengConfig {
try { try {
log.info("发送数据:{}",httpPost); log.info("发送数据:{}",httpPost);
CloseableHttpResponse response = httpclient.execute(httpPost); CloseableHttpResponse response = httpclient.execute(httpPost);
log.info("返回数据1{}",response);
String respStr = EntityUtils.toString(response.getEntity()); String respStr = EntityUtils.toString(response.getEntity());
log.info("返回数据:{}",respStr); log.info("返回数据:{}",respStr);
return JSONUtil.toBean(respStr, UmResp.class); return JSONUtil.toBean(respStr, UmResp.class);
@@ -113,36 +116,66 @@ public class UmengConfig {
} }
public void sendAndroidCustomizedcast() throws Exception { public void sendAndroidCustomizedcast(PushMsgInfo pushMsgInfo) throws Exception {
AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(AliKeyConfig.UMApp_AliKey,AliKeyConfig.UMApp_AliSecret); // appAliKey: 204918113
// appAliSecret: v4UrIhhLZlo0adpmevyCfvThGFbrRer0
// AndroidCustomizedcast customizedcast = new AndroidCustomizedcast("68a9988ce563686f4288e26d","vxq4qfnb3jbb3jahrcxpbtpjgcuu7dtm");
AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(AliKeyConfig.UMApp_Android_Key,AliKeyConfig.Android_SECRET);
// TODO Set your alias here, and use comma to split them if there are multiple alias. // TODO Set your alias here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then // And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification. // use file_id to send customized notification.
customizedcast.setAlias("alias", "alias_type"); customizedcast.setAlias(pushMsgInfo.getAlias(), pushMsgInfo.getAlias_type());
customizedcast.setTicker( "Android customizedcast ticker"); customizedcast.setTicker(pushMsgInfo.getTicker());
customizedcast.setTitle( "中文的title"); customizedcast.setTitle(pushMsgInfo.getTitle());
customizedcast.setText( "Android customizedcast text"); customizedcast.setText(pushMsgInfo.getText());
customizedcast.goAppAfterOpen(); customizedcast.goAppAfterOpen();
customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION); customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device. // TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc. // For how to register a test device, please see the developer doc.
customizedcast.setProductionMode(); customizedcast.setProductionMode();
//厂商通道相关参数 //厂商通道相关参数
customizedcast.setChannelActivity("your channel activity"); // customizedcast.setChannelActivity("your channel activity");
customizedcast.setChannelProperties("abc"); // customizedcast.setChannelProperties("abc");
client.send(customizedcast);
}
public void sendIOSCustomizedcast(PushMsgInfo pushMsgInfo) throws Exception {
//App Key68a99a66ec2b5b6f8825b8b1
//App Master Secrettjbflqx0eoqjixtyrtbh0zgijawmvxfe
//IOSCustomizedcast customizedcast = new IOSCustomizedcast("68a99a66ec2b5b6f8825b8b1","tjbflqx0eoqjixtyrtbh0zgijawmvxfe");
IOSCustomizedcast customizedcast = new IOSCustomizedcast(AliKeyConfig.UMApp_IOS_Key,AliKeyConfig.IOS_SECRET);
// TODO Set your alias and alias_type here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification.
customizedcast.setAlias(pushMsgInfo.getAlias(), pushMsgInfo.getAlias_type());
//customizedcast.setAlert("IOS 个性化测试");
//alert的值设置为字典
customizedcast.setAlert(pushMsgInfo.getTitle() , "" , pushMsgInfo.getText());
customizedcast.setBadge( 0);
customizedcast.setSound( "default");
// TODO set 'production_mode' to 'true' if your app is under production mode
customizedcast.setTestMode();
client.send(customizedcast); client.send(customizedcast);
} }
public static void main(String[] args) { public static void main(String[] args) throws Exception {
UmengConfig umengConfig = new UmengConfig();
// System.out.println(DeviceTypeEnum.ANDROID.name()); // System.out.println(DeviceTypeEnum.ANDROID.name());
// UmResp sss1 = send("eyJvIjoiaU9TIiwiayI6ImJNSGJwMktVdjhVaE5zOW1wQWhwYlwvWCtVRTlqcnZKe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UIrbHNcL3luWWZFNWNicDIwRE9NV3ZcL0xLa0I2cXA5RkVtaXV6eDY2MWYzZE9hZnk2WUJ2V2dsQnljU05TSkdDNkpYeTZnWHEwR1wvNE9XTkRPdjFhakIxMnhGRk9PK1dhbUVKcG9Takxic0FFV0V5eEtDb3pXaU9meG0ydEJ0bHdoM2hwXC9Vb3RyRCtIbkY2Z1NOOGtCblVtYnJRU3FzYUdsM2g3WDZSZUREbXdRSmMzSzY0QkxNcCJ9", "ios");
// String sss; // String sss;
// //
// sss = "{\"success\":true,\"data\":{\"mobile\":\"18518753918\",\"score\":null,\"activeScore\":null,\"aesEncryptKey\":null},\"code\":2001,\"message\":\"gain mobile's result success\",\"requestId\":\"0E87E249-42A0-42C0-94D3-7424D45E571E\"}\n"; // sss = "{\"success\":true,\"data\":{\"mobile\":\"18518753918\",\"score\":null,\"activeScore\":null,\"aesEncryptKey\":null},\"code\":2001,\"message\":\"gain mobile's result success\",\"requestId\":\"0E87E249-42A0-42C0-94D3-7424D45E571E\"}\n";
// //
// UmResp ss = JSONUtil.toBean(sss, UmResp.class); // UmResp ss = JSONUtil.toBean(sss, UmResp.class);
// System.out.println(ss); // System.out.println(ss);
//UmengConfig umengConfig = new UmengConfig();
// PushMsgInfo pushMsgInfo = new PushMsgInfo();
// pushMsgInfo.setText("test");
// pushMsgInfo.setTitle("title");
// pushMsgInfo.setAlias("13943965645");
// //umengConfig.sendAndroidCustomizedcast(pushMsgInfo);
// umengConfig.sendIOSCustomizedcast(pushMsgInfo);
} }