update
This commit is contained in:
parent
6d2a37365e
commit
441439d492
30
pom.xml
30
pom.xml
|
|
@ -233,6 +233,36 @@
|
||||||
<version>${fastjson.version}</version>
|
<version>${fastjson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.gexin.platform</groupId>
|
||||||
|
<artifactId>gexin-rp-fastjson</artifactId>
|
||||||
|
<version>1.0.0.7</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
<version>2.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.gexin.platform</groupId>
|
||||||
|
<artifactId>gexin-rp-sdk-base</artifactId>
|
||||||
|
<version>4.0.0.37</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.gexin.platform</groupId>
|
||||||
|
<artifactId>gexin-rp-sdk-http</artifactId>
|
||||||
|
<version>4.1.1.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.gexin.platform</groupId>
|
||||||
|
<artifactId>gexin-rp-sdk-template</artifactId>
|
||||||
|
<version>4.0.0.29</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,11 @@ public class TblAliyunDeviceInfo {
|
||||||
*/
|
*/
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型 0默认 1个推
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机类型
|
* 手机类型
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,27 @@ import com.aliyuncs.push.model.v20160801.PushRequest;
|
||||||
import com.aliyuncs.push.model.v20160801.PushResponse;
|
import com.aliyuncs.push.model.v20160801.PushResponse;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.gexin.rp.sdk.base.IPushResult;
|
||||||
|
import com.gexin.rp.sdk.base.impl.SingleMessage;
|
||||||
|
import com.gexin.rp.sdk.base.impl.Target;
|
||||||
|
import com.gexin.rp.sdk.base.notify.Notify;
|
||||||
|
import com.gexin.rp.sdk.dto.GtReq;
|
||||||
|
import com.gexin.rp.sdk.http.IGtPush;
|
||||||
|
import com.gexin.rp.sdk.template.NotificationTemplate;
|
||||||
|
import com.gexin.rp.sdk.template.TransmissionTemplate;
|
||||||
|
import com.gexin.rp.sdk.template.style.Style0;
|
||||||
import com.ifish7.mq.business.user.entity.TblAliyunDeviceInfo;
|
import com.ifish7.mq.business.user.entity.TblAliyunDeviceInfo;
|
||||||
import com.ifish7.mq.business.user.entity.TblPushList;
|
import com.ifish7.mq.business.user.entity.TblPushList;
|
||||||
import com.ifish7.mq.business.user.service.ITblAliyunDeviceInfoService;
|
import com.ifish7.mq.business.user.service.ITblAliyunDeviceInfoService;
|
||||||
import com.ifish7.mq.business.user.service.ITblPushListService;
|
import com.ifish7.mq.business.user.service.ITblPushListService;
|
||||||
import lombok.extern.log4j.Log4j;
|
import lombok.extern.log4j.Log4j;
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: yan.y
|
* @author: yan.y
|
||||||
|
|
@ -36,7 +39,10 @@ import java.util.*;
|
||||||
@Log4j
|
@Log4j
|
||||||
public class AliyunPushApi {
|
public class AliyunPushApi {
|
||||||
|
|
||||||
private DefaultAcsClient client;
|
private final DefaultAcsClient client;
|
||||||
|
|
||||||
|
private final IGtPush iGtPush = new IGtPush(HOST_HTTPS, "099ng3u5ud5pVGqsH0GlK", "w3yLh3Ng4j5JYqGYH7C7o9");
|
||||||
|
|
||||||
|
|
||||||
public AliyunPushApi(String regionId,String accessKeyId,String accessKeySecret){
|
public AliyunPushApi(String regionId,String accessKeyId,String accessKeySecret){
|
||||||
client = new DefaultAcsClient(DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret));
|
client = new DefaultAcsClient(DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret));
|
||||||
|
|
@ -47,12 +53,23 @@ public class AliyunPushApi {
|
||||||
//推送类型
|
//推送类型
|
||||||
private static final String PUSH_TYPE = "NOTICE";
|
private static final String PUSH_TYPE = "NOTICE";
|
||||||
|
|
||||||
|
private static final String HOST_HTTPS = "https://api.getui.com/apiex.htm";
|
||||||
|
|
||||||
@Value("${android_app_key}")
|
@Value("${android_app_key}")
|
||||||
private String androidAppKey;
|
private String androidAppKey;
|
||||||
|
|
||||||
@Value("${ios_app_key}")
|
@Value("${ios_app_key}")
|
||||||
private String iosAppKey;
|
private String iosAppKey;
|
||||||
|
|
||||||
|
@Value("${gtAppId}")
|
||||||
|
private String gtAppId;
|
||||||
|
|
||||||
|
@Value("${gtAppKey}")
|
||||||
|
private String gtAppKey;
|
||||||
|
|
||||||
|
@Value("${gtMasterSecret}")
|
||||||
|
private String gtMasterSecret;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PushRequest pushRequest;
|
private PushRequest pushRequest;
|
||||||
|
|
||||||
|
|
@ -79,6 +96,20 @@ public class AliyunPushApi {
|
||||||
}
|
}
|
||||||
List<TblAliyunDeviceInfo> pushUserDevices = aliyunDeviceInfoService.list(allQuary);
|
List<TblAliyunDeviceInfo> pushUserDevices = aliyunDeviceInfoService.list(allQuary);
|
||||||
pushUserDevices.forEach(aliyunDeviceInfo -> {
|
pushUserDevices.forEach(aliyunDeviceInfo -> {
|
||||||
|
if (aliyunDeviceInfo.getType() == 1) {
|
||||||
|
gtPush(pushList, aliyunDeviceInfo);
|
||||||
|
} else {
|
||||||
|
aliyunPush(pushList, aliyunDeviceInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//未读
|
||||||
|
pushList.setIsRead(1);
|
||||||
|
pushListService.save(pushList);
|
||||||
|
|
||||||
|
//sendMsg(String.valueOf(pushList.getUserId()),pushList.getPushContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void aliyunPush(TblPushList pushList, TblAliyunDeviceInfo aliyunDeviceInfo) {
|
||||||
if ("iOS".equals(aliyunDeviceInfo.getPhoneType())) {
|
if ("iOS".equals(aliyunDeviceInfo.getPhoneType())) {
|
||||||
pushRequest.setAppKey(Long.parseLong(iosAppKey));
|
pushRequest.setAppKey(Long.parseLong(iosAppKey));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -121,14 +152,64 @@ public class AliyunPushApi {
|
||||||
} catch (ClientException e) {
|
} catch (ClientException e) {
|
||||||
log.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
//未读
|
|
||||||
pushList.setIsRead(1);
|
|
||||||
pushListService.save(pushList);
|
|
||||||
|
|
||||||
//sendMsg(String.valueOf(pushList.getUserId()),pushList.getPushContext());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void gtPush(TblPushList pushList, TblAliyunDeviceInfo aliyunDeviceInfo) {
|
||||||
|
SingleMessage singleMessage = new SingleMessage();
|
||||||
|
Notify notify = new Notify();
|
||||||
|
notify.setTitle(pushList.getPushTitle());
|
||||||
|
notify.setContent(pushList.getPushContext());
|
||||||
|
notify.addExtKVToAll("/android/notification/importance","NORMAL");
|
||||||
|
notify.addXMExtKV("/extra.channel_id", "131247");
|
||||||
|
|
||||||
|
TransmissionTemplate transmissionTemplate = new TransmissionTemplate();
|
||||||
|
transmissionTemplate.setTransmissionType(2); // 透传消息接受方式设置:1:立即启动APP 2:客户端收到消息后需要自行处理
|
||||||
|
|
||||||
|
transmissionTemplate.setAppId(gtAppId);
|
||||||
|
transmissionTemplate.setAppkey(gtAppKey);
|
||||||
|
transmissionTemplate.set3rdNotifyInfo(notify);
|
||||||
|
singleMessage.setData(transmissionTemplate);
|
||||||
|
singleMessage.setOffline(true);
|
||||||
|
singleMessage.setOfflineExpireTime(72 * 3600000L);
|
||||||
|
Target target = new Target();
|
||||||
|
target.setAppId(gtAppId);
|
||||||
|
target.setClientId(aliyunDeviceInfo.getAliyunDeviceId());
|
||||||
|
IPushResult pushResult = iGtPush.pushMessageToSingle(singleMessage, target);
|
||||||
|
Map<String, Object> response = pushResult.getResponse();
|
||||||
|
log.info("gtPush request : " + JSONObject.toJSONString(singleMessage) + " , response : " + JSONObject.toJSONString(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//8cfcfe16d96ef9345391de475bb5297d
|
||||||
|
SingleMessage singleMessage = new SingleMessage();
|
||||||
|
Style0 style = new Style0();
|
||||||
|
// 设置通知栏标题与内容
|
||||||
|
style.setTitle("测试推送-11111");
|
||||||
|
style.setText("测试推送-11111");
|
||||||
|
// 设置通知是否响铃,震动,或者可清除
|
||||||
|
style.setRing(true);
|
||||||
|
style.setVibrate(true);
|
||||||
|
style.setClearable(true);
|
||||||
|
NotificationTemplate notificationTemplate = new NotificationTemplate();
|
||||||
|
notificationTemplate.setAppId("C2ZpsHzexi5UKuUKyW0Ig");
|
||||||
|
notificationTemplate.setAppkey("099ng3u5ud5pVGqsH0GlK");
|
||||||
|
notificationTemplate.setStyle(style);
|
||||||
|
|
||||||
|
singleMessage.setData(notificationTemplate);
|
||||||
|
singleMessage.setOffline(true);
|
||||||
|
singleMessage.setOfflineExpireTime(72 * 3600000L);
|
||||||
|
Target target = new Target();
|
||||||
|
target.setAppId("C2ZpsHzexi5UKuUKyW0Ig");
|
||||||
|
target.setClientId("fc8c87fa41da480fb769fbdae92c4cd2");
|
||||||
|
IGtPush iGtPush = new IGtPush(HOST_HTTPS, "099ng3u5ud5pVGqsH0GlK", "w3yLh3Ng4j5JYqGYH7C7o9");
|
||||||
|
IPushResult pushResult = iGtPush.pushMessageToSingle(singleMessage, target);
|
||||||
|
System.out.println(JSONObject.toJSONString(pushResult));
|
||||||
|
Map<String, Object> response = pushResult.getResponse();
|
||||||
|
System.out.println(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送普通消息 (已废弃 网易云信)
|
* 发送普通消息 (已废弃 网易云信)
|
||||||
* @param userId
|
* @param userId
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,6 @@ version = 2016-08-01
|
||||||
# \u53D1\u9001\u7684tag, tag\u8868\u8FBE\u5F0F\u53C2\u8003\u6587\u6863:https://help.aliyun.com/document_detail/48055.html?
|
# \u53D1\u9001\u7684tag, tag\u8868\u8FBE\u5F0F\u53C2\u8003\u6587\u6863:https://help.aliyun.com/document_detail/48055.html?
|
||||||
#tag =
|
#tag =
|
||||||
#tagExpression =
|
#tagExpression =
|
||||||
|
gtAppId=C2ZpsHzexi5UKuUKyW0Ig
|
||||||
|
gtAppKey=099ng3u5ud5pVGqsH0GlK
|
||||||
|
gtMasterSecret=w3yLh3Ng4j5JYqGYH7C7o9
|
||||||
Loading…
Reference in New Issue