|
@@ -1,5 +1,6 @@
|
|
|
package com.yh.saas.plugin.yiliangyiyun.util;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
import com.getui.push.v2.sdk.ApiHelper;
|
|
|
import com.getui.push.v2.sdk.GtApiConfiguration;
|
|
|
import com.getui.push.v2.sdk.api.PushApi;
|
|
@@ -11,25 +12,32 @@ import com.getui.push.v2.sdk.dto.req.message.PushChannel;
|
|
|
import com.getui.push.v2.sdk.dto.req.message.PushDTO;
|
|
|
import com.getui.push.v2.sdk.dto.req.message.PushMessage;
|
|
|
import com.getui.push.v2.sdk.dto.req.message.android.AndroidDTO;
|
|
|
+import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
|
|
|
import com.getui.push.v2.sdk.dto.req.message.android.ThirdNotification;
|
|
|
import com.getui.push.v2.sdk.dto.req.message.android.Ups;
|
|
|
import com.getui.push.v2.sdk.dto.req.message.ios.Alert;
|
|
|
import com.getui.push.v2.sdk.dto.req.message.ios.Aps;
|
|
|
import com.getui.push.v2.sdk.dto.req.message.ios.IosDTO;
|
|
|
import com.gexin.rp.sdk.base.IPushResult;
|
|
|
-import com.gexin.rp.sdk.base.impl.AppMessage;
|
|
|
+import com.winnerlook.model.VoiceNotifyBody;
|
|
|
import com.gexin.rp.sdk.base.impl.SingleMessage;
|
|
|
import com.gexin.rp.sdk.base.impl.Target;
|
|
|
import com.gexin.rp.sdk.base.payload.APNPayload;
|
|
|
import com.gexin.rp.sdk.exceptions.RequestException;
|
|
|
import com.gexin.rp.sdk.http.IGtPush;
|
|
|
import com.gexin.rp.sdk.template.TransmissionTemplate;
|
|
|
+import com.winsea.svc.base.base.entity.CommonStaff;
|
|
|
+import com.winsea.svc.base.base.mapper.CommonStaffMapper;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.CommonUser;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.mapper.CommonUserMapper;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -38,20 +46,41 @@ import java.util.Map;
|
|
|
* @Description: 个推Util类
|
|
|
* @Date:Created in 9:38 2021-06-03
|
|
|
*/
|
|
|
-
|
|
|
@Component
|
|
|
public class GeTuiUtils {
|
|
|
@Autowired
|
|
|
private CommonUserMapper commonUserMapper;
|
|
|
- private static String appId = "q2frjgRYqt7RuC9Vjj6Va9";
|
|
|
- private static String appKey = "L0gnzFQa2O8aFW15lPRzh2";
|
|
|
- private static String masterSecret = "NhuCKHZJhp877ofHWtlQWA";
|
|
|
+ @Autowired
|
|
|
+ private CommonStaffMapper commonStaffMapper;
|
|
|
+ private String appId = "";
|
|
|
+ private String appKey = "";
|
|
|
+ private String masterSecret = "";
|
|
|
PushApi pushApi = null;
|
|
|
+ @Value("${com.changyuntong.env}")
|
|
|
+ private String ENV;
|
|
|
+
|
|
|
+ public void setUserId(String userId) {
|
|
|
+ this.userId = userId;
|
|
|
+ }
|
|
|
|
|
|
+ public String userId;
|
|
|
//别名推送方式
|
|
|
static String host = "http://sdk.open.api.igexin.com/apiex.htm";
|
|
|
|
|
|
public GeTuiUtils(){
|
|
|
+ CommonUser userDO = this.commonUserMapper.selectById(userId);
|
|
|
+ if("1".equals(userDO.getIdentification())){
|
|
|
+ //司机端
|
|
|
+ appId = "EjFcDQXGAu7MR3rvxqPB77";
|
|
|
+ appKey = "e2CbYjkmzs8gyPtOHRlwZ4";
|
|
|
+ masterSecret = "biZ1A0Evm2ABIuk0lKDVA";
|
|
|
+ }else {
|
|
|
+ //货主端
|
|
|
+ appId = "cESNrYEdCn5rDqpBoHC4N5";
|
|
|
+ appKey = "xhF3JuJh2Y8xjyQY4LFqo";
|
|
|
+ masterSecret = "e72ag0SXpU5LOvgroi7Oh5";
|
|
|
+ }
|
|
|
+
|
|
|
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
|
|
|
//填写应用配置
|
|
|
apiConfiguration.setAppId(appId);
|
|
@@ -66,100 +95,300 @@ public class GeTuiUtils {
|
|
|
}
|
|
|
|
|
|
public void pushByCid(String title,String content,String userId){
|
|
|
- try{
|
|
|
- CommonUser userDO = commonUserMapper.selectById(userId);
|
|
|
- String cid = userDO.getCid();
|
|
|
- //根据cid进行单推
|
|
|
- PushDTO<Audience> pushDTO = new PushDTO<Audience>();
|
|
|
- // 设置推送参数
|
|
|
- pushDTO.setRequestId(System.currentTimeMillis() + "");//requestid需要每次变化唯一
|
|
|
- //配置推送条件
|
|
|
- // 1: 表示该消息在用户在线时推送个推通道,用户离线时推送厂商通道;
|
|
|
- // 2: 表示该消息只通过厂商通道策略下发,不考虑用户是否在线;
|
|
|
- // 3: 表示该消息只通过个推通道下发,不考虑用户是否在线;
|
|
|
- // 4: 表示该消息优先从厂商通道下发,若消息内容在厂商通道代发失败后会从个推通道下发。
|
|
|
- Strategy strategy=new Strategy();
|
|
|
- strategy.setDef(1);
|
|
|
- Settings settings=new Settings();
|
|
|
- settings.setStrategy(strategy);
|
|
|
- pushDTO.setSettings(settings);
|
|
|
- settings.setTtl(3600000);//消息有效期,走厂商消息需要设置该值
|
|
|
- //推送苹果离线通知标题内容
|
|
|
- Alert alert=new Alert();
|
|
|
- alert.setTitle(title);
|
|
|
- alert.setBody(content);
|
|
|
- Aps aps = new Aps();
|
|
|
- //1表示静默推送(无通知栏消息),静默推送时不需要填写其他参数。
|
|
|
- //苹果建议1小时最多推送3条静默消息
|
|
|
- aps.setContentAvailable(0);
|
|
|
- aps.setSound("default");
|
|
|
- aps.setAlert(alert);
|
|
|
- IosDTO iosDTO = new IosDTO();
|
|
|
- iosDTO.setAps(aps);
|
|
|
- iosDTO.setType("notify");
|
|
|
- PushChannel pushChannel = new PushChannel();
|
|
|
- pushChannel.setIos(iosDTO);
|
|
|
- //安卓离线厂商通道推送消息体
|
|
|
+ if ("3".equals(ENV)) {
|
|
|
+ try {
|
|
|
+ CommonUser userDO = commonUserMapper.selectById(userId);
|
|
|
+ if("1".equals(userDO.getIdentification())){
|
|
|
+ //司机端
|
|
|
+ appId = "EjFcDQXGAu7MR3rvxqPB77";
|
|
|
+ appKey = "e2CbYjkmzs8gyPtOHRlwZ4";
|
|
|
+ masterSecret = "biZ1A0Evm2ABIuk0lKDVA";
|
|
|
+ }else {
|
|
|
+ //货主端
|
|
|
+ appId = "cESNrYEdCn5rDqpBoHC4N5";
|
|
|
+ appKey = "xhF3JuJh2Y8xjyQY4LFqo";
|
|
|
+ masterSecret = "e72ag0SXpU5LOvgroi7Oh5";
|
|
|
+ }
|
|
|
+ String cid = userDO.getCid();
|
|
|
+ //根据cid进行单推
|
|
|
+ PushDTO<Audience> pushDTO = new PushDTO<Audience>();
|
|
|
+ // 设置推送参数
|
|
|
+ pushDTO.setRequestId(System.currentTimeMillis() + "");//requestid需要每次变化唯一
|
|
|
+ //配置推送条件
|
|
|
+ // 1: 表示该消息在用户在线时推送个推通道,用户离线时推送厂商通道;
|
|
|
+ // 2: 表示该消息只通过厂商通道策略下发,不考虑用户是否在线;
|
|
|
+ // 3: 表示该消息只通过个推通道下发,不考虑用户是否在线;
|
|
|
+ // 4: 表示该消息优先从厂商通道下发,若消息内容在厂商通道代发失败后会从个推通道下发。
|
|
|
+ Strategy strategy = new Strategy();
|
|
|
+ strategy.setDef(1);
|
|
|
+ Settings settings = new Settings();
|
|
|
+ settings.setStrategy(strategy);
|
|
|
+ pushDTO.setSettings(settings);
|
|
|
+ settings.setTtl(3600000);//消息有效期,走厂商消息需要设置该值
|
|
|
+ //推送苹果离线通知标题内容
|
|
|
+ Alert alert = new Alert();
|
|
|
+ alert.setTitle(title);
|
|
|
+ alert.setBody(content);
|
|
|
+ Aps aps = new Aps();
|
|
|
+ //1表示静默推送(无通知栏消息),静默推送时不需要填写其他参数。
|
|
|
+ //苹果建议1小时最多推送3条静默消息
|
|
|
+ aps.setContentAvailable(0);
|
|
|
+ aps.setSound("pushsound.caf");
|
|
|
+ aps.setAlert(alert);
|
|
|
+ IosDTO iosDTO = new IosDTO();
|
|
|
+ iosDTO.setAps(aps);
|
|
|
+ iosDTO.setType("notify");
|
|
|
+ PushChannel pushChannel = new PushChannel();
|
|
|
+ pushChannel.setIos(iosDTO);
|
|
|
+ //安卓离线厂商通道推送消息体
|
|
|
// PushChannel pushChannel = new PushChannel();
|
|
|
- AndroidDTO androidDTO = new AndroidDTO();
|
|
|
- Ups ups = new Ups();
|
|
|
- ThirdNotification notification1 = new ThirdNotification();;
|
|
|
- ups.setNotification(notification1);
|
|
|
- notification1.setTitle(title);
|
|
|
- notification1.setBody(content);
|
|
|
- notification1.setClickType("intent");
|
|
|
- notification1.setIntent("intent:#Intent;launchFlags=0x04000000;action=android.intent.action.oppopush;component=uni.UNI7297DA2/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title="+title+";S.content="+content+";S.payload=test;end");
|
|
|
- //各厂商自有功能单项设置
|
|
|
- //ups.addOption("HW", "/message/android/notification/badge/class", "io.dcloud.PandoraEntry ");
|
|
|
- //ups.addOption("HW", "/message/android/notification/badge/add_num", 1);
|
|
|
- //ups.addOption("HW", "/message/android/notification/importance", "HIGH");
|
|
|
- //ups.addOption("VV","classification",1);
|
|
|
- androidDTO.setUps(ups);
|
|
|
- pushChannel.setAndroid(androidDTO);
|
|
|
- pushDTO.setPushChannel(pushChannel);
|
|
|
- // PushMessage在线走个推通道才会起作用的消息体
|
|
|
- PushMessage pushMessage = new PushMessage();
|
|
|
- pushMessage.setTransmission(" {title:\""+title+"\",content:\""+content+"\",payload:\"test\"}");
|
|
|
- pushDTO.setPushMessage(pushMessage);
|
|
|
+ AndroidDTO androidDTO = new AndroidDTO();
|
|
|
+ Ups ups = new Ups();
|
|
|
+ ThirdNotification notification1 = new ThirdNotification();
|
|
|
+ ;
|
|
|
+ notification1.setTitle(title);
|
|
|
+ notification1.setBody(content);
|
|
|
+ notification1.setClickType("intent");
|
|
|
+ notification1.setIntent("intent:#Intent;launchFlags=0x04000000;action=android.intent.action.oppopush;component=uni.UNI7297DA2/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=" + title + ";S.content=" + content + ";S.payload=test;end");
|
|
|
+ ups.setNotification(notification1);
|
|
|
+ //各厂商自有功能单项设置
|
|
|
+ ups.addOption("HW", "/message/android/notification/badge/class", "io.dcloud.PandoraEntry ");
|
|
|
+ ups.addOption("HW", "/message/android/notification/badge/add_num", 1);
|
|
|
+ ups.addOption("HW", "/message/android/notification/sound", "/raw/ring");
|
|
|
+ ups.addOption("HW", "/message/android/notification/channel_id", "task2");
|
|
|
+ ups.addOption("HW", "/message/android/notification/importance", "NORMAL");
|
|
|
+ ups.addOption("HW", "/message/android/notification/category", "WORK");
|
|
|
+ ups.addOption("HW", "/message/android/notification/default_sound", false);
|
|
|
+ ups.addOption("XM", "/extra.sound_uri", "android.resource://uni.UNI7297DA2/raw/task1");
|
|
|
+ ups.addOption("XM", "/extra.channel_id", "high_custom_5");
|
|
|
+ //ups.addOption("VV","classification",1);
|
|
|
+ androidDTO.setUps(ups);
|
|
|
+ pushChannel.setAndroid(androidDTO);
|
|
|
+ pushDTO.setPushChannel(pushChannel);
|
|
|
+ // PushMessage在线走个推通道才会起作用的消息体
|
|
|
+ PushMessage pushMessage = new PushMessage();
|
|
|
+ GTNotification gtNotification = new GTNotification();
|
|
|
+ gtNotification.setTitle(title);
|
|
|
+ gtNotification.setBody(content);
|
|
|
+ gtNotification.setRingName("ring");
|
|
|
+ gtNotification.setChannelId("task1");
|
|
|
+ gtNotification.setChannelName("消息通知");
|
|
|
+ gtNotification.setChannelLevel("4");
|
|
|
+ gtNotification.setClickType("startapp");
|
|
|
+ gtNotification.setLogo("logo.png");
|
|
|
+ pushMessage.setNotification(gtNotification);
|
|
|
+// pushMessage.setTransmission(" {title:\""+title+"\",content:\""+content+"\",payload:\"test\"}");
|
|
|
+ pushDTO.setPushMessage(pushMessage);
|
|
|
// pushMessage.setTransmission(" {title:\"标题\",content:\"内容\",payload:\"自定义数据\"}");
|
|
|
- // 设置接收人信息
|
|
|
- Audience audience = new Audience();
|
|
|
- pushDTO.setAudience(audience);
|
|
|
- audience.addCid(cid);
|
|
|
-
|
|
|
- // 进行cid单推
|
|
|
- ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO);
|
|
|
- if (apiResult.isSuccess()) {
|
|
|
- // success
|
|
|
- System.out.println("个推 通知消息3:"+apiResult.getData());
|
|
|
- } else {
|
|
|
- // failed
|
|
|
- System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
|
|
|
+ // 设置接收人信息
|
|
|
+ Audience audience = new Audience();
|
|
|
+ pushDTO.setAudience(audience);
|
|
|
+ audience.addCid(cid);
|
|
|
+
|
|
|
+ // 进行cid单推
|
|
|
+ ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO);
|
|
|
+ if (apiResult.isSuccess()) {
|
|
|
+ // success
|
|
|
+ System.out.println("个推 通知消息3:" + apiResult.getData());
|
|
|
+ } else {
|
|
|
+ // failed
|
|
|
+ System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
|
|
|
+ }
|
|
|
+ //推送穿透消息
|
|
|
+ IGtPush push = new IGtPush(host, appKey, masterSecret);
|
|
|
+ TransmissionTemplate template = genTransmissionTemplate(content, title, appId, appKey);// 设定消息模式为透传
|
|
|
+ SingleMessage msg = new SingleMessage();// 个人推送
|
|
|
+ msg.setOffline(true);
|
|
|
+ msg.setOfflineExpireTime(2 * 1000 * 3600);
|
|
|
+ msg.setData(template);
|
|
|
+ Target target = new Target();// 设定接收人
|
|
|
+ target.setAppId(appId);
|
|
|
+ target.setClientId(cid);
|
|
|
+ try {
|
|
|
+ IPushResult ret = push.pushMessageToSingle(msg, target);
|
|
|
+ System.out.println("个推 通知消息1:" + ret.getResponse().toString());
|
|
|
+ } catch (RequestException e) {
|
|
|
+ String requstId = e.getRequestId();
|
|
|
+ IPushResult ret = push.pushMessageToSingle(msg, target, requstId);
|
|
|
+ System.out.println("个推 通知消息2:" + ret.getResponse().toString());
|
|
|
+ }
|
|
|
+ System.out.println("推送成功:" + userDO.getUserName() + "," + title + "," + content);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("推送异常:" + e.getMessage());
|
|
|
}
|
|
|
- //推送穿透消息
|
|
|
- IGtPush push = new IGtPush(host, appKey, masterSecret);
|
|
|
- TransmissionTemplate template = genTransmissionTemplate(content, title);// 设定消息模式为透传
|
|
|
- SingleMessage msg = new SingleMessage();// 个人推送
|
|
|
- msg.setOffline(true);
|
|
|
- msg.setOfflineExpireTime(2 * 1000 * 3600);
|
|
|
- msg.setData(template);
|
|
|
- Target target = new Target();// 设定接收人
|
|
|
- target.setAppId(appId);
|
|
|
- target.setClientId(cid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void pushByCidPhone(String title,String content,String staffId){
|
|
|
+ if ("3".equals(ENV)) {
|
|
|
try {
|
|
|
- IPushResult ret = push.pushMessageToSingle(msg, target);
|
|
|
- System.out.println("个推 通知消息1:"+ret.getResponse().toString());
|
|
|
- } catch (RequestException e) {
|
|
|
- String requstId = e.getRequestId();
|
|
|
- IPushResult ret = push.pushMessageToSingle(msg, target, requstId);
|
|
|
- System.out.println("个推 通知消息2:"+ret.getResponse().toString());
|
|
|
+// CommonUser userDO = commonUserMapper.selectById(userId);
|
|
|
+ CommonStaff commonStaff = commonStaffMapper.selectById(staffId);
|
|
|
+ List<CommonUser> list = commonUserMapper.selectList(new EntityWrapper<CommonUser>()
|
|
|
+ .eq("phone",commonStaff.getStaffMobilePhone())
|
|
|
+ .eq("delete_flag",0));
|
|
|
+ String cid = "";
|
|
|
+ if(list.size() > 0){
|
|
|
+ cid = list.get(0).getCid();
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //根据cid进行单推
|
|
|
+ PushDTO<Audience> pushDTO = new PushDTO<Audience>();
|
|
|
+ // 设置推送参数
|
|
|
+ pushDTO.setRequestId(System.currentTimeMillis() + "");//requestid需要每次变化唯一
|
|
|
+ //配置推送条件
|
|
|
+ // 1: 表示该消息在用户在线时推送个推通道,用户离线时推送厂商通道;
|
|
|
+ // 2: 表示该消息只通过厂商通道策略下发,不考虑用户是否在线;
|
|
|
+ // 3: 表示该消息只通过个推通道下发,不考虑用户是否在线;
|
|
|
+ // 4: 表示该消息优先从厂商通道下发,若消息内容在厂商通道代发失败后会从个推通道下发。
|
|
|
+ Strategy strategy = new Strategy();
|
|
|
+ strategy.setDef(1);
|
|
|
+ Settings settings = new Settings();
|
|
|
+ settings.setStrategy(strategy);
|
|
|
+ pushDTO.setSettings(settings);
|
|
|
+ settings.setTtl(3600000);//消息有效期,走厂商消息需要设置该值
|
|
|
+ //推送苹果离线通知标题内容
|
|
|
+ Alert alert = new Alert();
|
|
|
+ alert.setTitle(title);
|
|
|
+ alert.setBody(content);
|
|
|
+ Aps aps = new Aps();
|
|
|
+ //1表示静默推送(无通知栏消息),静默推送时不需要填写其他参数。
|
|
|
+ //苹果建议1小时最多推送3条静默消息
|
|
|
+ aps.setContentAvailable(0);
|
|
|
+ aps.setSound("pushsound.caf");
|
|
|
+ aps.setAlert(alert);
|
|
|
+ IosDTO iosDTO = new IosDTO();
|
|
|
+ iosDTO.setAps(aps);
|
|
|
+ iosDTO.setType("notify");
|
|
|
+ PushChannel pushChannel = new PushChannel();
|
|
|
+ pushChannel.setIos(iosDTO);
|
|
|
+ //安卓离线厂商通道推送消息体
|
|
|
+// PushChannel pushChannel = new PushChannel();
|
|
|
+ AndroidDTO androidDTO = new AndroidDTO();
|
|
|
+ Ups ups = new Ups();
|
|
|
+ ThirdNotification notification1 = new ThirdNotification();
|
|
|
+ ;
|
|
|
+ notification1.setTitle(title);
|
|
|
+ notification1.setBody(content);
|
|
|
+ notification1.setClickType("intent");
|
|
|
+ notification1.setIntent("intent:#Intent;launchFlags=0x04000000;action=android.intent.action.oppopush;component=uni.UNI7297DA2/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=" + title + ";S.content=" + content + ";S.payload=test;end");
|
|
|
+ ups.setNotification(notification1);
|
|
|
+ //各厂商自有功能单项设置
|
|
|
+ ups.addOption("HW", "/message/android/notification/badge/class", "io.dcloud.PandoraEntry ");
|
|
|
+ ups.addOption("HW", "/message/android/notification/badge/add_num", 1);
|
|
|
+ ups.addOption("HW", "/message/android/notification/sound", "/raw/ring");
|
|
|
+ ups.addOption("HW", "/message/android/notification/channel_id", "task2");
|
|
|
+ ups.addOption("HW", "/message/android/notification/importance", "NORMAL");
|
|
|
+ ups.addOption("HW", "/message/android/notification/category", "WORK");
|
|
|
+ ups.addOption("HW", "/message/android/notification/default_sound", false);
|
|
|
+ ups.addOption("XM", "/extra.sound_uri", "android.resource://uni.UNI7297DA2/raw/task1");
|
|
|
+ ups.addOption("XM", "/extra.channel_id", "high_custom_5");
|
|
|
+ //ups.addOption("VV","classification",1);
|
|
|
+ androidDTO.setUps(ups);
|
|
|
+ pushChannel.setAndroid(androidDTO);
|
|
|
+ pushDTO.setPushChannel(pushChannel);
|
|
|
+ // PushMessage在线走个推通道才会起作用的消息体
|
|
|
+ PushMessage pushMessage = new PushMessage();
|
|
|
+ GTNotification gtNotification = new GTNotification();
|
|
|
+ gtNotification.setTitle(title);
|
|
|
+ gtNotification.setBody(content);
|
|
|
+ gtNotification.setRingName("ring");
|
|
|
+ gtNotification.setChannelId("task1");
|
|
|
+ gtNotification.setChannelName("工作事项提醒");
|
|
|
+ gtNotification.setChannelLevel("4");
|
|
|
+ gtNotification.setClickType("startapp");
|
|
|
+ gtNotification.setLogo("logo.png");
|
|
|
+ pushMessage.setNotification(gtNotification);
|
|
|
+// pushMessage.setTransmission(" {title:\""+title+"\",content:\""+content+"\",payload:\"test\"}");
|
|
|
+ pushDTO.setPushMessage(pushMessage);
|
|
|
+// pushMessage.setTransmission(" {title:\"标题\",content:\"内容\",payload:\"自定义数据\"}");
|
|
|
+ // 设置接收人信息
|
|
|
+ Audience audience = new Audience();
|
|
|
+ pushDTO.setAudience(audience);
|
|
|
+ audience.addCid(cid);
|
|
|
+
|
|
|
+ // 进行cid单推
|
|
|
+ ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO);
|
|
|
+ if (apiResult.isSuccess()) {
|
|
|
+ // success
|
|
|
+ System.out.println("个推 通知消息3:" + apiResult.getData());
|
|
|
+ } else {
|
|
|
+ // failed
|
|
|
+ System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
|
|
|
+ }
|
|
|
+ //推送穿透消息
|
|
|
+ IGtPush push = new IGtPush(host, appKey, masterSecret);
|
|
|
+ TransmissionTemplate template = genTransmissionTemplate(content, title, appId, appKey);// 设定消息模式为透传
|
|
|
+ SingleMessage msg = new SingleMessage();// 个人推送
|
|
|
+ msg.setOffline(true);
|
|
|
+ msg.setOfflineExpireTime(2 * 1000 * 3600);
|
|
|
+ msg.setData(template);
|
|
|
+ Target target = new Target();// 设定接收人
|
|
|
+ target.setAppId(appId);
|
|
|
+ target.setClientId(cid);
|
|
|
+ try {
|
|
|
+ IPushResult ret = push.pushMessageToSingle(msg, target);
|
|
|
+ System.out.println("个推 通知消息1:" + ret.getResponse().toString());
|
|
|
+ } catch (RequestException e) {
|
|
|
+ String requstId = e.getRequestId();
|
|
|
+ IPushResult ret = push.pushMessageToSingle(msg, target, requstId);
|
|
|
+ System.out.println("个推 通知消息2:" + ret.getResponse().toString());
|
|
|
+ }
|
|
|
+ System.out.println("推送成功:" + list.get(0).getUserName() + "," + title + "," + content);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("推送异常:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception e){
|
|
|
- System.out.println("推送异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void callPhone(String userId) throws Exception {
|
|
|
+ CommonStaff commonStaff= commonStaffMapper.selectById(userId);
|
|
|
+ System.out.println("result = " + commonStaff.getStaffName());
|
|
|
+ System.out.println("----------------------");
|
|
|
+ // 电话信息
|
|
|
+
|
|
|
+ /*请修改为平台分配的accountId*/
|
|
|
+ String accountId="285481";
|
|
|
+ /*请修改为平台分配的token*/
|
|
|
+ String token="9e412526531a43f296d23bb29771c761";
|
|
|
+ VoiceNotifyBody message = new VoiceNotifyBody();
|
|
|
+ /*用户接收回执的服务器地址*/
|
|
|
+ message.setCallbackUrl("http://192.168.1.102:9780/voice/api/VoiceWeb/receiveRecord");
|
|
|
+// CommonStaff commonStaff= commonStaffMapper.selectById(userId);
|
|
|
+// message.setCalleeNumber("18840825257");
|
|
|
+ if(commonStaff != null){
|
|
|
+ message.setCalleeNumber(commonStaff.getStaffMobilePhone());
|
|
|
}
|
|
|
+ message.setReplayTimes(3);
|
|
|
+ message.setDisplayNumber("");
|
|
|
+
|
|
|
+ /*设置平台分配的模板ID*/
|
|
|
+ message.setTemplateId("401047");
|
|
|
+
|
|
|
+ LinkedHashMap<String,String> params = new LinkedHashMap<String,String>();
|
|
|
+ /*设置模板参数*/
|
|
|
+// params.put("{1}","八就二六五四三五一");
|
|
|
+ /*params.put("{2}","您好");
|
|
|
+ params.put("{3}","895621");*/
|
|
|
+ message.setTemplateArgs(params);
|
|
|
+
|
|
|
+ try {
|
|
|
+// VoiceResponseResult result = VoiceSender.httpsSendVoiceNotify(message, accountId, token);
|
|
|
+
|
|
|
+// System.out.println("result = " + result);
|
|
|
+
|
|
|
+ }catch (Exception e) {
|
|
|
+ //Log.e(this.getClass(), " e = " + e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- private static TransmissionTemplate genTransmissionTemplate(String content, String title) throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static TransmissionTemplate genTransmissionTemplate(String content, String title, String appId, String appKey) throws Exception {
|
|
|
TransmissionTemplate template = new TransmissionTemplate();
|
|
|
template.setAppId(appId);
|
|
|
template.setAppkey(appKey);
|
|
@@ -175,7 +404,7 @@ public class GeTuiUtils {
|
|
|
|
|
|
apnpayload.setContentAvailable(1);// 推送直接带有透传数据
|
|
|
// apnpayload.setBadge(0);//应用icon上显示的数字
|
|
|
- apnpayload.setSound("default");// 通知铃声文件名
|
|
|
+ apnpayload.setSound("pushsound.caf");// 通知铃声文件名
|
|
|
// apnpayload.setAlertMsg(alertMsg);
|
|
|
template.setAPNInfo(apnpayload);
|
|
|
template.setTransmissionType(2);
|