记得上下班打卡 | git大法好,push需谨慎

Commit cf6166d3 authored by jiangxiulong's avatar jiangxiulong

upush

parent 1f9e3da0
......@@ -24,16 +24,6 @@ public class UpushParam implements Serializable {
*/
private Integer pushRange;
/**
* 推送类型 unicast broadcast
*/
private Integer pushType;
/**
* 推送号码
*/
private String mobile;
/**
* 推送标题
*/
......@@ -50,7 +40,7 @@ public class UpushParam implements Serializable {
private String img;
/**
* 跳转类型 go_app,go_channel,go_super_channel,normal_play,normal_live,ugc_play,ugc_live,ad_link,promotion,ticket,tour,goods,area
* 跳转类型
*/
private Integer jumpType;
......@@ -69,16 +59,6 @@ public class UpushParam implements Serializable {
*/
private String pushTime;
/**
* 推送者姓名
*/
private String pushedName;
/**
* 推送任务ID
*/
private String taskId;
/**
* 是否发送推送消息,2不发送 1发送推送消息
*/
......@@ -104,14 +84,4 @@ public class UpushParam implements Serializable {
*/
private Integer messageShowType;
private String showContent;
/**
* 推送者ID
*/
private String pushedBy;
private String createdAt;
private String updatedAt;
}
......@@ -32,12 +32,12 @@ public class UpushSearchParam implements Serializable {
private Integer pushRange;
/**
* 推送类型 unicast broadcast
* 用户类型
*/
private Integer pushType;
private Integer specifyType;
/**
* 跳转类型 go_app,go_channel,go_super_channel,normal_play,normal_live,ugc_play,ugc_live,ad_link,promotion,ticket,tour,goods,area
* 跳转类型
*/
private Integer jumpType;
......
......@@ -9,7 +9,7 @@
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-post-add">
<div class="form-group">
<!--<div class="form-group">
<label class="col-sm-2 control-label">消息类型</label>
<div class="col-sm-10">
<div class="radio check-box">
......@@ -23,7 +23,7 @@
</label>
</div>
</div>
</div>
</div>-->
<div class="form-group">
<label class="col-sm-2 control-label">设备类型</label>
<div class="col-sm-10">
......@@ -70,7 +70,7 @@
</div>
</div>
</div>
<div class="form-group">
<!--<div class="form-group">
<label class="col-sm-2 control-label">推送范围</label>
<div class="col-sm-10">
<div class="radio check-box">
......@@ -78,13 +78,13 @@
<input type="radio" value="2" name="specifyType" checked=""> 全部用户
</label>
</div>
<!--<div class="radio check-box">
<div class="radio check-box">
<label>
<input type="radio" value="1" name="specifyType"> 指定手机号
</label>
</div>-->
</div>
</div>
</div>
</div>-->
<div class="form-group">
<label class="col-sm-2 control-label">排版方式</label>
<div class="col-sm-10">
......
......@@ -3,13 +3,11 @@
<head>
<th:block th:include="include :: header('推送详情')"/>
<th:block th:include="include :: select2-css"/>
<th:block th:include="include :: datetimepicker-css"/>
<th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-post-add">
<div class="form-group">
<!--<div class="form-group">
<label class="col-sm-2 control-label">消息类型</label>
<div class="col-sm-10">
<div class="radio check-box">
......@@ -23,7 +21,7 @@
</label>
</div>
</div>
</div>
</div>-->
<div class="form-group">
<label class="col-sm-2 control-label">设备类型</label>
<div class="col-sm-10">
......@@ -53,7 +51,7 @@
<input class="form-control" type="text" disabled th:value="${UpushDetailsListDao.jumpValue + UpushDetailsListDao.jumpContent}">
</div>
</div>
<div class="form-group">
<!--<div class="form-group">
<label class="col-sm-2 control-label">推送范围</label>
<div class="col-sm-10">
<div class="radio check-box">
......@@ -61,13 +59,13 @@
<input type="radio" value="2" name="specifyType" disabled="" th:checked="${UpushDetailsListDao.specifyType==2 ? true : false}"> 全部用户
</label>
</div>
<!--<div class="radio check-box">
&lt;!&ndash;<div class="radio check-box">
<label>
<input type="radio" value="1" name="specifyType"> 指定手机号
</label>
</div>-->
</div>&ndash;&gt;
</div>
</div>
</div>-->
<div class="form-group">
<label class="col-sm-2 control-label">排版方式</label>
<div class="col-sm-10">
......@@ -131,7 +129,7 @@
</div>
<div class="col-sm-4">
<div class="input-daterange input-group">
<input name="pushTime" type="text" class="input-sm form-control" id="laydate-startTime" th:value="${UpushDetailsListDao.pushTime}" placeholder="yyyy-MM-dd HH:mm:ss"/>
<input name="pushTime" type="text" class="input-sm form-control" id="laydate-startTime" th:value="${UpushDetailsListDao.pushTime}" placeholder="定时推送时间"/>
</div>
</div>
</div>
......@@ -140,8 +138,5 @@
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: bootstrap-suggest-js"/>
</body>
</html>
......@@ -29,14 +29,14 @@
<option value="3">Android</option>
</select>
</li>
<li>
<label>推送类型:</label>
<select name="pushType">
<!--<li>
<label>用户类型:</label>
<select name="specifyType">
<option value="">全部</option>
<option value="1">unicast</option>
<option value="2">broadcast</option>
<option value="2">全部用户</option>
<option value="1">指定用户</option>
</select>
</li>
</li>-->
<li>
<label>是否发送通知:</label>
<select name="isPush">
......@@ -45,14 +45,14 @@
<option value="1">发送推送消息</option>
</select>
</li>
<li>
<!--<li>
<label>消息类型:</label>
<select name="messageType">
<option value="">全部</option>
<option value="2">系统消息</option>
<option value="1">会员消息</option>
</select>
</li>
</li>-->
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
class="fa fa-search"></i>&nbsp;搜索</a>
......@@ -90,10 +90,6 @@
field: 'upushId',
title: 'ID'
},
{
field: 'pushType',
title: '推送方式'
},
{
field: 'pushTitle',
title: '推送标题'
......@@ -125,7 +121,7 @@
}
}
},
{
/*{
field: 'specifyType',
title: '用户类型',
formatter: function(value, row, index) {
......@@ -136,7 +132,7 @@
return "指定手机号"
}
}
},
},*/
{
field: 'isPush',
title: '是否发通知',
......@@ -176,6 +172,16 @@
field: 'pushTime',
title: '推送时间'
},
{
field: '',
title: '推送结果',
formatter: function(value, row, index) {
var taskId = row.taskId;
var msgId = row.msgId;
var errorCode = row.errorCode;
return 'taskId:'+taskId+'<br>'+'msgId:'+msgId+'<br>'+'errorCode:'+errorCode;
}
},
{
title: '操作',
align: 'center',
......
package com.liquidnet.client.admin;
import com.liquidnet.client.admin.common.utils.security.Md5Utils;
import com.liquidnet.commons.lang.constant.LnsEnum;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.MD5;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dto.vo.returns.KylinOrderRefundsVo;
......@@ -12,6 +14,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.query.Criteria;
......@@ -19,6 +22,7 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.time.LocalDateTime;
import java.util.Arrays;
/**
* Test
......@@ -32,6 +36,9 @@ public class TestLocal {
@Autowired
MongoConverter mongoConverter;
@Autowired
Environment environment;
@Test
public void updateAt(){
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
......@@ -56,4 +63,10 @@ public class TestLocal {
String signsign = MD5.getStrMD5(str,null);
System.out.print(signsign);
}
@Test
public void isXianshang() {
boolean contains = Arrays.asList(LnsEnum.ENV.dev.name(), LnsEnum.ENV.test.name()).contains(environment.getProperty(CurrentUtil.CK_ENV_ACTIVE));
System.out.println(contains);
}
}
......@@ -65,6 +65,11 @@
<scope>system</scope>
<systemPath>${project.basedir}/lib/taobao-sdk-java-auto_1600401599540-20210607.jar</systemPath>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -5,7 +5,13 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liquidnet.client.admin.common.enums.UpushTargetType;
import com.liquidnet.client.admin.common.utils.ShiroUtils;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.AndroidNotification;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.PushClient;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.android.AndroidBroadcast;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.ios.IOSBroadcast;
import com.liquidnet.commons.lang.constant.LnsEnum;
import com.liquidnet.commons.lang.util.BeanUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.kylin.dao.UpushDetailsListDao;
......@@ -18,9 +24,11 @@ import com.liquidnet.service.kylin.service.admin.IAdminUpushService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
......@@ -37,6 +45,20 @@ public class AdminUpushServiceImpl extends ServiceImpl<AdminUpushMapper, AdminUp
@Value("${liquidnet.al-oss.imgUrl}")
private String imgUrl;
@Value("${liquidnet.umeng.ios.appkey}")
private String iosAppkey;
@Value("${liquidnet.umeng.ios.appMasterSecret}")
private String iosAppMasterSecret;
@Value("${liquidnet.umeng.android.appkey}")
private String androidAppkey;
@Value("${liquidnet.umeng.android.appMasterSecret}")
private String androidAppMasterSecret;
private PushClient client = new PushClient();
@Autowired
Environment environment;
@Autowired
private AdminUpushMapper adminUpushMapper;
......@@ -45,17 +67,28 @@ public class AdminUpushServiceImpl extends ServiceImpl<AdminUpushMapper, AdminUp
// 入数据库
String upushId = IDGenerator.nextSnowId();
upushParam.setUpushId(upushId);
upushParam.setCreatedAt(DateUtil.getNowTime());
String authId = ShiroUtils.getUserId().toString();
String authName = ShiroUtils.getLoginName();
upushParam.setPushedBy(authId);
upushParam.setPushedName(authName);
AdminUpush adminUpush = new AdminUpush();
BeanUtils.copyProperties(upushParam, adminUpush);
adminUpush.setCreatedAt(DateUtil.getNowTime());
adminUpush.setPushedBy(authId);
adminUpush.setPushedName(authName);
if (adminUpush.getPushTime().isEmpty()) {
adminUpush.setPushTime(null);
}
adminUpushMapper.insert(adminUpush);
if (adminUpush.getIsPush() == 1) {
if (adminUpush.getPushRange() == 1) {
sendAndroidBroadcast(adminUpush);
sendIOSBroadcast(adminUpush);
} else if (adminUpush.getPushRange() == 2) {
sendIOSBroadcast(adminUpush);
} else if (adminUpush.getPushRange() == 3) {
sendAndroidBroadcast(adminUpush);
}
}
return true;
} catch (Exception e) {
return false;
......@@ -91,4 +124,60 @@ public class AdminUpushServiceImpl extends ServiceImpl<AdminUpushMapper, AdminUp
return upushDetailsListDao;
}
public void sendAndroidBroadcast(AdminUpush adminUpush) {
try {
AndroidBroadcast broadcast = new AndroidBroadcast(androidAppkey, androidAppMasterSecret);
broadcast.setTicker(adminUpush.getPushTitle());
broadcast.setTitle(adminUpush.getPushTitle());
broadcast.setText(adminUpush.getPushContent());
broadcast.goAppAfterOpen();
broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
if (Arrays.asList(LnsEnum.ENV.dev.name(), LnsEnum.ENV.test.name()).contains(environment.getProperty(CurrentUtil.CK_ENV_ACTIVE))) {
broadcast.setTestMode();
} else {
broadcast.setProductionMode();
}
// Set customized fields
broadcast.setExtraField("type", adminUpush.getJumpType().toString());
broadcast.setExtraField("id", adminUpush.getJumpValue());
broadcast.setExtraField("url", adminUpush.getJumpValue());
if (adminUpush.getSendType() == 1) {
String pushTime = adminUpush.getPushTime();
broadcast.setPredefinedKeyValue("start_time", pushTime);
}
client.send(broadcast);
} catch (Exception e) {
}
}
public void sendIOSBroadcast(AdminUpush adminUpush) {
try {
IOSBroadcast broadcast = new IOSBroadcast(iosAppkey, iosAppMasterSecret);
//alert的值设置为字典
broadcast.setAlert(adminUpush.getPushTitle(), adminUpush.getPushTitle(), adminUpush.getPushContent());
broadcast.setBadge(0);
broadcast.setSound("default");
if (Arrays.asList(LnsEnum.ENV.dev.name(), LnsEnum.ENV.test.name()).contains(environment.getProperty(CurrentUtil.CK_ENV_ACTIVE))) {
broadcast.setTestMode();
} else {
broadcast.setProductionMode();
}
// Set customized fields
broadcast.setCustomizedField("type", adminUpush.getJumpType().toString());
broadcast.setCustomizedField("id", adminUpush.getJumpValue());
broadcast.setCustomizedField("url", adminUpush.getJumpValue());
if (adminUpush.getSendType() == 1) {
String pushTime = adminUpush.getPushTime();
broadcast.setPredefinedKeyValue("start_time", pushTime);
}
client.send(broadcast);
} catch (Exception e) {
}
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush;
import org.json.JSONObject;
import java.util.Arrays;
import java.util.HashSet;
public abstract class AndroidNotification extends UmengNotification {
// Keys can be set in the payload level
protected static final HashSet<String> PAYLOAD_KEYS = new HashSet<String>(Arrays.asList(new String[]{
"display_type"}));
// Keys can be set in the body level
protected static final HashSet<String> BODY_KEYS = new HashSet<String>(Arrays.asList(new String[]{
"ticker", "title", "text", "builder_id", "icon", "largeIcon", "img", "play_vibrate", "play_lights", "play_sound",
"sound", "after_open", "url", "activity", "custom"}));
public enum DisplayType{
NOTIFICATION{public String getValue(){return "notification";}},///通知:消息送达到用户设备后,由友盟SDK接管处理并在通知栏上显示通知内容。
MESSAGE{public String getValue(){return "message";}};///消息:消息送达到用户设备后,消息内容透传给应用自身进行解析处理。
public abstract String getValue();
}
public enum AfterOpenAction{
go_app,//打开应用
go_url,//跳转到URL
go_activity,//打开特定的activity
go_custom//用户自定义内容。
}
// Set key/value in the rootJson, for the keys can be set please see ROOT_KEYS, PAYLOAD_KEYS,
// BODY_KEYS and POLICY_KEYS.
@Override
public boolean setPredefinedKeyValue(String key, Object value) throws Exception {
if (ROOT_KEYS.contains(key)) {
// This key should be in the root level
rootJson.put(key, value);
} else if (PAYLOAD_KEYS.contains(key)) {
// This key should be in the payload level
JSONObject payloadJson = null;
if (rootJson.has("payload")) {
payloadJson = rootJson.getJSONObject("payload");
} else {
payloadJson = new JSONObject();
rootJson.put("payload", payloadJson);
}
payloadJson.put(key, value);
} else if (BODY_KEYS.contains(key)) {
// This key should be in the body level
JSONObject bodyJson = null;
JSONObject payloadJson = null;
// 'body' is under 'payload', so build a payload if it doesn't exist
if (rootJson.has("payload")) {
payloadJson = rootJson.getJSONObject("payload");
} else {
payloadJson = new JSONObject();
rootJson.put("payload", payloadJson);
}
// Get body JSONObject, generate one if not existed
if (payloadJson.has("body")) {
bodyJson = payloadJson.getJSONObject("body");
} else {
bodyJson = new JSONObject();
payloadJson.put("body", bodyJson);
}
bodyJson.put(key, value);
} else if (POLICY_KEYS.contains(key)) {
// This key should be in the body level
JSONObject policyJson = null;
if (rootJson.has("policy")) {
policyJson = rootJson.getJSONObject("policy");
} else {
policyJson = new JSONObject();
rootJson.put("policy", policyJson);
}
policyJson.put(key, value);
} else {
if (key == "payload" || key == "body" || key == "policy" || key == "extra") {
throw new Exception("You don't need to set value for " + key + " , just set values for the sub keys in it.");
} else {
throw new Exception("Unknown key: " + key);
}
}
return true;
}
// Set extra key/value for Android notification
public boolean setExtraField(String key, String value) throws Exception {
JSONObject payloadJson = null;
JSONObject extraJson = null;
if (rootJson.has("payload")) {
payloadJson = rootJson.getJSONObject("payload");
} else {
payloadJson = new JSONObject();
rootJson.put("payload", payloadJson);
}
if (payloadJson.has("extra")) {
extraJson = payloadJson.getJSONObject("extra");
} else {
extraJson = new JSONObject();
payloadJson.put("extra", extraJson);
}
extraJson.put(key, value);
return true;
}
//
public void setDisplayType(DisplayType d) throws Exception {
setPredefinedKeyValue("display_type", d.getValue());
}
///通知栏提示文字
public void setTicker(String ticker) throws Exception {
setPredefinedKeyValue("ticker", ticker);
}
///通知标题
public void setTitle(String title) throws Exception {
setPredefinedKeyValue("title", title);
}
///通知文字描述
public void setText(String text) throws Exception {
setPredefinedKeyValue("text", text);
}
///用于标识该通知采用的样式。使用该参数时, 必须在SDK里面实现自定义通知栏样式。
public void setBuilderId(Integer builder_id) throws Exception {
setPredefinedKeyValue("builder_id", builder_id);
}
///状态栏图标ID, R.drawable.[smallIcon],如果没有, 默认使用应用图标。
public void setIcon(String icon) throws Exception {
setPredefinedKeyValue("icon", icon);
}
///通知栏拉开后左侧图标ID
public void setLargeIcon(String largeIcon) throws Exception {
setPredefinedKeyValue("largeIcon", largeIcon);
}
///通知栏大图标的URL链接。该字段的优先级大于largeIcon。该字段要求以http或者https开头。
public void setImg(String img) throws Exception {
setPredefinedKeyValue("img", img);
}
///收到通知是否震动,默认为"true"
public void setPlayVibrate(Boolean play_vibrate) throws Exception {
setPredefinedKeyValue("play_vibrate", play_vibrate.toString());
}
///收到通知是否闪灯,默认为"true"
public void setPlayLights(Boolean play_lights) throws Exception {
setPredefinedKeyValue("play_lights", play_lights.toString());
}
///收到通知是否发出声音,默认为"true"
public void setPlaySound(Boolean play_sound) throws Exception {
setPredefinedKeyValue("play_sound", play_sound.toString());
}
///通知声音,R.raw.[sound]. 如果该字段为空,采用SDK默认的声音
public void setSound(String sound) throws Exception {
setPredefinedKeyValue("sound", sound);
}
///收到通知后播放指定的声音文件
public void setPlaySound(String sound) throws Exception {
setPlaySound(true);
setSound(sound);
}
///点击"通知"的后续行为,默认为打开app。
public void goAppAfterOpen() throws Exception {
setAfterOpenAction(AfterOpenAction.go_app);
}
public void goUrlAfterOpen(String url) throws Exception {
setAfterOpenAction(AfterOpenAction.go_url);
setUrl(url);
}
public void goActivityAfterOpen(String activity) throws Exception {
setAfterOpenAction(AfterOpenAction.go_activity);
setActivity(activity);
}
public void goCustomAfterOpen(String custom) throws Exception {
setAfterOpenAction(AfterOpenAction.go_custom);
setCustomField(custom);
}
public void goCustomAfterOpen(JSONObject custom) throws Exception {
setAfterOpenAction(AfterOpenAction.go_custom);
setCustomField(custom);
}
///点击"通知"的后续行为,默认为打开app。原始接口
public void setAfterOpenAction(AfterOpenAction action) throws Exception {
setPredefinedKeyValue("after_open", action.toString());
}
public void setUrl(String url) throws Exception {
setPredefinedKeyValue("url", url);
}
public void setActivity(String activity) throws Exception {
setPredefinedKeyValue("activity", activity);
}
///can be a string of json
public void setCustomField(String custom) throws Exception {
setPredefinedKeyValue("custom", custom);
}
public void setCustomField(JSONObject custom) throws Exception {
setPredefinedKeyValue("custom", custom);
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush;
import org.json.JSONObject;
import java.util.Arrays;
import java.util.HashSet;
public abstract class IOSNotification extends UmengNotification {
// Keys can be set in the aps level
protected static final HashSet<String> APS_KEYS = new HashSet<String>(Arrays.asList(new String[]{
"alert", "badge", "sound", "content-available"
}));
@Override
public boolean setPredefinedKeyValue(String key, Object value) throws Exception {
if (ROOT_KEYS.contains(key)) {
// This key should be in the root level
rootJson.put(key, value);
} else if (APS_KEYS.contains(key)) {
// This key should be in the aps level
JSONObject apsJson = null;
JSONObject payloadJson = null;
if (rootJson.has("payload")) {
payloadJson = rootJson.getJSONObject("payload");
} else {
payloadJson = new JSONObject();
rootJson.put("payload", payloadJson);
}
if (payloadJson.has("aps")) {
apsJson = payloadJson.getJSONObject("aps");
} else {
apsJson = new JSONObject();
payloadJson.put("aps", apsJson);
}
apsJson.put(key, value);
} else if (POLICY_KEYS.contains(key)) {
// This key should be in the body level
JSONObject policyJson = null;
if (rootJson.has("policy")) {
policyJson = rootJson.getJSONObject("policy");
} else {
policyJson = new JSONObject();
rootJson.put("policy", policyJson);
}
policyJson.put(key, value);
} else {
if (key == "payload" || key == "aps" || key == "policy") {
throw new Exception("You don't need to set value for " + key + " , just set values for the sub keys in it.");
} else {
throw new Exception("Unknownd key: " + key);
}
}
return true;
}
// Set customized key/value for IOS notification
public boolean setCustomizedField(String key, String value) throws Exception {
//rootJson.put(key, value);
JSONObject payloadJson = null;
if (rootJson.has("payload")) {
payloadJson = rootJson.getJSONObject("payload");
} else {
payloadJson = new JSONObject();
rootJson.put("payload", payloadJson);
}
payloadJson.put(key, value);
return true;
}
public void setAlert(String token) throws Exception {
setPredefinedKeyValue("alert", token);
}
public void setAlert(String title ,String subtitle , String body) throws Exception{
JSONObject object = new JSONObject();
object.put("title" , title);
object.put("subtitle" , subtitle);
object.put("body" , body);
setPredefinedKeyValue("alert",object );
}
public void setBadge(Integer badge) throws Exception {
setPredefinedKeyValue("badge", badge);
}
public void setSound(String sound) throws Exception {
setPredefinedKeyValue("sound", sound);
}
public void setContentAvailable(Integer contentAvailable) throws Exception {
setPredefinedKeyValue("content-available", contentAvailable);
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class PushClient {
// The user agent
protected final String USER_AGENT = "Mozilla/5.0";
// This object is used for sending the post request to Umeng
// protected HttpClient client = new DefaultHttpClient();
protected CloseableHttpClient client = HttpClients.createDefault();
// The host
protected static final String host = "http://msg.umeng.com"; // https://msgapi.umeng.com
// The upload path
protected static final String uploadPath = "/upload";
// The post path
protected static final String postPath = "/api/send";
public boolean send(UmengNotification msg) throws Exception {
// TODO: 2021/7/14 上线去掉
msg.setTestMode();
String timestamp = Integer.toString((int)(System.currentTimeMillis() / 1000));
msg.setPredefinedKeyValue("timestamp", timestamp);
String url = host + postPath;
String postBody = msg.getPostBody();
String sign = DigestUtils.md5Hex(("POST" + url + postBody + msg.getAppMasterSecret()).getBytes("utf8"));
url = url + "?sign=" + sign;
HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT);
StringEntity se = new StringEntity(postBody, "UTF-8");
post.setEntity(se);
// Send the post request and get the response
HttpResponse response = client.execute(post);
int status = response.getStatusLine().getStatusCode();
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
if (status == 200) {
System.out.println("Notification sent successfully.");
} else {
System.out.println("Failed to send the notification!");
}
return true;
}
// Upload file with device_tokens to Umeng
public String uploadContents(String appkey,String appMasterSecret,String contents) throws Exception {
// Construct the json string
JSONObject uploadJson = new JSONObject();
uploadJson.put("appkey", appkey);
String timestamp = Integer.toString((int)(System.currentTimeMillis() / 1000));
uploadJson.put("timestamp", timestamp);
uploadJson.put("content", contents);
// Construct the request
String url = host + uploadPath;
String postBody = uploadJson.toString();
String sign = DigestUtils.md5Hex(("POST" + url + postBody + appMasterSecret).getBytes("utf8"));
url = url + "?sign=" + sign;
HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT);
StringEntity se = new StringEntity(postBody, "UTF-8");
post.setEntity(se);
// Send the post request and get the response
HttpResponse response = client.execute(post);
System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
// Decode response string and get file_id from it
JSONObject respJson = new JSONObject(result.toString());
String ret = respJson.getString("ret");
if (!ret.equals("SUCCESS")) {
throw new Exception("Failed to upload file");
}
JSONObject data = respJson.getJSONObject("data");
String fileId = data.getString("file_id");
// Set file_id into rootJson using setPredefinedKeyValue
return fileId;
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush;
import org.json.JSONObject;
import java.util.Arrays;
import java.util.HashSet;
public abstract class UmengNotification {
// This JSONObject is used for constructing the whole request string.
protected final JSONObject rootJson = new JSONObject();
// The app master secret
protected String appMasterSecret;
// Keys can be set in the root level
protected static final HashSet<String> ROOT_KEYS = new HashSet<String>(Arrays.asList(new String[]{
"appkey", "timestamp", "type", "device_tokens", "alias", "alias_type", "file_id",
"filter", "production_mode", "feedback", "description", "thirdparty_id" , "mipush" , "mi_activity" , "channel_properties"}));
// Keys can be set in the policy level
protected static final HashSet<String> POLICY_KEYS = new HashSet<String>(Arrays.asList(new String[]{
"start_time", "expire_time", "max_send_num"
}));
// Set predefined keys in the rootJson, for extra keys(Android) or customized keys(IOS) please
// refer to corresponding methods in the subclass.
public abstract boolean setPredefinedKeyValue(String key, Object value) throws Exception;
public void setAppMasterSecret(String secret) {
appMasterSecret = secret;
}
public String getPostBody(){
return rootJson.toString();
}
protected final String getAppMasterSecret(){
return appMasterSecret;
}
protected void setProductionMode(Boolean prod) throws Exception {
setPredefinedKeyValue("production_mode", prod.toString());
}
///正式模式
public void setProductionMode() throws Exception {
setProductionMode(true);
}
///测试模式
public void setTestMode() throws Exception {
setProductionMode(false);
}
///发送消息描述,建议填写。
public void setDescription(String description) throws Exception {
setPredefinedKeyValue("description", description);
}
///定时发送时间,若不填写表示立即发送。格式: "YYYY-MM-DD hh:mm:ss"。
public void setStartTime(String startTime) throws Exception {
setPredefinedKeyValue("start_time", startTime);
}
///消息过期时间,格式: "YYYY-MM-DD hh:mm:ss"。
public void setExpireTime(String expireTime) throws Exception {
setPredefinedKeyValue("expire_time", expireTime);
}
///发送限速,每秒发送的最大条数。
public void setMaxSendNum(Integer num) throws Exception {
setPredefinedKeyValue("max_send_num", num);
}
//厂商弹窗activity
public void setChannelActivity(String activity) throws Exception{
setPredefinedKeyValue("mipush", "true");
setPredefinedKeyValue("mi_activity",activity );
}
//厂商属性配置
public void setChannelProperties(String xiaoMiChannelId) throws Exception{
JSONObject object = new JSONObject();
object.put("xiaomi_channel_id" , xiaoMiChannelId);
setPredefinedKeyValue("channel_properties", object);
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.android;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.AndroidNotification;
public class AndroidBroadcast extends AndroidNotification {
public AndroidBroadcast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "broadcast");
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.android;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.AndroidNotification;
public class AndroidCustomizedcast extends AndroidNotification {
public AndroidCustomizedcast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "customizedcast");
}
public void setAlias(String alias,String aliasType) throws Exception {
setPredefinedKeyValue("alias", alias);
setPredefinedKeyValue("alias_type", aliasType);
}
public void setFileId(String fileId,String aliasType) throws Exception {
setPredefinedKeyValue("file_id", fileId);
setPredefinedKeyValue("alias_type", aliasType);
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.android;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.AndroidNotification;
public class AndroidFilecast extends AndroidNotification {
public AndroidFilecast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "filecast");
}
public void setFileId(String fileId) throws Exception {
setPredefinedKeyValue("file_id", fileId);
}
}
\ No newline at end of file
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.android;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.AndroidNotification;
import org.json.JSONObject;
public class AndroidGroupcast extends AndroidNotification {
public AndroidGroupcast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "groupcast");
}
public void setFilter(JSONObject filter) throws Exception {
setPredefinedKeyValue("filter", filter);
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.android;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.AndroidNotification;
public class AndroidUnicast extends AndroidNotification {
public AndroidUnicast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "unicast");
}
public void setDeviceToken(String token) throws Exception {
setPredefinedKeyValue("device_tokens", token);
}
}
\ No newline at end of file
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.ios;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.IOSNotification;
public class IOSBroadcast extends IOSNotification {
public IOSBroadcast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "broadcast");
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.ios;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.IOSNotification;
public class IOSCustomizedcast extends IOSNotification {
public IOSCustomizedcast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "customizedcast");
}
public void setAlias(String alias,String aliasType) throws Exception {
setPredefinedKeyValue("alias", alias);
setPredefinedKeyValue("alias_type", aliasType);
}
public void setFileId(String fileId, String aliasType) throws Exception {
setPredefinedKeyValue("file_id", fileId);
setPredefinedKeyValue("alias_type", aliasType);
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.ios;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.IOSNotification;
public class IOSFilecast extends IOSNotification {
public IOSFilecast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "filecast");
}
public void setFileId(String fileId) throws Exception {
setPredefinedKeyValue("file_id", fileId);
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.ios;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.IOSNotification;
import org.json.JSONObject;
public class IOSGroupcast extends IOSNotification {
public IOSGroupcast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "groupcast");
}
public void setFilter(JSONObject filter) throws Exception {
setPredefinedKeyValue("filter", filter);
}
}
package com.liquidnet.client.admin.zhengzai.kylin.utils.upush.ios;
import com.liquidnet.client.admin.zhengzai.kylin.utils.upush.IOSNotification;
public class IOSUnicast extends IOSNotification {
public IOSUnicast(String appkey,String appMasterSecret) throws Exception{
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "unicast");
}
public void setDeviceToken(String token) throws Exception {
setPredefinedKeyValue("device_tokens", token);
}
}
......@@ -240,6 +240,12 @@
<artifactId>liquidnet-client-admin-zhengzai</artifactId>
<version>${ruoyi.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
</dependencies>
</dependencyManagement>
......
......@@ -87,6 +87,13 @@ liquidnet:
dysms:
accessKeyId: LTAI5tHt7yvm97G8zxackcMK
accessKeySecret: xC3i5qEptJ3JIIRaYLaKvhk4gVASfl
umeng:
ios:
appkey: 54fe819bfd98c546b50004f0
appMasterSecret: fsls9dv1vwyemqdv9lidjfppk37nmssa
android:
appkey: 5c6cf6cbb465f592e4000bae
appMasterSecret: dmsho74wlpd1hp7vrwp9bjehzwo29pza
#application-dev-end
......@@ -87,6 +87,13 @@ liquidnet:
dysms:
accessKeyId: LTAI5tHt7yvm97G8zxackcMK
accessKeySecret: xC3i5qEptJ3JIIRaYLaKvhk4gVASfl
umeng:
ios:
appkey: 54fe819bfd98c546b50004f0
appMasterSecret: fsls9dv1vwyemqdv9lidjfppk37nmssa
android:
appkey: 5c6cf6cbb465f592e4000bae
appMasterSecret: dmsho74wlpd1hp7vrwp9bjehzwo29pza
#application-test-end
\ No newline at end of file
......@@ -18,16 +18,6 @@ public class UpushDetailsListDao implements Serializable {
*/
private Integer pushRange;
/**
* 推送类型 unicast broadcast
*/
private Integer pushType;
/**
* 推送号码
*/
private String mobile;
/**
* 推送标题
*/
......@@ -44,7 +34,7 @@ public class UpushDetailsListDao implements Serializable {
private String img;
/**
* 跳转类型 go_app,go_channel,go_super_channel,normal_play,normal_live,ugc_play,ugc_live,ad_link,promotion,ticket,tour,goods,area
* 跳转类型
*/
private Integer jumpType;
private String jumpName;
......@@ -64,11 +54,6 @@ public class UpushDetailsListDao implements Serializable {
*/
private String pushTime;
/**
* 推送任务ID
*/
private String taskId;
/**
* 是否发送推送消息,2不发送 1发送推送消息
*/
......@@ -94,8 +79,6 @@ public class UpushDetailsListDao implements Serializable {
*/
private Integer messageShowType;
private String showContent;
/**
* 推送者ID
*/
......@@ -109,4 +92,8 @@ public class UpushDetailsListDao implements Serializable {
private String createdAt;
private String updatedAt;
private String errorCode;
private String taskId;
private String msgId;
}
......@@ -12,8 +12,8 @@
<if test="pushRange != ''">
AND push_range=${pushRange}
</if>
<if test="pushType != ''">
AND push_type=${pushType}
<if test="specifyType != ''">
AND specify_type=${specifyType}
</if>
<if test="jumpType != ''">
AND jump_type=${jumpType}
......
......@@ -987,25 +987,25 @@ CREATE TABLE `admin_upush`
(
`mid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`upush_id` varchar(255) NOT NULL DEFAULT 0 COMMENT 'upush_id',
`push_range` tinyint NOT NULL DEFAULT 0 COMMENT '推送设备all ios android',
`push_type` tinyint NOT NULL DEFAULT 0 COMMENT '推送类型 unicast broadcast',
`mobile` varchar(11) NOT NULL DEFAULT '' COMMENT '推送号码',
`push_range` tinyint NOT NULL DEFAULT 0 COMMENT '推送设备 1all 2ios 3android',
`push_title` varchar(255) NOT NULL DEFAULT '' COMMENT '推送标题',
`push_content` varchar(255) NOT NULL DEFAULT '' COMMENT '推送内容',
`img` varchar(500) NOT NULL DEFAULT '' COMMENT '封面图',
`jump_type` tinyint NOT NULL DEFAULT 0 COMMENT '跳转类型 go_app,go_channel,go_super_channel,normal_play,normal_live,ugc_play,ugc_live,ad_link,promotion,ticket,tour,goods,area',
`jump_type` tinyint NOT NULL DEFAULT 0 COMMENT '跳转类型',
`jump_value` varchar(255) NOT NULL DEFAULT '' COMMENT '跳转值',
`jump_content` varchar(500) NOT NULL DEFAULT '' COMMENT '跳转对应的值名称',
`push_time` timestamp NULL DEFAULT NULL COMMENT '推送时间',
`task_id` varchar(255) NOT NULL DEFAULT '' COMMENT '推送任务ID',
`is_push` int NOT NULL DEFAULT 0 COMMENT '是否发送推送消息,2不发送 1发送推送消息',
`send_type` int NOT NULL DEFAULT 0 COMMENT '发送类型,2立即发送 1定时发送',
`message_type` int NOT NULL DEFAULT 0 COMMENT '消息类型,2系统消息 1会员消息',
`specify_type` int NOT NULL DEFAULT 0 COMMENT '用户类型,2全部用户 1指定手机号',
`message_type` int NOT NULL DEFAULT 2 COMMENT '消息类型,2系统消息 1会员消息 会员不做了 默认2',
`specify_type` int NOT NULL DEFAULT 2 COMMENT '用户类型,2全部用户 1指定手机号 指定手机不做了默认2',
`message_show_type` int NOT NULL DEFAULT 0 COMMENT '消息展示类型,2普通文本,1图文排版',
`show_content` text,
`pushed_by` varchar(255) NOT NULL DEFAULT '' COMMENT '推送者ID',
`pushed_name` varchar(255) NOT NULL DEFAULT '' COMMENT '推送者姓名',
`task_id` varchar(255) NOT NULL DEFAULT '' COMMENT '任务类消息(type为broadcast、groupcast、filecast、customizedcast且file_id不为空)返回',
`msg_id` varchar(255) NOT NULL DEFAULT '' COMMENT '单播类消息(type为unicast、listcast、customizedcast且不带file_id)返回',
`error_code` varchar(255) NOT NULL DEFAULT '' COMMENT '错误码',
`error_msg` varchar(255) NOT NULL DEFAULT '' COMMENT '错误信息',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
KEY `admin_upush_id_index` (`upush_id`),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment