wangning 7 years ago
parent e4c8f7de62
commit 0327de0101

@ -1,5 +1,39 @@
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.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.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,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.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.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.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;
@ -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.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 cn.jpush.api.JPushClient;
import java.io.IOException; import cn.jpush.api.push.model.PushPayload;
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.
@ -120,6 +132,8 @@ public class RetailAppServiceImp implements RetailAppService {
private APNSMessageHelper apnsMessageHelper; private APNSMessageHelper apnsMessageHelper;
@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 ThreadPoolExecutor sendingAppleMsgPool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@ -455,10 +469,24 @@ public class RetailAppServiceImp implements RetailAppService {
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"));
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.payment"), if("iphone".equals(devToken.getString("client_type"))) {
LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount"), token, apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.payment"),
order, type); LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount"), token,
log.put("status", 2); 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); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
logger.error("出错了:" + e.getMessage()); logger.error("出错了:" + e.getMessage());
@ -501,9 +529,14 @@ public class RetailAppServiceImp implements RetailAppService {
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"));
apnsMessageHelper.sendAppleMessage("Refund JpushMessage", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount, token, if("iphone".equals(devToken.getString("client_type"))) {
order, type); apnsMessageHelper.sendAppleMessage("Refund JpushMessage", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount, token,
log.put("status", 2); order, type);
}
if("android".equals(devToken.getString("client_type"))) {
sendAppleMessage
}
log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
logger.error("出错了:" + e.getMessage()); logger.error("出错了:" + e.getMessage());
@ -535,8 +568,23 @@ 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());
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"), notice.getTitle(), token, noticeObj, if("iphone".equals(devToken.getString("client_type"))){
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); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);
} catch (Exception e) { } catch (Exception e) {
@ -1147,4 +1195,9 @@ 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);
} }
private void sendJpush(int client_id,JpushMessage message){
}
} }

@ -2,13 +2,17 @@ package au.com.royalpay.payment.manage.pushMessage;
import au.com.royalpay.payment.manage.pushMessage.bean.JpushMessage; import au.com.royalpay.payment.manage.pushMessage.bean.JpushMessage;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Map; 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.JPushClient;
import cn.jpush.api.push.model.Options; import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform; import cn.jpush.api.push.model.Platform;
@ -25,8 +29,8 @@ public class JpushMessageHelper {
Logger logger = LoggerFactory.getLogger(getClass()); Logger logger = LoggerFactory.getLogger(getClass());
// 推送文本最大长度 // 推送文本最大长度
private final Integer NOTIFICATION_MAX_LENGTH = 54; private static final Integer NOTIFICATION_MAX_LENGTH = 54;
private static JPushClient client=null; private static JPushClient client = null;
public static JPushClient getPush() { public static JPushClient getPush() {
if (client == null) { if (client == null) {
@ -35,24 +39,33 @@ public class JpushMessageHelper {
return client; return client;
} }
public PushPayload generateSinglePayload(Set<String> 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); Notification notify = getNotify(pushMessage);
return PushPayload.newBuilder() return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.alias(alias)).setNotification(notify)
.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); String alert = getText(pushMessage);
return Notification return Notification.newBuilder().addPlatformNotification(
.newBuilder() AndroidNotification.newBuilder().setTitle(pushMessage.getTitle()).setAlert(alert).addExtras(getExtra(pushMessage)).build()).build();
.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(); String text = pushMessage.getText();
int length = text.length(); int length = text.length();
int trueLength = 0; int trueLength = 0;
@ -77,8 +90,7 @@ public class JpushMessageHelper {
return cutString; return cutString;
} }
private static Map<String, String> getExtra(JpushMessage message) {
private Map<String, String> getExtra(JpushMessage message){
Map map = message.getParams(); Map map = message.getParams();
return map; return map;
} }

@ -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>

Loading…
Cancel
Save