Merge branch 'Jpush' into develop

master
wangning 7 years ago
commit c84bb59102

@ -132,6 +132,21 @@
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> <artifactId>druid</artifactId>
</dependency> </dependency>
<!--jpush start -->
<dependency>
<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<!--jpush end -->
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

@ -32,8 +32,6 @@ public interface RetailAppService {
void sign_out(JSONObject device); void sign_out(JSONObject device);
void sendAppMessage();
void sendOrderAppMessage(JSONObject order, int client_id); void sendOrderAppMessage(JSONObject order, int client_id);
void sendRefundAppMessage(String refundAmount, JSONObject order); void sendRefundAppMessage(String refundAmount, JSONObject order);

@ -1,5 +1,42 @@
package au.com.royalpay.payment.manage.appclient.core.impls; package au.com.royalpay.payment.manage.appclient.core.impls;
import java.math.BigDecimal;
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;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import au.com.royalpay.payment.core.PaymentApi; import au.com.royalpay.payment.core.PaymentApi;
import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper; import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper;
import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper; import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper;
@ -14,17 +51,27 @@ import au.com.royalpay.payment.manage.mappers.log.ClearingDetailAnalysisMapper;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper; import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper;
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper; import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.system.*; import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientDeviceTokenMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientSettleDelayConfMapper;
import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
import au.com.royalpay.payment.manage.mappers.system.CustomerRelationAlipayMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.notice.beans.NoticeInfo; import au.com.royalpay.payment.manage.notice.beans.NoticeInfo;
import au.com.royalpay.payment.manage.notice.core.NoticeManage; import au.com.royalpay.payment.manage.notice.core.NoticeManage;
import au.com.royalpay.payment.manage.notice.core.NoticePartner; 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.beans.ChangePwdBean;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.signin.core.impls.SignInAccountServiceImpl; import au.com.royalpay.payment.manage.signin.core.impls.SignInAccountServiceImpl;
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery; import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery;
import au.com.royalpay.payment.tools.cms.RoyalPayCMSSupport; import au.com.royalpay.payment.tools.cms.RoyalPayCMSSupport;
import au.com.royalpay.payment.tools.device.DeviceSupport; 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.device.support.DeviceRegister;
import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
@ -35,37 +82,6 @@ import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
import au.com.royalpay.payment.tools.permission.enums.PartnerRole; import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
import au.com.royalpay.payment.tools.utils.PageListUtils; import au.com.royalpay.payment.tools.utils.PageListUtils;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils; import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* Created by yishuqian on 28/03/2017. * Created by yishuqian on 28/03/2017.
@ -77,77 +93,64 @@ public class RetailAppServiceImp implements RetailAppService {
private TransactionAnalysisMapper transactionAnalysisMapper; private TransactionAnalysisMapper transactionAnalysisMapper;
@Resource @Resource
private TransactionMapper transactionMapper; private TransactionMapper transactionMapper;
@Resource @Resource
private ClientManager clientManager; private ClientManager clientManager;
@Resource @Resource
private NoticeManage noticeManage; private NoticeManage noticeManage;
@Resource @Resource
private NoticePartner noticePartner; private NoticePartner noticePartner;
@Resource @Resource
private CustomerAndOrdersStatisticsMapper customerAndOrdersStatisticsMapper; private CustomerAndOrdersStatisticsMapper customerAndOrdersStatisticsMapper;
@Resource @Resource
private ClearingDetailMapper clearingDetailMapper; private ClearingDetailMapper clearingDetailMapper;
@Resource @Resource
private OrderMapper orderMapper; private OrderMapper orderMapper;
@Resource @Resource
private ClientAccountMapper clientAccountMapper; private ClientAccountMapper clientAccountMapper;
@Resource @Resource
private AppMessageLogMapper appMessageLogMapper; private AppMessageLogMapper appMessageLogMapper;
@Resource @Resource
private SignInAccountService signInAccountService; private SignInAccountService signInAccountService;
@Resource @Resource
private CashbackService cashbackService; private CashbackService cashbackService;
@Resource @Resource
private ClearingDetailAnalysisMapper clearingDetailAnalysisMapper; private ClearingDetailAnalysisMapper clearingDetailAnalysisMapper;
@Resource @Resource
private ClientSettleDelayConfMapper clientSettleDelayConfMapper; private ClientSettleDelayConfMapper clientSettleDelayConfMapper;
@Resource @Resource
private XPlanFundConfigServiceImpl xPlanFundConfigService; private XPlanFundConfigServiceImpl xPlanFundConfigService;
@Resource @Resource
private MerchantInfoProvider merchantInfoProvider; private MerchantInfoProvider merchantInfoProvider;
@Resource @Resource
private RoyalPayCMSSupport royalPayCMSSupport; private RoyalPayCMSSupport royalPayCMSSupport;
@Resource @Resource
private PaymentApi paymentApi; private PaymentApi paymentApi;
@Resource @Resource
private DeviceSupport deviceSupport; private DeviceSupport deviceSupport;
@Resource @Resource
private CustomerRelationAlipayMapper customerRelationAlipayMapper; private CustomerRelationAlipayMapper customerRelationAlipayMapper;
@Resource @Resource
private CustomerMapper customerMapper; private CustomerMapper customerMapper;
@Resource
@Value("classpath:apple_message_cert_dev.p12") private APNSMessageHelper apnsMessageHelper;
private org.springframework.core.io.Resource appleMessageFileDev;
@Value("classpath:apple_message_cert_product.p12")
private org.springframework.core.io.Resource appleMessageFileProduct;
@Value("${apple.message.apns.password}")
private String appleMessagePassword;
@Resource @Resource
private ClientDeviceTokenMapper clientDeviceTokenMapper; private ClientDeviceTokenMapper clientDeviceTokenMapper;
@Resource
private JpushMessageHelper jpushMessageHelper;
private ThreadPoolExecutor sendingAppleMsgPool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); 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 @Resource
private CouponValidateService couponVerificationService; private CouponValidateService couponVerificationService;
//若app未传client_ids,检测是否包含子商户,若包含查询全部 // 若app未传client_ids,检测是否包含子商户,若包含查询全部
private void setAllClientIds(JSONObject params, int clientId) { private void setAllClientIds(JSONObject params, int clientId) {
if (params.containsKey("client_ids")) { if (params.containsKey("client_ids")) {
return; return;
@ -175,10 +178,10 @@ public class RetailAppServiceImp implements RetailAppService {
params.put("client_id", client_id); params.put("client_id", client_id);
res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params)); res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params));
res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params)); res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params));
// res.put("refund_amount", transactionAnalysisMapper.analysisRefundAmount(params)); // res.put("refund_amount", transactionAnalysisMapper.analysisRefundAmount(params));
res.put("not_settled", transactionAnalysisMapper.analysisNotSettled(params)); res.put("not_settled", transactionAnalysisMapper.analysisNotSettled(params));
res.put("old_customers", transactionAnalysisMapper.countOldCustomers(params)); res.put("old_customers", transactionAnalysisMapper.countOldCustomers(params));
//微信小程序不查询汇率 // 微信小程序不查询汇率
if (!StringUtils.equals(device.getString("client_type"), "wxapp")) { if (!StringUtils.equals(device.getString("client_type"), "wxapp")) {
res.put("rate", paymentApi.channelApi("Wechat").queryExchangeRateDecimal(client_id)); res.put("rate", paymentApi.channelApi("Wechat").queryExchangeRateDecimal(client_id));
} }
@ -266,7 +269,6 @@ public class RetailAppServiceImp implements RetailAppService {
} }
} }
@Override @Override
public JSONObject getClientSettlementLog(JSONObject device, AppQueryBean appQueryBean) { public JSONObject getClientSettlementLog(JSONObject device, AppQueryBean appQueryBean) {
String clientType = device.getString("client_type"); String clientType = device.getString("client_type");
@ -280,7 +282,8 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject params = appQueryBean.toParams(); JSONObject params = appQueryBean.toParams();
setAllClientIds(params, client_id); setAllClientIds(params, client_id);
params.put("client_id", client_id); params.put("client_id", client_id);
PageList<JSONObject> logs = clearingDetailMapper.listClientSettlementLog(params, new PageBounds(appQueryBean.getPage(), appQueryBean.getLimit(), Order.formString("report_date.desc"))); PageList<JSONObject> logs = clearingDetailMapper.listClientSettlementLog(params,
new PageBounds(appQueryBean.getPage(), appQueryBean.getLimit(), Order.formString("report_date.desc")));
return PageListUtils.buildPageListResult(logs); return PageListUtils.buildPageListResult(logs);
} }
@ -354,11 +357,13 @@ public class RetailAppServiceImp implements RetailAppService {
params.put("dev_id", device.getString("dev_id")); params.put("dev_id", device.getString("dev_id"));
} }
params.put("client_id", client_id); params.put("client_id", client_id);
PageList<JSONObject> orders = orderMapper.listOrdersByClients(params, new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc"))); PageList<JSONObject> orders = orderMapper.listOrdersByClients(params,
new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
TimeZoneUtils.switchTimeZone(orders, query.getTimezone(), "create_time", "transaction_time", "confirm_time"); TimeZoneUtils.switchTimeZone(orders, query.getTimezone(), "create_time", "transaction_time", "confirm_time");
ArrayList<String> date_contains = new ArrayList<>(); ArrayList<String> date_contains = new ArrayList<>();
for (JSONObject order : orders) { for (JSONObject order : orders) {
// Date tradeDate = order.getDate("confirm_time") == null ? (order.getDate("transaction_time") == null ? order.getDate("create_time") : order.getDate("transaction_time")) : order.getDate("confirm_time"); // Date tradeDate = order.getDate("confirm_time") == null ? (order.getDate("transaction_time") == null ?
// order.getDate("create_time") : order.getDate("transaction_time")) : order.getDate("confirm_time");
Calendar calendar = (Calendar) order.get("create_time"); Calendar calendar = (Calendar) order.get("create_time");
String trade_date = DateFormatUtils.format(calendar, "yyyy-MM-dd"); String trade_date = DateFormatUtils.format(calendar, "yyyy-MM-dd");
String trade_time = DateFormatUtils.format(calendar, "HH:mm:ss"); String trade_time = DateFormatUtils.format(calendar, "HH:mm:ss");
@ -369,7 +374,7 @@ public class RetailAppServiceImp implements RetailAppService {
TradeLogQuery date_query = new TradeLogQuery(); TradeLogQuery date_query = new TradeLogQuery();
date_query.setDatefrom(re_date); date_query.setDatefrom(re_date);
date_query.setDateto(re_date); date_query.setDateto(re_date);
// date_query.setStatus(OrderStatus.ALL); // date_query.setStatus(OrderStatus.ALL);
if (params.containsKey("client_ids")) { if (params.containsKey("client_ids")) {
date_query.setClient_ids((String[]) params.get("client_ids")); date_query.setClient_ids((String[]) params.get("client_ids"));
} }
@ -388,7 +393,7 @@ public class RetailAppServiceImp implements RetailAppService {
query.setGateway_app("11"); query.setGateway_app("11");
String clientType = device.getString("client_type"); String clientType = device.getString("client_type");
DeviceRegister register = deviceSupport.findRegister(clientType); DeviceRegister register = deviceSupport.findRegister(clientType);
Assert.notNull(register,"Device is not registered"); Assert.notNull(register, "Device is not registered");
int client_id = device.getIntValue("client_id"); int client_id = device.getIntValue("client_id");
JSONObject client = clientManager.getClientInfo(client_id); JSONObject client = clientManager.getClientInfo(client_id);
String timezone = client.getString("timezone"); String timezone = client.getString("timezone");
@ -455,31 +460,6 @@ public class RetailAppServiceImp implements RetailAppService {
} }
@Override
public void sendAppMessage() {
// String p12Path = "D:/MbaikeDevCertificates.p12";
// InputStream keyIns = appleMessageFile.getInputStream();
// String password = "F1b5*ChJPp73";
String pushToken = "719e4b7a7ed8b9000188440228437714d9dc67785f1791fae01234dae6a1570c";
JSONObject order = new JSONObject();
order.put("clearing_amount", 0.01);
order.put("client_id", 9);
order.put("client_moniker", "PINE");
order.put("order_id", "9201704110348156694986");
try {
/**设置参数,发送数据**/
InputStream keyIns = appleMessageFileProduct.getInputStream();
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle("到账通知").alertBody("Hello,0.01AUD").badge(1).sound("default").customField("data", order).build();
service.push(pushToken, payload);
System.out.println("推送信息已发送!");
} catch (Exception e) {
logger.error("出错了:" + e.getMessage());
}
}
@Override @Override
public void sendOrderAppMessage(final JSONObject order, int client_id) { public void sendOrderAppMessage(final JSONObject order, int client_id) {
logger.debug("sendOrderAppMessage-" + client_id + "-" + order.getString("order_id")); logger.debug("sendOrderAppMessage-" + client_id + "-" + order.getString("order_id"));
@ -491,21 +471,32 @@ public class RetailAppServiceImp implements RetailAppService {
return; return;
} }
System.out.println("Device Token" + token); System.out.println("Device Token" + token);
//todo 抽象发送信息接口,根据设备类型选择不同实现类 JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "payment", token,
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "payment", token, order.getString("order_id")); order.getString("order_id"));
try { try {
order.put("send_type", "payment"); order.put("send_type", "payment");
JSONObject type = new JSONObject(); JSONObject type = new JSONObject();
type.put("send_type", "payment"); type.put("send_type", "payment");
type.put("id", order.getString("order_id")); type.put("id", order.getString("order_id"));
sendAppleMessage(LocaleSupport.localeMessage("app.message.title.payment"), AppMsgSender sender = senderMap.get(devToken.getString("client_type"));
LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount"), token, order, 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); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
logger.error("出错了:" + e.getMessage()); logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage()); appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App Message Failed", e); throw new ServerErrorException("Send App "+devToken.getString("client_type")+" Failed", e);
} }
}; };
sendingAppleMsgPool.execute(task); sendingAppleMsgPool.execute(task);
@ -536,14 +527,26 @@ public class RetailAppServiceImp implements RetailAppService {
return; return;
} }
System.out.println("Device Token" + token); System.out.println("Device Token" + token);
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "refund", token, order.getString("order_id")); JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "refund", token,
order.getString("order_id"));
try { try {
order.put("send_type", "refund"); order.put("send_type", "refund");
JSONObject type = new JSONObject(); JSONObject type = new JSONObject();
type.put("send_type", "refund"); type.put("send_type", "refund");
type.put("id", order.getString("order_id")); type.put("id", order.getString("order_id"));
sendAppleMessage("Refund Message",
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); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
@ -567,7 +570,8 @@ public class RetailAppServiceImp implements RetailAppService {
if (token == null) { if (token == null) {
continue; continue;
} }
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "notice", token, "notice_id:" + notice.getNotice_id()); JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "notice", token,
"notice_id:" + notice.getNotice_id());
try { try {
notice.setContent(null); notice.setContent(null);
JSONObject noticeObj = notice.toJson(); JSONObject noticeObj = notice.toJson();
@ -575,7 +579,19 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject(); JSONObject type = new JSONObject();
type.put("send_type", "notice"); type.put("send_type", "notice");
type.put("id", notice.getNotice_id()); type.put("id", notice.getNotice_id());
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); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
@ -600,19 +616,32 @@ public class RetailAppServiceImp implements RetailAppService {
if (token == null) { if (token == null) {
return; return;
} }
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "cashback", token, order.getString("order_id") + "返现" + cashbackAmount); JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "cashback", token,
order.getString("order_id") + "返现" + cashbackAmount);
try { try {
JSONObject type = new JSONObject(); JSONObject type = new JSONObject();
type.put("send_type", "cashback"); type.put("send_type", "cashback");
type.put("id", order.getString("order_id")); type.put("id", order.getString("order_id"));
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); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
logger.error("出错了:" + e.getMessage()); logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage()); appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App Message Failed", e); throw new ServerErrorException("Send App "+devToken.getString("client_type")+" Failed", e);
} }
} }
}); });
@ -625,7 +654,8 @@ public class RetailAppServiceImp implements RetailAppService {
String clearing_amount = log_clearing_detail.getBigDecimal("clearing_amount").setScale(2, BigDecimal.ROUND_HALF_DOWN).toString(); String clearing_amount = log_clearing_detail.getBigDecimal("clearing_amount").setScale(2, BigDecimal.ROUND_HALF_DOWN).toString();
String settle_date_from = DateFormatUtils.format(log_clearing_detail.getDate("settle_date_from"), "MM/dd/yyyy"); String settle_date_from = DateFormatUtils.format(log_clearing_detail.getDate("settle_date_from"), "MM/dd/yyyy");
String settle_date_to = DateFormatUtils.format(log_clearing_detail.getDate("settle_date_to"), "MM/dd/yyyy"); String settle_date_to = DateFormatUtils.format(log_clearing_detail.getDate("settle_date_to"), "MM/dd/yyyy");
logger.debug("sendCleanMessage-" + log_clearing_detail.getString("client_moniker") + "- " + PlatformEnvironment.getEnv().getForeignCurrency() + " " + clearing_amount + "(" + settle_date_from + "-" + settle_date_to + ")"); logger.debug("sendCleanMessage-" + log_clearing_detail.getString("client_moniker") + "- " + PlatformEnvironment.getEnv().getForeignCurrency() + " "
+ clearing_amount + "(" + settle_date_from + "-" + settle_date_to + ")");
List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByClient_id(client_id); List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByClient_id(client_id);
for (JSONObject devToken : tokens) { for (JSONObject devToken : tokens) {
String token = devToken.getString("token"); String token = devToken.getString("token");
@ -633,24 +663,36 @@ public class RetailAppServiceImp implements RetailAppService {
continue; continue;
} }
String log_clearing_detail_id = log_clearing_detail.getString("clear_detail_id"); String log_clearing_detail_id = log_clearing_detail.getString("clear_detail_id");
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "clean", token, "本次清算" + log_clearing_detail_id + ",$" + clearing_amount + "(" + settle_date_from + "-" + settle_date_to + ")"); JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "clean", token,
"本次清算" + log_clearing_detail_id + ",$" + clearing_amount + "(" + settle_date_from + "-" + settle_date_to + ")");
try { try {
JSONObject type = new JSONObject(); JSONObject type = new JSONObject();
type.put("send_type", "clean"); type.put("send_type", "clean");
type.put("id", log_clearing_detail_id); type.put("id", log_clearing_detail_id);
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); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
logger.error("出错了:" + e.getMessage()); logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage()); appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App Message Failed", e); throw new ServerErrorException("Send App "+devToken.getString("client_type")+" Failed", e);
} }
} }
} }
@Override @Override
public void sendTransactionDailyMessage(JSONObject tradeInfo, int client_id) { public void sendTransactionDailyMessage(JSONObject tradeInfo, int client_id) {
String trade_date = tradeInfo.getString("trade_date"); String trade_date = tradeInfo.getString("trade_date");
@ -663,51 +705,26 @@ public class RetailAppServiceImp implements RetailAppService {
if (token == null) { if (token == null) {
continue; continue;
} }
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "daily_notice", token, "Trade Date:" + trade_date); JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "daily_notice", token,
"Trade Date:" + trade_date);
try { try {
JSONObject type = new JSONObject(); JSONObject type = new JSONObject();
type.put("send_type", "daily_notice"); type.put("send_type", "daily_notice");
type.put("id", trade_date); type.put("id", trade_date);
sendAppleMessageDetail(LocaleSupport.localeMessage("app.message.title.daily_notice"), apnsMessageHelper.sendAppleMessageDetail(
trade_date + ": 总交易额 " + PlatformEnvironment.getEnv().getForeignCurrency() + total_amount + ", 订单数:" + total_orders + ", 付款人数:" + customers, token, tradeInfo, type); LocaleSupport.localeMessage("app.message.title.daily_notice"), trade_date + ": 总交易额 "
+ PlatformEnvironment.getEnv().getForeignCurrency() + total_amount + ", 订单数:" + total_orders + ", 付款人数:" + customers,
token, tradeInfo, type);
log.put("status", 2); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
logger.error("出错了:" + e.getMessage()); logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage()); appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App Message Failed", e); throw new ServerErrorException("Send App "+devToken.getString("client_type")+" Failed", e);
} }
} }
} }
private void sendAppleMessage(String title, String body, String token, JSONObject data, JSONObject type) throws IOException {
/**设置参数,发送数据**/
InputStream keyIns = appleMessageFileProduct.getInputStream();
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle(title).alertBody(body).badge(1).sound("default").customField("data", data).customField("type", type).build();
service.push(token, payload);
System.out.println("推送信息已发送!");
}
/**
*
*
* @param title
* @param body
* @param token
* @param data
* @param type
* @throws IOException
*/
private void sendAppleMessageDetail(String title, String body, String token, JSONObject data, JSONObject type) throws IOException {
/**设置参数,发送数据**/
InputStream keyIns = appleMessageFileProduct.getInputStream();
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle(title).alertBody(body).category("myNotificationCategory").badge(1).sound("default").customField("data", data).customField("type", type).build();
service.push(token, payload);
System.out.println("推送信息已发送!");
}
@Override @Override
public void updateReadStatus(JSONObject device, String noticeId) { public void updateReadStatus(JSONObject device, String noticeId) {
String clientType = device.getString("client_type"); String clientType = device.getString("client_type");
@ -747,7 +764,7 @@ public class RetailAppServiceImp implements RetailAppService {
Document doc = Jsoup.parse(res.getString("content")); Document doc = Jsoup.parse(res.getString("content"));
String father = "<div style=\"padding:0 10px\"></div>"; String father = "<div style=\"padding:0 10px\"></div>";
String html = doc.body().children().wrap(father).html(); String html = doc.body().children().wrap(father).html();
// logger.debug("wrapped html---->"+html); // logger.debug("wrapped html---->"+html);
res.put("content", doc.html()); res.put("content", doc.html());
return res; return res;
} }
@ -756,7 +773,7 @@ public class RetailAppServiceImp implements RetailAppService {
public void changeAccountPassword(JSONObject device, ChangePwdBean change, String account_id) { public void changeAccountPassword(JSONObject device, ChangePwdBean change, String account_id) {
String clientType = device.getString("client_type"); String clientType = device.getString("client_type");
deviceSupport.findRegister(clientType); deviceSupport.findRegister(clientType);
//JSONObject client = signInAccountService.getClient(account_id); // JSONObject client = signInAccountService.getClient(account_id);
if (!account_id.equals(device.getString("account_id"))) { if (!account_id.equals(device.getString("account_id"))) {
throw new ForbiddenException("You have no permission"); throw new ForbiddenException("You have no permission");
} }
@ -779,7 +796,7 @@ public class RetailAppServiceImp implements RetailAppService {
Date now = new Date(); Date now = new Date();
JSONObject res = merchantInfoProvider.clientCurrentRate(clientId, now, "Wechat"); JSONObject res = merchantInfoProvider.clientCurrentRate(clientId, now, "Wechat");
JSONObject client = clientManager.getClientInfo(clientId); JSONObject client = clientManager.getClientInfo(clientId);
Assert.notNull(client,"Client is null"); Assert.notNull(client, "Client is null");
JSONObject[] channels = new JSONObject[3]; JSONObject[] channels = new JSONObject[3];
@ -804,7 +821,7 @@ public class RetailAppServiceImp implements RetailAppService {
Date now = new Date(); Date now = new Date();
JSONObject res = merchantInfoProvider.clientCurrentRate(clientId, now, "Wechat"); JSONObject res = merchantInfoProvider.clientCurrentRate(clientId, now, "Wechat");
JSONObject client = clientManager.getClientInfo(clientId); JSONObject client = clientManager.getClientInfo(clientId);
Assert.notNull(client,"Client is null"); Assert.notNull(client, "Client is null");
ArrayList<JSONObject> channels = new ArrayList<>(); ArrayList<JSONObject> channels = new ArrayList<>();
if (client.getBigDecimal("customer_surcharge_rate") != null) { if (client.getBigDecimal("customer_surcharge_rate") != null) {
@ -889,7 +906,7 @@ public class RetailAppServiceImp implements RetailAppService {
} }
res.put("data", new_acts); res.put("data", new_acts);
} }
//手续费返还活动 // 手续费返还活动
List<JSONObject> acts = (List<JSONObject>) res.get("data"); List<JSONObject> acts = (List<JSONObject>) res.get("data");
for (JSONObject act : acts) { for (JSONObject act : acts) {
if (StringUtils.isNotBlank(act.getString("page_keywords")) && act.getString("page_keywords").equalsIgnoreCase("native")) { if (StringUtils.isNotBlank(act.getString("page_keywords")) && act.getString("page_keywords").equalsIgnoreCase("native")) {
@ -923,7 +940,7 @@ public class RetailAppServiceImp implements RetailAppService {
String newAppVersion = PlatformEnvironment.getEnv().getNewVersion(); String newAppVersion = PlatformEnvironment.getEnv().getNewVersion();
Boolean isUpdate = PlatformEnvironment.getEnv().isAppUpdate(); Boolean isUpdate = PlatformEnvironment.getEnv().isAppUpdate();
String updateContent = PlatformEnvironment.getEnv().getAppUpdateContent(); String updateContent = PlatformEnvironment.getEnv().getAppUpdateContent();
int update_type = 0;//0:不更新 1更新 2强制更新 int update_type = 0;// 0:不更新 1更新 2强制更新
if (newAppVersion.compareToIgnoreCase(version) > 0) { if (newAppVersion.compareToIgnoreCase(version) > 0) {
update_type = 1; update_type = 1;
if (isUpdate) { if (isUpdate) {
@ -943,7 +960,6 @@ public class RetailAppServiceImp implements RetailAppService {
return clientManager.listSubClients(device.getIntValue("client_id")); return clientManager.listSubClients(device.getIntValue("client_id"));
} }
private JSONObject saveAppMessageLog(String dev_id, int client_id, String messageType, String dev_token, String remark) { private JSONObject saveAppMessageLog(String dev_id, int client_id, String messageType, String dev_token, String remark) {
JSONObject log = new JSONObject(); JSONObject log = new JSONObject();
log.put("dev_id", dev_id); log.put("dev_id", dev_id);
@ -1078,7 +1094,7 @@ public class RetailAppServiceImp implements RetailAppService {
if (clientRate.getIntValue("clean_days") == 1) { if (clientRate.getIntValue("clean_days") == 1) {
JSONObject config = clientSettleDelayConfMapper.findClientConf(device.getIntValue("client_id")); JSONObject config = clientSettleDelayConfMapper.findClientConf(device.getIntValue("client_id"));
if (config == null) { if (config == null) {
// res.put("show", true); // res.put("show", true);
res.put("interest_rate", xPlanFundConfigService.configuration().getInterestRate().setScale(2, BigDecimal.ROUND_DOWN)); res.put("interest_rate", xPlanFundConfigService.configuration().getInterestRate().setScale(2, BigDecimal.ROUND_DOWN));
} }
@ -1086,7 +1102,6 @@ public class RetailAppServiceImp implements RetailAppService {
return res; return res;
} }
@Override @Override
public void sendMassageByCode(final JSONObject params) { public void sendMassageByCode(final JSONObject params) {
try { try {
@ -1095,7 +1110,7 @@ public class RetailAppServiceImp implements RetailAppService {
if (params.getString("type").equals("Merchant")) { if (params.getString("type").equals("Merchant")) {
for (String partner_code : codes) { for (String partner_code : codes) {
JSONObject client = clientManager.getClientInfoByMoniker(partner_code); JSONObject client = clientManager.getClientInfoByMoniker(partner_code);
Assert.notNull(client,"Client is null"); Assert.notNull(client, "Client is null");
List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByClient_id(client.getInteger("client_id")); List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByClient_id(client.getInteger("client_id"));
if (null != tokens && tokens.size() > 0) { if (null != tokens && tokens.size() > 0) {
for (final JSONObject devToken : tokens) { for (final JSONObject devToken : tokens) {
@ -1103,7 +1118,8 @@ public class RetailAppServiceImp implements RetailAppService {
sendingAppleMsgPool.execute(new Runnable() { sendingAppleMsgPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "dev", token, "Parampartner_code自定义推送消息"); JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "dev", token,
"Parampartner_code自定义推送消息");
sending(token, params, log); sending(token, params, log);
} }
}); });
@ -1135,19 +1151,30 @@ public class RetailAppServiceImp implements RetailAppService {
} }
public void sending(String devToken, JSONObject params, JSONObject log) { public void sending(String devToken, JSONObject params, JSONObject log) {
try { try {
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); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
logger.error("出错了:" + e.getMessage()); logger.error("出错了:" + e.getMessage());
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage()); appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
throw new ServerErrorException("Send App Message Failed", e); throw new ServerErrorException("Send App "+params.getString("client_type")+" Failed", e);
} }
} }
@Override @Override
public JSONObject getCoupons(JSONObject device, int page, int limit) { public JSONObject getCoupons(JSONObject device, int page, int limit) {
String clientType = device.getString("client_type"); String clientType = device.getString("client_type");
@ -1207,4 +1234,5 @@ public class RetailAppServiceImp implements RetailAppService {
String regex = "[A-Za-z0-9]{8}"; String regex = "[A-Za-z0-9]{8}";
return str.matches(regex); return str.matches(regex);
} }
} }

@ -16,7 +16,7 @@ public class Message {
public String title; public String title;
@NotEmpty(message = "content can not be null") @NotEmpty(message = "content can not be null")
public String content; public String content;
public String client_type;
public JSONObject insertObject() { public JSONObject insertObject() {
JSONObject res = (JSONObject) JSON.toJSON(this); JSONObject res = (JSONObject) JSON.toJSON(this);
return res; return res;
@ -53,4 +53,12 @@ public class Message {
public void setContent(String content) { public void setContent(String content) {
this.content = content; this.content = content;
} }
public String getClient_type() {
return client_type;
}
public void setClient_type(String client_type) {
this.client_type = client_type;
}
} }

@ -2775,7 +2775,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi(); MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
paymentApi.sendTemplateMessage(msg); paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) { } catch (WechatException e) {
logger.error("Wechat Message Error,绿色通道开通完成" + e.getMessage()); logger.error("Wechat JpushMessage Error,绿色通道开通完成" + e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,绿色通道开通完成,openid=" + wxopenid)); publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,绿色通道开通完成,openid=" + wxopenid));
} }
} }
@ -2794,7 +2794,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
bd_user_name, "制作合同申请", "BD申请制作" + short_name + "的合同"); bd_user_name, "制作合同申请", "BD申请制作" + short_name + "的合同");
paymentApi.sendTemplateMessage(msg); paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) { } catch (WechatException e) {
logger.error("Wechat Message Error,open_status=1" + e.getMessage()); logger.error("Wechat JpushMessage Error,open_status=1" + e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=1,openid=" + wxopenid)); publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=1,openid=" + wxopenid));
} }
} }
@ -2812,7 +2812,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
"Compliance", "合规材料", "上传完整合规材料,商户:" + short_name); "Compliance", "合规材料", "上传完整合规材料,商户:" + short_name);
paymentApi.sendTemplateMessage(msg); paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) { } catch (WechatException e) {
logger.error("Wechat Message Error,open_status=3" + e.getMessage()); logger.error("Wechat JpushMessage Error,open_status=3" + e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=3,openid=" + wxopenid)); publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=3,openid=" + wxopenid));
} }
@ -2832,7 +2832,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
bd_user_name, "审核材料", "BD已提交合规材料等待审核"); bd_user_name, "审核材料", "BD已提交合规材料等待审核");
paymentApi.sendTemplateMessage(msg); paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) { } catch (WechatException e) {
logger.error("Wechat Message Error,open_status=1" + e.getMessage()); logger.error("Wechat JpushMessage Error,open_status=1" + e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=1,openid=" + wxopenid)); publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=1,openid=" + wxopenid));
} }
} }
@ -2849,7 +2849,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi(); MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
paymentApi.sendTemplateMessage(msg); paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) { } catch (WechatException e) {
logger.error("Wechat Message Error,open_status=5" + e.getMessage()); logger.error("Wechat JpushMessage Error,open_status=5" + e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=5,openid=" + wxopenid)); publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=5,openid=" + wxopenid));
} }
} }
@ -2868,7 +2868,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
bd_user_name, "绿色通道申请", "BD已提交绿色通道申请,商户:" + short_name); bd_user_name, "绿色通道申请", "BD已提交绿色通道申请,商户:" + short_name);
paymentApi.sendTemplateMessage(msg); paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) { } catch (WechatException e) {
logger.error("Wechat Message Error,open_status=10"); logger.error("Wechat JpushMessage Error,open_status=10");
publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=10,openid=" + wxopenid)); publisher.publishEvent(new WechatExceptionEvent(this, e, "Audit,open_status=10,openid=" + wxopenid));
} }
} }

