master
wangning 7 years ago
parent d5bbf8e0be
commit de7a193402

@ -132,6 +132,21 @@
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</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>
<build>
<plugins>

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

@ -19,6 +19,7 @@ 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.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.signin.beans.ChangePwdBean;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.signin.core.impls.SignInAccountServiceImpl;
@ -77,77 +78,55 @@ public class RetailAppServiceImp implements RetailAppService {
private TransactionAnalysisMapper transactionAnalysisMapper;
@Resource
private TransactionMapper transactionMapper;
@Resource
private ClientManager clientManager;
@Resource
private NoticeManage noticeManage;
@Resource
private NoticePartner noticePartner;
@Resource
private CustomerAndOrdersStatisticsMapper customerAndOrdersStatisticsMapper;
@Resource
private ClearingDetailMapper clearingDetailMapper;
@Resource
private OrderMapper orderMapper;
@Resource
private ClientAccountMapper clientAccountMapper;
@Resource
private AppMessageLogMapper appMessageLogMapper;
@Resource
private SignInAccountService signInAccountService;
@Resource
private CashbackService cashbackService;
@Resource
private ClearingDetailAnalysisMapper clearingDetailAnalysisMapper;
@Resource
private ClientSettleDelayConfMapper clientSettleDelayConfMapper;
@Resource
private XPlanFundConfigServiceImpl xPlanFundConfigService;
@Resource
private MerchantInfoProvider merchantInfoProvider;
@Resource
private RoyalPayCMSSupport royalPayCMSSupport;
@Resource
private PaymentApi paymentApi;
@Resource
private DeviceSupport deviceSupport;
@Resource
private CustomerRelationAlipayMapper customerRelationAlipayMapper;
@Resource
private CustomerMapper customerMapper;
@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;
@Resource
private APNSMessageHelper apnsMessageHelper;
@Resource
private ClientDeviceTokenMapper clientDeviceTokenMapper;
private ThreadPoolExecutor sendingAppleMsgPool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@Resource
private CouponValidateService couponVerificationService;
//若app未传client_ids,检测是否包含子商户,若包含查询全部
// 若app未传client_ids,检测是否包含子商户,若包含查询全部
private void setAllClientIds(JSONObject params, int clientId) {
if (params.containsKey("client_ids")) {
return;
@ -175,10 +154,10 @@ public class RetailAppServiceImp implements RetailAppService {
params.put("client_id", client_id);
res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(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("old_customers", transactionAnalysisMapper.countOldCustomers(params));
//微信小程序不查询汇率
// 微信小程序不查询汇率
if (!StringUtils.equals(device.getString("client_type"), "wxapp")) {
res.put("rate", paymentApi.channelApi("Wechat").queryExchangeRateDecimal(client_id));
}
@ -266,7 +245,6 @@ public class RetailAppServiceImp implements RetailAppService {
}
}
@Override
public JSONObject getClientSettlementLog(JSONObject device, AppQueryBean appQueryBean) {
String clientType = device.getString("client_type");
@ -280,7 +258,8 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject params = appQueryBean.toParams();
setAllClientIds(params, 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);
}
@ -354,11 +333,13 @@ public class RetailAppServiceImp implements RetailAppService {
params.put("dev_id", device.getString("dev_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");
ArrayList<String> date_contains = new ArrayList<>();
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");
String trade_date = DateFormatUtils.format(calendar, "yyyy-MM-dd");
String trade_time = DateFormatUtils.format(calendar, "HH:mm:ss");
@ -369,7 +350,7 @@ public class RetailAppServiceImp implements RetailAppService {
TradeLogQuery date_query = new TradeLogQuery();
date_query.setDatefrom(re_date);
date_query.setDateto(re_date);
// date_query.setStatus(OrderStatus.ALL);
// date_query.setStatus(OrderStatus.ALL);
if (params.containsKey("client_ids")) {
date_query.setClient_ids((String[]) params.get("client_ids"));
}
@ -388,7 +369,7 @@ public class RetailAppServiceImp implements RetailAppService {
query.setGateway_app("11");
String clientType = device.getString("client_type");
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");
JSONObject client = clientManager.getClientInfo(client_id);
String timezone = client.getString("timezone");
@ -455,31 +436,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
public void sendOrderAppMessage(final JSONObject order, int client_id) {
logger.debug("sendOrderAppMessage-" + client_id + "-" + order.getString("order_id"));
@ -491,21 +447,23 @@ 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"));
// todo 抽象发送信息接口,根据设备类型选择不同实现类
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "payment", token,
order.getString("order_id"));
try {
order.put("send_type", "payment");
JSONObject type = new JSONObject();
type.put("send_type", "payment");
type.put("id", order.getString("order_id"));
sendAppleMessage(LocaleSupport.localeMessage("app.message.title.payment"),
LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount"), token, order, 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);
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 Message Failed", e);
throw new ServerErrorException("Send App JpushMessage Failed", e);
}
};
sendingAppleMsgPool.execute(task);
@ -536,14 +494,15 @@ public class RetailAppServiceImp implements RetailAppService {
return;
}
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 {
order.put("send_type", "refund");
JSONObject type = new JSONObject();
type.put("send_type", "refund");
type.put("id", order.getString("order_id"));
sendAppleMessage("Refund Message",
LocaleSupport.localeMessage("app.message.body.refund") + refundAmount, token, order, type);
apnsMessageHelper.sendAppleMessage("Refund JpushMessage", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount, token,
order, type);
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
@ -567,7 +526,8 @@ public class RetailAppServiceImp implements RetailAppService {
if (token == null) {
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 {
notice.setContent(null);
JSONObject noticeObj = notice.toJson();
@ -575,7 +535,8 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "notice");
type.put("id", notice.getNotice_id());
sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"), notice.getTitle(), token, noticeObj, type);
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"), notice.getTitle(), token, noticeObj,
type);
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
@ -600,19 +561,22 @@ public class RetailAppServiceImp implements RetailAppService {
if (token == null) {
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 {
JSONObject type = new JSONObject();
type.put("send_type", "cashback");
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);
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"),
LocaleSupport.localeMessage("app.message.body.cashback") + PlatformEnvironment.getEnv().getForeignCurrency() + " "
+ cashbackAmount,
token, order, type);
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 Message Failed", e);
throw new ServerErrorException("Send App JpushMessage Failed", e);
}
}
});
@ -625,7 +589,8 @@ public class RetailAppServiceImp implements RetailAppService {
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_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);
for (JSONObject devToken : tokens) {
String token = devToken.getString("token");
@ -633,24 +598,25 @@ public class RetailAppServiceImp implements RetailAppService {
continue;
}
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 {
JSONObject type = new JSONObject();
type.put("send_type", "clean");
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);
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);
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 Message Failed", e);
throw new ServerErrorException("Send App JpushMessage Failed", e);
}
}
}
@Override
public void sendTransactionDailyMessage(JSONObject tradeInfo, int client_id) {
String trade_date = tradeInfo.getString("trade_date");
@ -663,50 +629,26 @@ public class RetailAppServiceImp implements RetailAppService {
if (token == null) {
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 {
JSONObject type = new JSONObject();
type.put("send_type", "daily_notice");
type.put("id", trade_date);
sendAppleMessageDetail(LocaleSupport.localeMessage("app.message.title.daily_notice"),
trade_date + ": 总交易额 " + PlatformEnvironment.getEnv().getForeignCurrency() + total_amount + ", 订单数:" + total_orders + ", 付款人数:" + customers, token, tradeInfo, type);
apnsMessageHelper.sendAppleMessageDetail(
LocaleSupport.localeMessage("app.message.title.daily_notice"), trade_date + ": 总交易额 "
+ PlatformEnvironment.getEnv().getForeignCurrency() + total_amount + ", 订单数:" + total_orders + ", 付款人数:" + customers,
token, tradeInfo, type);
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 Message Failed", e);
throw new ServerErrorException("Send App JpushMessage 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
public void updateReadStatus(JSONObject device, String noticeId) {
@ -747,7 +689,7 @@ public class RetailAppServiceImp implements RetailAppService {
Document doc = Jsoup.parse(res.getString("content"));
String father = "<div style=\"padding:0 10px\"></div>";
String html = doc.body().children().wrap(father).html();
// logger.debug("wrapped html---->"+html);
// logger.debug("wrapped html---->"+html);
res.put("content", doc.html());
return res;
}
@ -756,7 +698,7 @@ public class RetailAppServiceImp implements RetailAppService {
public void changeAccountPassword(JSONObject device, ChangePwdBean change, String account_id) {
String clientType = device.getString("client_type");
deviceSupport.findRegister(clientType);
//JSONObject client = signInAccountService.getClient(account_id);
// JSONObject client = signInAccountService.getClient(account_id);
if (!account_id.equals(device.getString("account_id"))) {
throw new ForbiddenException("You have no permission");
}
@ -779,7 +721,7 @@ public class RetailAppServiceImp implements RetailAppService {
Date now = new Date();
JSONObject res = merchantInfoProvider.clientCurrentRate(clientId, now, "Wechat");
JSONObject client = clientManager.getClientInfo(clientId);
Assert.notNull(client,"Client is null");
Assert.notNull(client, "Client is null");
JSONObject[] channels = new JSONObject[3];
@ -804,7 +746,7 @@ public class RetailAppServiceImp implements RetailAppService {
Date now = new Date();
JSONObject res = merchantInfoProvider.clientCurrentRate(clientId, now, "Wechat");
JSONObject client = clientManager.getClientInfo(clientId);
Assert.notNull(client,"Client is null");
Assert.notNull(client, "Client is null");
ArrayList<JSONObject> channels = new ArrayList<>();
if (client.getBigDecimal("customer_surcharge_rate") != null) {
@ -889,7 +831,7 @@ public class RetailAppServiceImp implements RetailAppService {
}
res.put("data", new_acts);
}
//手续费返还活动
// 手续费返还活动
List<JSONObject> acts = (List<JSONObject>) res.get("data");
for (JSONObject act : acts) {
if (StringUtils.isNotBlank(act.getString("page_keywords")) && act.getString("page_keywords").equalsIgnoreCase("native")) {
@ -923,7 +865,7 @@ public class RetailAppServiceImp implements RetailAppService {
String newAppVersion = PlatformEnvironment.getEnv().getNewVersion();
Boolean isUpdate = PlatformEnvironment.getEnv().isAppUpdate();
String updateContent = PlatformEnvironment.getEnv().getAppUpdateContent();
int update_type = 0;//0:不更新 1更新 2强制更新
int update_type = 0;// 0:不更新 1更新 2强制更新
if (newAppVersion.compareToIgnoreCase(version) > 0) {
update_type = 1;
if (isUpdate) {
@ -943,7 +885,6 @@ public class RetailAppServiceImp implements RetailAppService {
return clientManager.listSubClients(device.getIntValue("client_id"));
}
private JSONObject saveAppMessageLog(String dev_id, int client_id, String messageType, String dev_token, String remark) {
JSONObject log = new JSONObject();
log.put("dev_id", dev_id);
@ -1078,7 +1019,7 @@ public class RetailAppServiceImp implements RetailAppService {
if (clientRate.getIntValue("clean_days") == 1) {
JSONObject config = clientSettleDelayConfMapper.findClientConf(device.getIntValue("client_id"));
if (config == null) {
// res.put("show", true);
// res.put("show", true);
res.put("interest_rate", xPlanFundConfigService.configuration().getInterestRate().setScale(2, BigDecimal.ROUND_DOWN));
}
@ -1086,7 +1027,6 @@ public class RetailAppServiceImp implements RetailAppService {
return res;
}
@Override
public void sendMassageByCode(final JSONObject params) {
try {
@ -1095,7 +1035,7 @@ public class RetailAppServiceImp implements RetailAppService {
if (params.getString("type").equals("Merchant")) {
for (String partner_code : codes) {
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"));
if (null != tokens && tokens.size() > 0) {
for (final JSONObject devToken : tokens) {
@ -1103,7 +1043,8 @@ public class RetailAppServiceImp implements RetailAppService {
sendingAppleMsgPool.execute(new Runnable() {
@Override
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);
}
});
@ -1129,7 +1070,7 @@ public class RetailAppServiceImp implements RetailAppService {
throw new ServerErrorException(s.getMessage());
} catch (Exception e) {
logger.error("出错了:" + e.getMessage());
throw new ServerErrorException("Send App Message Failed", e);
throw new ServerErrorException("Send App JpushMessage Failed", e);
}
}
@ -1137,17 +1078,16 @@ public class RetailAppServiceImp implements RetailAppService {
public void sending(String devToken, JSONObject params, JSONObject log) {
try {
sendAppleMessage(params.getString("title"), params.getString("content"), devToken, new JSONObject(), new JSONObject());
apnsMessageHelper.sendAppleMessage(params.getString("title"), params.getString("content"), devToken, new JSONObject(), new JSONObject());
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 Message Failed", e);
throw new ServerErrorException("Send App JpushMessage Failed", e);
}
}
@Override
public JSONObject getCoupons(JSONObject device, int page, int limit) {
String clientType = device.getString("client_type");

@ -2774,7 +2774,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
paymentApi.sendTemplateMessage(msg);
} 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));
}
}
@ -2793,7 +2793,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
bd_user_name, "制作合同申请", "BD申请制作" + short_name + "的合同");
paymentApi.sendTemplateMessage(msg);
} 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));
}
}
@ -2811,7 +2811,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
"Compliance", "合规材料", "上传完整合规材料,商户:" + short_name);
paymentApi.sendTemplateMessage(msg);
} 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));
}
@ -2831,7 +2831,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
bd_user_name, "审核材料", "BD已提交合规材料等待审核");
paymentApi.sendTemplateMessage(msg);
} 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));
}
}
@ -2848,7 +2848,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
paymentApi.sendTemplateMessage(msg);
} 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));
}
}
@ -2867,7 +2867,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
bd_user_name, "绿色通道申请", "BD已提交绿色通道申请,商户:" + short_name);
paymentApi.sendTemplateMessage(msg);
} 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));
}
}

@ -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,88 @@
package au.com.royalpay.payment.manage.pushMessage;
import au.com.royalpay.payment.manage.pushMessage.bean.JpushMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Set;
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.IosNotification;
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;
public static JPushClient getPush() {
if (client == null) {
client = new JPushClient("c235e93f6b91abd72ca5d74e", "c235e93f6b91abd72ca5d74e");
}
return client;
}
public PushPayload makeSinglePayload(Set<String> clientIds, JpushMessage pushMessage) {
Notification notify = getNotify(pushMessage);
return PushPayload.newBuilder()
.setPlatform(Platform.android_ios())
.setAudience(Audience.registrationId(clientIds))
.setNotification(notify)
// 设置离线时长
.setOptions(
Options.newBuilder().setTimeToLive(600).build()).build();
}
private Notification getNotify(JpushMessage pushMessage) {
String alert = getText(pushMessage);
return Notification
.newBuilder()
.addPlatformNotification(IosNotification.newBuilder().setAlert(alert).setSound("default").addExtras(getExtra(pushMessage)).build())
.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,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;
}
}
Loading…
Cancel
Save