unipush消息推送DCloud开发者中心中通过clientid进行推送测试成功;华为手机客户端能接收到推送消息服务;
在App.vue中获取clientid
export default {
onLaunch: function () {
//#ifdef APP-PLUS
plus.push.getClientInfo().clientid
//#endif
},
服务器后台使用.net 对单个用户clientid进行消息送,消息推送结果失败,另外是否一定在开发者中心设置厂商推送设置,能否通过华为手机没有APPKEY 怎么解决;
/// <summary>
/// 消息推送
/// </summary>
public class Program
{
//采用"C# SDK 快速入门", "第二步 获取访问凭证 "中获得的应用配置,用户可自行替换
private static String APPID = "UNIxxx";
private static String APPKEY = "";
private static String MASTERSECRET = "";
//您获取的clientID
private static String CLIENTID1 = "094a875xxxxxxxx";
private static String CLIENTID2 = "";
//别名推送方式
//private static String ALIAS = "";
//HOST:OpenService接口地址
private static String HOST = "http://sdk.open.api.igexin.com/apiex.htm";
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
//toList接口每个用户状态返回是否开启,可选
//Console.OutputEncoding = Encoding.GetEncoding(936);
Environment.SetEnvironmentVariable("needDetails", "true");
//1.对单个用户推送消息接口
PushMessageToSingle();
//2.对指定列表用户推送消息接口
//PushMessageToList();
//3.对指定应用群推送消息接口
//pushMessageToApp();
//5.批量单推送功能接口
//singleBatchPushMessage();
}
#region 对单个用户推送消息
/// <summary>
/// 对单个用户推送消息
/// </summary>
private static void PushMessageToSingle()
{
IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
//消息模版:TransmissionTemplate:透传模板
TransmissionTemplate template = TransmissionTemplateDemo();
// 单推消息模型
SingleMessage message = new SingleMessage();
message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选
message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选
message.Data = template;
//判断是否客户端是否wifi环境下推送,2为4G/3G/2G,1为在WIFI环境下,0为不限制环境
//message.PushNetWorkType = 1;
com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target();
target.appId = APPID;
target.clientId = CLIENTID1;
//target.alias = ALIAS;
try
{
String pushResult = push.pushMessageToSingle(message, target);
System.Console.WriteLine("-----------------------------------------------");
System.Console.WriteLine("-----------------------------------------------");
System.Console.WriteLine("----------------服务端返回结果:" + pushResult);
}
catch (RequestException e)
{
String requestId = e.RequestId;
//发送失败后的重发
String pushResult = push.pushMessageToSingle(message, target, requestId);
System.Console.WriteLine("-----------------------------------------------");
System.Console.WriteLine("-----------------------------------------------");
System.Console.WriteLine("----------------服务端返回结果:" + pushResult);
}
}
//透传模板动作内容
public static TransmissionTemplate TransmissionTemplateDemo()
{
TransmissionTemplate template = new TransmissionTemplate();
template.AppId = APPID;
template.AppKey = APPKEY;
//应用启动类型,1:强制应用启动 2:等待应用启动
template.TransmissionType = "1";
//透传内容
template.TransmissionContent = "透传内容";
//设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)
//String begin = "2015-03-06 14:36:10";
//String end = "2015-03-06 14:46:20";
//template.setDuration(begin, end);
Notify noti = new Notify();
noti.Title = "消息推送";
noti.Content = "家庭医生消息推送服务测试";
// noti.Type = NotifyInfo.Types.Type._url;
//noti.Url = "www.baidu.com";
noti.Type = NotifyInfo.Types.Type._intent;
noti.Intent = "intent:#Intent;launchFlags=0x14000000;package=com.pp.yl;component=你的包名/com.getui.demo.MainActivity; i.parm1 = 12; end";
template.set3rdNotifyInfo(noti);
return template;
}
#endregion
}