@ -0,0 +1,46 @@
package au.com.royalpay.payment.manage.pushMessage;
import com.alibaba.fastjson.JSONObject;
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by wangning on 2018/1/3.
*/
@Service
public class APNSMessageHelper {
private Logger logger = LoggerFactory.getLogger(getClass());
@Value("classpath:apple_message_cert_dev.p12")
private org.springframework.core.io.Resource appleMessageFileDev;
@Value("classpath:apple_message_cert_product.p12")
private org.springframework.core.io.Resource appleMessageFileProduct;
@Value("${apple.message.apns.password}")
private String appleMessagePassword;
public void sendAppleMessage(String title, String body, String token, JSONObject data, JSONObject type) throws IOException {
/**设置参数,发送数据**/
InputStream keyIns = appleMessageFileProduct.getInputStream();
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle(title).alertBody(body).badge(1).sound("default").customField("data", data).customField("type", type).build();
service.push(token, payload);
logger.debug("推送信息已发送!");
}
public void sendAppleMessageDetail(String title, String body, String token, JSONObject data, JSONObject type) throws IOException {
/**设置参数,发送数据**/
InputStream keyIns = appleMessageFileProduct.getInputStream();
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle(title).alertBody(body).category("myNotificationCategory").badge(1).sound("default").customField("data", data).customField("type", type).build();
service.push(token, payload);
logger.debug("推送信息已发送!");
}
}

