|
@@ -19,7 +19,6 @@ 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.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;
|
|
@@ -30,14 +29,9 @@ 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 javax.annotation.Resource;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -50,8 +44,6 @@ import java.util.Map;
|
|
|
public class GeTuiUtils {
|
|
|
@Autowired
|
|
|
private CommonUserMapper commonUserMapper;
|
|
|
- @Autowired
|
|
|
- private CommonStaffMapper commonStaffMapper;
|
|
|
private String appId = "";
|
|
|
private String appKey = "";
|
|
|
private String masterSecret = "";
|
|
@@ -59,15 +51,8 @@ public class GeTuiUtils {
|
|
|
@Value("${com.changyuntong.env}")
|
|
|
private String ENV;
|
|
|
|
|
|
- public void setUserId(String userId) {
|
|
|
+ public void initGeTui(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())){
|
|
|
//司机端
|
|
@@ -80,7 +65,6 @@ public class GeTuiUtils {
|
|
|
appKey = "xhF3JuJh2Y8xjyQY4LFqo";
|
|
|
masterSecret = "e72ag0SXpU5LOvgroi7Oh5";
|
|
|
}
|
|
|
-
|
|
|
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
|
|
|
//填写应用配置
|
|
|
apiConfiguration.setAppId(appId);
|
|
@@ -94,6 +78,10 @@ public class GeTuiUtils {
|
|
|
pushApi = apiHelper.creatApi(PushApi.class);
|
|
|
}
|
|
|
|
|
|
+ public String userId;
|
|
|
+ //别名推送方式
|
|
|
+ static String host = "http://sdk.open.api.igexin.com/apiex.htm";
|
|
|
+
|
|
|
public void pushByCid(String title,String content,String userId){
|
|
|
if ("3".equals(ENV)) {
|
|
|
try {
|
|
@@ -218,175 +206,129 @@ public class GeTuiUtils {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- public void pushByCidPhone(String title,String content,String staffId){
|
|
|
- if ("3".equals(ENV)) {
|
|
|
- try {
|
|
|
-// 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());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+// public void pushByCidPhone(String title,String content,String staffId){
|
|
|
+// if ("3".equals(ENV)) {
|
|
|
+// try {
|
|
|
+//// 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());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
private static TransmissionTemplate genTransmissionTemplate(String content, String title, String appId, String appKey) throws Exception {
|
|
|
TransmissionTemplate template = new TransmissionTemplate();
|