From 9b8b9639c0a31337afd7a1585605e8e77858268b Mon Sep 17 00:00:00 2001
From: wangning <164851225@qq.com>
Date: Fri, 5 Jan 2018 18:03:01 +0800
Subject: [PATCH 6/8] update
---
.../com/royalpay/payment/manage/dev/bean/Message.java | 10 +++++++++-
src/main/ui/static/config/devtools/devtools.js | 1 -
.../static/config/devtools/templates/send_message.html | 4 ++--
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/bean/Message.java b/src/main/java/au/com/royalpay/payment/manage/dev/bean/Message.java
index 2ded3cb61..b4d3ce22c 100644
--- a/src/main/java/au/com/royalpay/payment/manage/dev/bean/Message.java
+++ b/src/main/java/au/com/royalpay/payment/manage/dev/bean/Message.java
@@ -16,7 +16,7 @@ public class Message {
public String title;
@NotEmpty(message = "content can not be null")
public String content;
-
+ public String client_type;
public JSONObject insertObject() {
JSONObject res = (JSONObject) JSON.toJSON(this);
return res;
@@ -53,4 +53,12 @@ public class Message {
public void setContent(String content) {
this.content = content;
}
+
+ public String getClient_type() {
+ return client_type;
+ }
+
+ public void setClient_type(String client_type) {
+ this.client_type = client_type;
+ }
}
diff --git a/src/main/ui/static/config/devtools/devtools.js b/src/main/ui/static/config/devtools/devtools.js
index 709fc4f53..cd653273d 100644
--- a/src/main/ui/static/config/devtools/devtools.js
+++ b/src/main/ui/static/config/devtools/devtools.js
@@ -216,7 +216,6 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) {
app.controller('devSendMessageCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) {
$scope.params = {type:'Merchant'};
- alert($scope.params.client_type);
$scope.sendMessage = function () {
var params = angular.copy($scope.params);
$http.put('/dev/send_message',params).then(function (resp) {
diff --git a/src/main/ui/static/config/devtools/templates/send_message.html b/src/main/ui/static/config/devtools/templates/send_message.html
index dc37ff46a..84aa5393b 100644
--- a/src/main/ui/static/config/devtools/templates/send_message.html
+++ b/src/main/ui/static/config/devtools/templates/send_message.html
@@ -34,8 +34,8 @@
From 0563d91d683ffe254093d8155ba84bc881131010 Mon Sep 17 00:00:00 2001
From: wangning <164851225@qq.com>
Date: Mon, 8 Jan 2018 17:54:11 +0800
Subject: [PATCH 7/8] update android msg
---
.../core/impls/RetailAppServiceImp.java | 157 ++++++++++--------
.../bean/AppManagerMessageBuilder.java | 25 +++
2 files changed, 117 insertions(+), 65 deletions(-)
create mode 100644 src/main/java/au/com/royalpay/payment/manage/pushMessage/bean/AppManagerMessageBuilder.java
diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java
index 0c8713957..782f3954a 100644
--- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java
+++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java
@@ -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 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());
@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) {
-
- }
}
diff --git a/src/main/java/au/com/royalpay/payment/manage/pushMessage/bean/AppManagerMessageBuilder.java b/src/main/java/au/com/royalpay/payment/manage/pushMessage/bean/AppManagerMessageBuilder.java
new file mode 100644
index 000000000..8e862ed67
--- /dev/null
+++ b/src/main/java/au/com/royalpay/payment/manage/pushMessage/bean/AppManagerMessageBuilder.java
@@ -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"));
+ }
+}
From ae5a21fc3c2d7b191819a93f8ed4a71d658d8148 Mon Sep 17 00:00:00 2001
From: wangning <164851225@qq.com>
Date: Mon, 8 Jan 2018 20:05:38 +0800
Subject: [PATCH 8/8] update
---
.../manage/pushMessage/bean/AppManagerMessageBuilder.java | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/main/java/au/com/royalpay/payment/manage/pushMessage/bean/AppManagerMessageBuilder.java b/src/main/java/au/com/royalpay/payment/manage/pushMessage/bean/AppManagerMessageBuilder.java
index 8e862ed67..f008f7d6d 100644
--- a/src/main/java/au/com/royalpay/payment/manage/pushMessage/bean/AppManagerMessageBuilder.java
+++ b/src/main/java/au/com/royalpay/payment/manage/pushMessage/bean/AppManagerMessageBuilder.java
@@ -5,12 +5,9 @@ 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;