极光推送


/// <summary>
/// 应用标识:极光推送的用户名(门禁)
/// </summary>
private readonly string AppKey = ConfigurationManager.AppSettings["AppKey"];
/// <summary>
/// 极光推送的密码(门禁)
/// </summary>
private readonly string MasterSecret = ConfigurationManager.AppSettings["MasterSecret"];


//***有一条待审核订单
/// <summary>
/// 订单消息推送
/// </summary>
/// <param name="nextcode">下个审核节点(审核完后)</param>
public AppOrderPushResult AppOrderPush(string nextcode)
{
//流程配置表找权限编号->用户表中找对应审核人
var count = 0;
string R_Id = context.AuditConfigure.SingleOrDefault(s => s.AC_Code == nextcode).R_Id;
var list = context.Users.Where(s => s.R_Id == R_Id && s.U_Status == "0").ToList();
if (list.Count() > 0)
{
foreach (var item in list)
{
if (SendAppContent(item.U_Name,item.jpushid))
{
count += 1;
}
}
if (count > 0)
{
return new AppOrderPushResult { ResCode = ResCode.Ok, ResMsg = "消息推送成功" };
}
else
{
return new AppOrderPushResult { ResCode = ResCode.Fail, ResMsg = "消息推送失败" };
}
}
else
{
return new AppOrderPushResult { ResCode = ResCode.Fail, ResMsg = "消息推送失败" };
}
}


/// <summary>
/// 极光推送
/// </summary>
/// <param name="name">name</param>
/// <param name="jpushid">jpushid</param>
/// <returns></returns>
public bool SendAppContent(string name, string jpushid)
{
if (!string.IsNullOrEmpty(jpushid) && jpushid != "" && jpushid.Trim() != "")
{
JPushClient client = new JPushClient(AppKey, MasterSecret);
string content = name + "有一条消息待审核。";

PushPayload pushPayload = new PushPayload();
pushPayload.platform = Platform.all();
pushPayload.audience = Audience.s_registrationId(jpushid);
pushPayload.message = Message.content(content)
.AddExtras("type", "104");

var jresult = client.SendPush(pushPayload);
return jresult.isResultOK();
}
else
{
return false;
}
}

posted on 2019-03-19 10:31  *tfe*  阅读(115)  评论(0编辑  收藏  举报

导航