.net 极光推送
作者:互联网
/// <summary>
/// 应用标识:极光推送的用户名(设备)
/// </summary>
private readonly string AppKey = ConfigurationManager.AppSettings["AppKey"];
/// <summary>
/// 极光推送的密码(设备)
/// </summary>
private readonly string MasterSecret = ConfigurationManager.AppSettings["MasterSecret"];
/// <summary>
/// 测试极光推送
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
[HttpPost]
[Route("api/Device/Jpush/TestJpush/")]
public TestJpushResult TestJpush([FromBody]TestJpushModels model)
{
List<JpushModels> list = new List<JpushModels>();
JpushModels jModel = new JpushModels();
jModel.productid = 1;
jModel.price = "12";
JpushModels jModel1 = new JpushModels();
jModel1.productid = 2;
jModel1.price = "13";
JpushModels jModel2 = new JpushModels();
jModel2.productid = 3;
jModel2.price = "14";
list.Add(jModel);
list.Add(jModel1);
list.Add(jModel2);
try
{
JPushClient client = new JPushClient(AppKey, MasterSecret);
PushPayload pushPayload_alias = new PushPayload()
{
platform = Platform.android()
};
string[] alias = new string[] { model.code };
pushPayload_alias.audience = Audience.s_alias(alias);//别名
//通知
//var notification = new Notification();
//notification.AndroidNotification = new AndroidNotification().setAlert(model.title).AddExtra("action1", "101");
//pushPayload_alias.notification = notification;
string data = JsonConvert.SerializeObject(list);
//自定义
pushPayload_alias.message = Message.content(model.content).AddExtras("action1", "100").AddExtras("data", data).setTitle(model.title);
bool b = client.SendPush(pushPayload_alias).isResultOK();
if (b)
{
return new TestJpushResult { ResCode = ResCode.Ok, ResMsg = "成功" };
}
else
{
return new TestJpushResult { ResCode = ResCode.Ok, ResMsg = "失败" };
}
}
catch (Exception ex)
{
return new TestJpushResult { ResCode = ResCode.Fail, ResMsg = ex.ToString()};
}
}
1.引用极光推送程序集
2.在极光服务器先设置别名信息
标签:JpushModels,string,ResCode,极光,list,alias,new,net,推送 来源: https://www.cnblogs.com/tfeblog/p/11355831.html