@ -0,0 +1,97 @@
package au.com.royalpay.payment.manage.pushMessage;
import au.com.royalpay.payment.manage.pushMessage.bean.JpushMessage;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Map;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.Notification;
/**
* Created by wangning on 2018/1/3.
*/
@Service
public class JpushMessageHelper {
Logger logger = LoggerFactory.getLogger(getClass());
// 推送文本最大长度
private final Integer NOTIFICATION_MAX_LENGTH = 54;
private static JPushClient client = null;
private JPushClient getPush() {
if (client == null) {
client = new JPushClient("c235e93f6b91abd72ca5d74e", "c235e93f6b91abd72ca5d74e");
}
return client;
}
public void sendAppleMessage(String title, String body, String token, JSONObject data, JSONObject type) throws IOException, APIConnectionException, APIRequestException {
JPushClient jPushClient= getPush();
JpushMessage jpushMessage = new JpushMessage();
jpushMessage.setTitle(title);
jpushMessage.setText(body);
JSONObject param = new JSONObject();
param.put("data",data);
param.put("type",type);
jpushMessage.setParams(param);
PushPayload pushPayload = generateSinglePayload(token,jpushMessage);
jPushClient.sendPush(pushPayload);
}
private PushPayload generateSinglePayload(String alias, JpushMessage pushMessage) {
Notification notify = getNotify(pushMessage);
return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.alias(alias)).setNotification(notify)
// 设置离线时长
.setOptions(Options.newBuilder().setTimeToLive(60 * 60 * 4).build()).build();
}
private Notification getNotify(JpushMessage pushMessage) {
String alert = getText(pushMessage);
return Notification.newBuilder().addPlatformNotification(
AndroidNotification.newBuilder().setTitle(pushMessage.getTitle()).setAlert(alert).addExtras(getExtra(pushMessage)).build()).build();
}
private String getText(JpushMessage pushMessage) {
String text = pushMessage.getText();
int length = text.length();
int trueLength = 0;
String cutString = "";
for (int i = 0; i < length; i++) {
char c = text.charAt(i);
if (c < 0 || c > 128) {
// 汉字 3个字符
trueLength += 3;
} else {
// 英文等 1个字符
trueLength++;
}
cutString += c;
if (trueLength >= NOTIFICATION_MAX_LENGTH) {
cutString += "...";
break;
}
}
return cutString;
}
private Map<String, String> getExtra(JpushMessage message) {
Map map = message.getParams();
return map;
}
}

