Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

公众号消息推送标题优化 #366

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,13 @@
*/
public class PushPlusApi {


public static void sendNotice(IUser iUser, ILog operLog) {
public static void sendNotice(IUser iUser, ILog operLog, String title) {
String token = iUser.getPushPlusToken();
if (StringUtils.isEmpty(token)) {
return;
}
String title, content;
if (operLog.getStatus() == 0) {
//预约成功
title = iUser.getRemark() + "-i茅台执行成功";
content = iUser.getMobile() + System.lineSeparator() + operLog.getLogContent();
AsyncManager.me().execute(sendNotice(token, title, content, "txt"));
} else {
//预约失败
title = iUser.getRemark() + "-i茅台执行失败";
content = iUser.getMobile() + System.lineSeparator() + operLog.getLogContent();
AsyncManager.me().execute(sendNotice(token, title, content, "txt"));
}


String content = iUser.getMobile() + System.lineSeparator() + operLog.getLogContent();
AsyncManager.me().execute(sendNotice(token, title, content, "txt"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
public class IMTLogFactory {


public static void reservation(IUser iUser, String logContent) {
public static void reservation(IUser iUser, String logContent, String title) {
//{"code":2000,"data":{"successDesc":"申购完成,请于7月6日18:00查看预约申购结果","reservationList":[{"reservationId":17053404357,"sessionId":678,"shopId":"233331084001","reservationTime":1688608601720,"itemId":"10214","count":1}],"reservationDetail":{"desc":"申购成功后将以短信形式通知您,请您在申购成功次日18:00前确认支付方式,并在7天内完成提货。","lotteryTime":1688637600000,"cacheValidTime":1688637600000}}}
ILog operLog = new ILog();

operLog.setOperTime(new Date());

if (logContent.contains("报错")) {
//失败
operLog.setStatus(1);
Expand All @@ -30,10 +28,10 @@ public static void reservation(IUser iUser, String logContent) {
operLog.setMobile(iUser.getMobile());
operLog.setCreateUser(iUser.getCreateUser());
operLog.setLogContent(logContent);

// 日志记录
AsyncManager.me().execute(recordOper(operLog));
//推送
PushPlusApi.sendNotice(iUser, operLog);
// 消息推送
PushPlusApi.sendNotice(iUser, operLog, title);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,32 +186,28 @@ public void reservation(IUser iUser) {
String[] items = iUser.getItemCode().split("@");

String logContent = "";
String title = "";
for (String itemId : items) {
try {
String shopId = iShopService.getShopId(iUser.getShopType(), itemId,
iUser.getProvinceName(), iUser.getCityName(), iUser.getLat(), iUser.getLng());
//预约
JSONObject json = reservation(iUser, itemId, shopId);
title = "i茅台预约申购: 成功";
logContent += String.format("[预约项目]:%s\n[shopId]:%s\n[结果返回]:%s\n\n", itemId, shopId, json.toString());

//随机延迟3~5秒
Random random = new Random();
int sleepTime = random.nextInt(3) + 3;
Thread.sleep(sleepTime * 1000);
} catch (Exception e) {
title = "i茅台预约申购: 失败";
logContent += String.format("执行报错--[预约项目]:%s\n[结果返回]:%s\n\n", itemId, e.getMessage());
}
}

// try {
// //预约后领取耐力值
// String energyAward = getEnergyAward(iUser);
// logContent += "[申购耐力值]:" + energyAward;
// } catch (Exception e) {
// logContent += "执行报错--[申购耐力值]:" + e.getMessage();
// }
//日志记录
IMTLogFactory.reservation(iUser, logContent);
IMTLogFactory.reservation(iUser, logContent, title);
//预约后延迟领取耐力值
getEnergyAwardDelay(iUser);
}
Expand All @@ -226,17 +222,20 @@ public void getEnergyAwardDelay(IUser iUser) {
@Override
public void run() {
String logContent = "";
String title = "";
//sleep 10秒
try {
Thread.sleep(10000);
//预约后领取耐力值
String energyAward = getEnergyAward(iUser);
logContent += "[申购耐力值]:" + energyAward;
title = "i茅台申购领耐力: 成功";
} catch (Exception e) {
logContent += "执行报错--[申购耐力值]:" + e.getMessage();
title = "i茅台申购领耐力: 失败";
}
//日志记录
IMTLogFactory.reservation(iUser, logContent);
IMTLogFactory.reservation(iUser, logContent, title);
}
};
new Thread(runnable).start();
Expand Down Expand Up @@ -312,15 +311,18 @@ public String getEnergyAward(IUser iUser) {
@Override
public void getTravelReward(IUser iUser) {
String logContent = "";
String title = "";
try {
String s = travelReward(iUser);
logContent += "[获得旅行奖励]:" + s;
title = "i茅台小茅运旅行: 成功";
} catch (Exception e) {
// e.printStackTrace();
logContent += "执行报错--[获得旅行奖励]:" + e.getMessage();
title = "i茅台小茅运旅行: 失败";
}
//日志记录
IMTLogFactory.reservation(iUser, logContent);
IMTLogFactory.reservation(iUser, logContent, title);
}

/**
Expand Down Expand Up @@ -569,11 +571,20 @@ public void appointmentResults() {
}
for (Object itemVO : itemVOs) {
JSONObject item = JSON.parseObject(itemVO.toString());
// 预约时间在24小时内的
// 预约时间在24小时内的 成功
if (item.getInteger("status") == 2 && DateUtil.between(item.getDate("reservationTime"), new Date(), DateUnit.HOUR) < 24) {
String logContent = DateUtil.formatDate(item.getDate("reservationTime")) + " 申购" + item.getString("itemName") + "成功";
IMTLogFactory.reservation(iUser, logContent);
String title = "i茅台今日申购: 成功!!!";
IMTLogFactory.reservation(iUser, logContent, title);
}

// 预约时间在24小时内的 失败
if (item.getInteger("status") == 1 && DateUtil.between(item.getDate("reservationTime"), new Date(), DateUnit.HOUR) < 24) {
String logContent = DateUtil.formatDate(item.getDate("reservationTime")) + " 申购" + item.getString("itemName") + "失败";
String title = "i茅台今日申购: 失败";
IMTLogFactory.reservation(iUser, logContent, title);
}

}
} catch (Exception e) {
logger.error("查询申购结果失败:失败原因->{}", e.getMessage(), e);
Expand Down