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 219893af7..785c3f000 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 @@ -1,5 +1,39 @@ 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.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.List; +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.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper; import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper; @@ -14,12 +48,18 @@ 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.payment.OrderMapper; 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.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.pushMessage.JpushMessageHelper; +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; import au.com.royalpay.payment.manage.signin.core.impls.SignInAccountServiceImpl; @@ -36,37 +76,9 @@ import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; 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 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; +import cn.jpush.api.JPushClient; +import cn.jpush.api.push.model.PushPayload; /** * Created by yishuqian on 28/03/2017. @@ -120,6 +132,8 @@ public class RetailAppServiceImp implements RetailAppService { private APNSMessageHelper apnsMessageHelper; @Resource private ClientDeviceTokenMapper clientDeviceTokenMapper; + @Resource + private JpushMessageHelper jpushMessageHelper; private ThreadPoolExecutor sendingAppleMsgPool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue()); @@ -455,10 +469,24 @@ public class RetailAppServiceImp implements RetailAppService { JSONObject type = new JSONObject(); type.put("send_type", "payment"); type.put("id", order.getString("order_id")); - 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); + 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"))) { + JPushClient jPushClient= JpushMessageHelper.getPush(); + JpushMessage jpushMessage = new JpushMessage(); + jpushMessage.setTitle(LocaleSupport.localeMessage("app.message.title.payment")); + jpushMessage.setText(LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount")); + JSONObject param = new JSONObject(); + param.put("data",order); + param.put("type",type); + jpushMessage.setParams(param); + PushPayload pushPayload =JpushMessageHelper.generateSinglePayload(token,jpushMessage); + jPushClient.sendPush(pushPayload); + } + log.put("status", 2); appMessageLogMapper.update(log); } catch (Exception e) { logger.error("出错了:" + e.getMessage()); @@ -501,9 +529,14 @@ public class RetailAppServiceImp implements RetailAppService { JSONObject type = new JSONObject(); type.put("send_type", "refund"); type.put("id", order.getString("order_id")); - apnsMessageHelper.sendAppleMessage("Refund JpushMessage", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount, token, - order, type); - log.put("status", 2); + 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"))) { + sendAppleMessage + } + log.put("status", 2); appMessageLogMapper.update(log); } catch (Exception e) { logger.error("出错了:" + e.getMessage()); @@ -535,8 +568,23 @@ public class RetailAppServiceImp implements RetailAppService { JSONObject type = new JSONObject(); type.put("send_type", "notice"); type.put("id", notice.getNotice_id()); - apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"), notice.getTitle(), token, noticeObj, - type); + 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"))){ + JPushClient jPushClient= JpushMessageHelper.getPush(); + JpushMessage jpushMessage = new JpushMessage(); + jpushMessage.setTitle(notice.getTitle()); + jpushMessage.setText(LocaleSupport.localeMessage("app.message.title.notice")); + JSONObject param = new JSONObject(); + param.put("data",noticeObj); + param.put("type",type); + jpushMessage.setParams(param); + PushPayload pushPayload =JpushMessageHelper.generateSinglePayload(token,jpushMessage); + jPushClient.sendPush(pushPayload); + } + log.put("status", 2); appMessageLogMapper.update(log); } catch (Exception e) { @@ -1147,4 +1195,9 @@ public class RetailAppServiceImp implements RetailAppService { String regex = "[A-Za-z0-9]{8}"; return str.matches(regex); } + + private void sendJpush(int client_id,JpushMessage message){ + + + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/pushMessage/JpushMessageHelper.java b/src/main/java/au/com/royalpay/payment/manage/pushMessage/JpushMessageHelper.java index d31cb2869..d30322181 100644 --- a/src/main/java/au/com/royalpay/payment/manage/pushMessage/JpushMessageHelper.java +++ b/src/main/java/au/com/royalpay/payment/manage/pushMessage/JpushMessageHelper.java @@ -2,13 +2,17 @@ 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 java.util.Set; +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; @@ -25,8 +29,8 @@ public class JpushMessageHelper { Logger logger = LoggerFactory.getLogger(getClass()); // 推送文本最大长度 - private final Integer NOTIFICATION_MAX_LENGTH = 54; - private static JPushClient client=null; + private static final Integer NOTIFICATION_MAX_LENGTH = 54; + private static JPushClient client = null; public static JPushClient getPush() { if (client == null) { @@ -35,24 +39,33 @@ public class JpushMessageHelper { return client; } - public PushPayload generateSinglePayload(Set alias, JpushMessage pushMessage) { + public void sendAppleMessage(String title, String body, String token, JSONObject data, JSONObject type) throws IOException, APIConnectionException, APIRequestException { + JPushClient jPushClient= JpushMessageHelper.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 =JpushMessageHelper.generateSinglePayload(token,jpushMessage); + jPushClient.sendPush(pushPayload); + } + + public static PushPayload generateSinglePayload(String alias, JpushMessage pushMessage) { Notification notify = getNotify(pushMessage); - return PushPayload.newBuilder() - .setPlatform(Platform.android()) - .setAudience(Audience.alias(alias)) - .setNotification(notify) + return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.alias(alias)).setNotification(notify) // 设置离线时长 - .setOptions(Options.newBuilder().setTimeToLive(60*60*4).build()).build(); + .setOptions(Options.newBuilder().setTimeToLive(60 * 60 * 4).build()).build(); } - private Notification getNotify(JpushMessage pushMessage) { + private static Notification getNotify(JpushMessage pushMessage) { String alert = getText(pushMessage); - return Notification - .newBuilder() - .addPlatformNotification(AndroidNotification.newBuilder().setTitle(pushMessage.getTitle()).setAlert(alert).addExtras(getExtra(pushMessage)).build()).build(); + return Notification.newBuilder().addPlatformNotification( + AndroidNotification.newBuilder().setTitle(pushMessage.getTitle()).setAlert(alert).addExtras(getExtra(pushMessage)).build()).build(); } - private String getText(JpushMessage pushMessage) { + private static String getText(JpushMessage pushMessage) { String text = pushMessage.getText(); int length = text.length(); int trueLength = 0; @@ -77,8 +90,7 @@ public class JpushMessageHelper { return cutString; } - - private Map getExtra(JpushMessage message){ + private static Map getExtra(JpushMessage message) { Map map = message.getParams(); return map; } diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientDeviceTokenMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientDeviceTokenMapper.xml index 3551b3c64..66996e519 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientDeviceTokenMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientDeviceTokenMapper.xml @@ -1,10 +1,31 @@ - + +