wangning 7 years ago
parent e4c8f7de62
commit 0327de0101

@ -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<Runnable>());
@ -455,9 +469,23 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "payment");
type.put("id", order.getString("order_id"));
if("iphone".equals(devToken.getString("client_type"))) {
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.payment"),
LocaleSupport.localeMessage("app.message.body.payment") + order.getString("currency") + order.getDoubleValue("total_amount"), token,
order, type);
}
if("android".equals(devToken.getString("client_type"))) {
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) {
@ -501,8 +529,13 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "refund");
type.put("id", order.getString("order_id"));
if("iphone".equals(devToken.getString("client_type"))) {
apnsMessageHelper.sendAppleMessage("Refund JpushMessage", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount, token,
order, type);
}
if("android".equals(devToken.getString("client_type"))) {
sendAppleMessage
}
log.put("status", 2);
appMessageLogMapper.update(log);
} catch (Exception e) {
@ -535,8 +568,23 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject type = new JSONObject();
type.put("send_type", "notice");
type.put("id", notice.getNotice_id());
if("iphone".equals(devToken.getString("client_type"))){
apnsMessageHelper.sendAppleMessage(LocaleSupport.localeMessage("app.message.title.notice"), notice.getTitle(), token, noticeObj,
type);
}
if("android".equals(devToken.getString("client_type"))){
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){
}
}

@ -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<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);
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<String, String> getExtra(JpushMessage message){
private static Map<String, String> getExtra(JpushMessage message) {
Map map = message.getParams();
return map;
}

@ -1,10 +1,31 @@
<?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">
<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 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 * FROM sys_clients_devices_token where dev_id=#{dev_id} limit 1
</select>

Loading…
Cancel
Save