update android msg

master
wangning 7 years ago
parent 9b8b9639c0
commit 0563d91d68

@ -5,10 +5,13 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -59,6 +62,7 @@ import au.com.royalpay.payment.manage.notice.core.NoticeManage;
import au.com.royalpay.payment.manage.notice.core.NoticePartner;
import au.com.royalpay.payment.manage.pushMessage.APNSMessageHelper;
import au.com.royalpay.payment.manage.pushMessage.JpushMessageHelper;
import au.com.royalpay.payment.manage.pushMessage.bean.AppManagerMessageBuilder;
import au.com.royalpay.payment.manage.pushMessage.bean.JpushMessage;
import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
@ -66,6 +70,8 @@ import au.com.royalpay.payment.manage.signin.core.impls.SignInAccountServiceImpl
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery;
import au.com.royalpay.payment.tools.cms.RoyalPayCMSSupport;
import au.com.royalpay.payment.tools.device.DeviceSupport;
import au.com.royalpay.payment.tools.device.message.AppMessage;
import au.com.royalpay.payment.tools.device.message.AppMsgSender;
import au.com.royalpay.payment.tools.device.support.DeviceRegister;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
@ -77,9 +83,6 @@ import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
import au.com.royalpay.payment.tools.utils.PageListUtils;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.model.PushPayload;
/**
* Created by yishuqian on 28/03/2017.
*/
@ -135,6 +138,13 @@ public class RetailAppServiceImp implements RetailAppService {
@Resource
private JpushMessageHelper jpushMessageHelper;
private Map<String, AppMsgSender> senderMap = new HashMap<>();
@Resource
public void setAppMsgSenders(AppMsgSender[] senders) {
Arrays.stream(senders).forEach(appMsgSender -> senderMap.put(appMsgSender.devType(), appMsgSender));
}
private ThreadPoolExecutor sendingAppleMsgPool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@Resource
@ -461,7 +471,6 @@ public class RetailAppServiceImp implements RetailAppService {
return;
}
System.out.println("Device Token" + token);
// todo 抽象发送信息接口,根据设备类型选择不同实现类
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "payment", token,
order.getString("order_id"));
try {
@ -469,22 +478,25 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "payment");
type.put("id", order.getString("order_id"));
if ("iphone".equals(devToken.getString("client_type"))) {
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.payment"),
LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount"),
token, order, type);
}
if ("android".equals(devToken.getString("client_type"))) {
jpushMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.payment"),
LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount"),
token, order, type);
AppMsgSender sender = senderMap.get(devToken.getString("client_type"));
if (token == null || sender == null) {
return;
}
JSONObject managerMsg = new JSONObject();
managerMsg.put("title", LocaleSupport.localeMessage("app.message.title.payment"));
managerMsg.put("body",
LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount"));
managerMsg.put("type", type);
managerMsg.put("data", order);
managerMsg.put("msgType", "payment");
AppMessage appMessage = new AppManagerMessageBuilder(managerMsg).buildMessage();
sender.sendMessage(appMessage, devToken);
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App JpushMessage Failed", e);
throw new ServerErrorException("Send App "+devToken.getString("client_type")+" Failed", e);
}
};
sendingAppleMsgPool.execute(task);
@ -522,14 +534,19 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "refund");
type.put("id", order.getString("order_id"));
if ("iphone".equals(devToken.getString("client_type"))) {
apnsMessageHelper.sendAppleMessage("Refund JpushMessage", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount,
token, order, type);
}
if ("android".equals(devToken.getString("client_type"))) {
jpushMessageHelper.sendAppleMessage("Refund JpushMessage", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount,
token, order, type);
AppMsgSender sender = senderMap.get(devToken.getString("client_type"));
if (token == null || sender == null) {
return;
}
JSONObject managerMsg = new JSONObject();
managerMsg.put("title", "Refund "+devToken.getString("client_type")+"");
managerMsg.put("body", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount);
managerMsg.put("type", type);
managerMsg.put("data", order);
managerMsg.put("msgType", "refund");
AppMessage appMessage = new AppManagerMessageBuilder(managerMsg).buildMessage();
sender.sendMessage(appMessage, devToken);
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
@ -562,15 +579,19 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "notice");
type.put("id", notice.getNotice_id());
if ("iphone".equals(devToken.getString("client_type"))) {
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"), notice.getTitle(), token, noticeObj,
type);
}
if ("android".equals(devToken.getString("client_type"))) {
jpushMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"), notice.getTitle(), token,
noticeObj, type);
}
AppMsgSender sender = senderMap.get(devToken.getString("client_type"));
if (token == null || sender == null) {
return;
}
JSONObject managerMsg = new JSONObject();
managerMsg.put("title", LocaleSupport.localeMessage("app.message.title.notice"));
managerMsg.put("body", notice.getTitle());
managerMsg.put("type", type);
managerMsg.put("data", noticeObj);
managerMsg.put("msgType", "notice");
AppMessage appMessage = new AppManagerMessageBuilder(managerMsg).buildMessage();
sender.sendMessage(appMessage, devToken);
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
@ -601,25 +622,26 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "cashback");
type.put("id", order.getString("order_id"));
if ("iphone".equals(devToken.getString("client_type"))) {
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"),
LocaleSupport.localeMessage("app.message.body.cashback") + PlatformEnvironment.getEnv().getForeignCurrency() + " "
+ cashbackAmount,
token, order, type);
}
if ("android".equals(devToken.getString("client_type"))) {
jpushMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"),
LocaleSupport.localeMessage("app.message.body.cashback") + PlatformEnvironment.getEnv().getForeignCurrency() + " "
+ cashbackAmount,
token, order, type);
AppMsgSender sender = senderMap.get(devToken.getString("client_type"));
if (token == null || sender == null) {
return;
}
JSONObject managerMsg = new JSONObject();
managerMsg.put("title", LocaleSupport.localeMessage("app.message.title.notice"));
managerMsg.put("body", LocaleSupport.localeMessage("app.message.body.cashback") + PlatformEnvironment.getEnv().getForeignCurrency()
+ " " + cashbackAmount);
managerMsg.put("type", type);
managerMsg.put("data", order);
managerMsg.put("msgType", "cashback");
AppMessage appMessage = new AppManagerMessageBuilder(managerMsg).buildMessage();
sender.sendMessage(appMessage, devToken);
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App JpushMessage Failed", e);
throw new ServerErrorException("Send App "+devToken.getString("client_type")+" Failed", e);
}
}
});
@ -647,26 +669,26 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "clean");
type.put("id", log_clearing_detail_id);
if ("iphone".equals(devToken.getString("client_type"))) {
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.clean"),
LocaleSupport.localeMessage("app.message.body.clean") + PlatformEnvironment.getEnv().getForeignCurrency() + " " + clearing_amount
+ " (" + settle_date_from + "-" + settle_date_to + ")",
token, log_clearing_detail, type);
}
if ("android".equals(devToken.getString("client_type"))) {
jpushMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.clean"),
LocaleSupport.localeMessage("app.message.body.clean") + PlatformEnvironment.getEnv().getForeignCurrency() + " " + clearing_amount
+ " (" + settle_date_from + "-" + settle_date_to + ")",
token, log_clearing_detail, type);
AppMsgSender sender = senderMap.get(devToken.getString("client_type"));
if (token == null || sender == null) {
return;
}
JSONObject managerMsg = new JSONObject();
managerMsg.put("title", LocaleSupport.localeMessage("app.message.title.clean"));
managerMsg.put("body", LocaleSupport.localeMessage("app.message.body.clean") + PlatformEnvironment.getEnv().getForeignCurrency() + " "
+ clearing_amount + " (" + settle_date_from + "-" + settle_date_to + ")");
managerMsg.put("type", type);
managerMsg.put("data", log_clearing_detail);
managerMsg.put("msgType", "clean");
AppMessage appMessage = new AppManagerMessageBuilder(managerMsg).buildMessage();
sender.sendMessage(appMessage, devToken);
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App JpushMessage Failed", e);
throw new ServerErrorException("Send App "+devToken.getString("client_type")+" Failed", e);
}
}
}
@ -698,7 +720,7 @@ public class RetailAppServiceImp implements RetailAppService {
} catch (Exception e) {
logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App JpushMessage Failed", e);
throw new ServerErrorException("Send App "+devToken.getString("client_type")+" Failed", e);
}
}
}
@ -1123,25 +1145,33 @@ public class RetailAppServiceImp implements RetailAppService {
throw new ServerErrorException(s.getMessage());
} catch (Exception e) {
logger.error("出错了:" + e.getMessage());
throw new ServerErrorException("Send App JpushMessage Failed", e);
throw new ServerErrorException("Send App Message Failed", e);
}
}
public void sending(String devToken, JSONObject params, JSONObject log) {
try {
if ("iphone".equals(params.getString("client_type"))) {
apnsMessageHelper.sendAppleMessage(params.getString("title"), params.getString("content"), devToken, new JSONObject(), new JSONObject());
}
if ("android".equals(params.getString("client_type"))) {
jpushMessageHelper.sendAppleMessage(params.getString("title"), params.getString("content"), devToken, new JSONObject(), new JSONObject());
JSONObject devTokenJson = new JSONObject();
devTokenJson.put("token", devToken);
AppMsgSender sender = senderMap.get(params.getString("client_type"));
if (devToken == null || sender == null) {
return;
}
JSONObject managerMsg = new JSONObject();
managerMsg.put("title", params.getString("title"));
managerMsg.put("body", params.getString("content"));
managerMsg.put("type", new JSONObject());
managerMsg.put("data", new JSONObject());
managerMsg.put("msgType", "payment");
AppMessage appMessage = new AppManagerMessageBuilder(managerMsg).buildMessage();
sender.sendMessage(appMessage, devTokenJson);
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App JpushMessage Failed", e);
throw new ServerErrorException("Send App "+params.getString("client_type")+" Failed", e);
}
}
@ -1205,7 +1235,4 @@ public class RetailAppServiceImp implements RetailAppService {
return str.matches(regex);
}
private void sendJpush(int client_id, JpushMessage message) {
}
}

@ -0,0 +1,25 @@
package au.com.royalpay.payment.manage.pushMessage.bean;
import au.com.royalpay.payment.tools.device.message.AppMessage;
import au.com.royalpay.payment.tools.device.message.AppMessageBuilder;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;
/**
* Created by wangning on 08/01/2018.
*/
@Service
public class AppManagerMessageBuilder implements AppMessageBuilder {
private JSONObject managerMsg;
public AppManagerMessageBuilder(JSONObject managerMsg) {
this.managerMsg = managerMsg;
}
@Override
public AppMessage buildMessage() {
return new AppMessage(managerMsg.getString("msgType"), managerMsg.getString("title"), managerMsg.getString("body")).setTypeData(managerMsg.getJSONObject("type")).setData(managerMsg.getJSONObject("data"));
}
}
Loading…
Cancel
Save