@ -0,0 +1,22 @@
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;
/**
* Created by wangning on 08/01/2018.
*/
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"));
}
}

@ -0,0 +1,44 @@
package au.com.royalpay.payment.manage.pushMessage.bean;
import com.alibaba.fastjson.JSONObject;
public class JpushMessage implements java.io.Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
private String title;
/**
*
*/
private String text;
private JSONObject params;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public JSONObject getParams() {
return params;
}
public void setParams(JSONObject params) {
this.params = params;
}
}

@ -1,10 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="au.com.royalpay.payment.manage.mappers.system.ClientDeviceTokenMapper"> <mapper namespace="au.com.royalpay.payment.manage.mappers.system.ClientDeviceTokenMapper">
<select id="listTokensByClient_id" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTokensByClient_id" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM sys_clients_devices_token where client_id=#{client_id} and is_valid=1 group by token SELECT
t.*, d.client_type
FROM
sys_clients_devices_token t
LEFT JOIN sys_clients_devices d ON t.dev_id = d.dev_id
WHERE
t.client_id = #{client_id}
AND t.is_valid = 1
GROUP BY
token
</select> </select>
<select id="listAllTokensByClient_id" resultType="com.alibaba.fastjson.JSONObject">
SELECT
t.*, d.client_type
FROM
sys_clients_devices_token t
LEFT JOIN sys_clients_devices d ON t.dev_id = d.dev_id
WHERE
t.client_id = #{client_id}
GROUP BY
token
</select>
<select id="findByDevId" resultType="com.alibaba.fastjson.JSONObject"> <select id="findByDevId" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM sys_clients_devices_token where dev_id=#{dev_id} limit 1 SELECT * FROM sys_clients_devices_token where dev_id=#{dev_id} limit 1
</select> </select>

@ -31,6 +31,13 @@
<label>DevToken</label> <label>DevToken</label>
<input ng-model="params.code" class="form-control" type="text" /> <input ng-model="params.code" class="form-control" type="text" />
</div> </div>
<div class="form-group" ng-if="params.type=='Personal'">
<label>Client Type</label>
<select ng-model="params.client_type">
<option value="iphone">iphone</option>
<option value="android">android</option>
</select>
</div>
<div class="form-group"> <div class="form-group">
<label>Title</label> <label>Title</label>
<input ng-model="params.title" class="form-control" type="text" /> <input ng-model="params.title" class="form-control" type="text" />

Loading…
Cancel
Save