参考:http://docs.jpush.cn/display/dev/Push-API-v3
给android,ios设备发送推送消息。
给所有用户或者单个用户推送消息。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using cn.jpush.api;
using cn.jpush.api.push;
using cn.jpush.api.report;
using cn.jpush.api.common;
using cn.jpush.api.util;
namespace JpushApiClientExample
{
class JPushApiExample
{
public class ExtralClass
{
public String sound = "ssss";
public String menu="button";
}
static void Main(string[] args)
{
Console.WriteLine("************");
Console.WriteLine("*****开始发送******");
//String result;
String app_key = "-";//需要申请
String master_secret = "-";
//int sendno = 9;
HashSet<DeviceEnum> set = new HashSet<DeviceEnum>();
set.Add(DeviceEnum.Android);
set.Add(DeviceEnum.IOS);
JPushClient client = new JPushClient(app_key, master_secret, 0, set, true);
MessageResult result = null;
NotificationParams notifyParams = new NotificationParams();
//CustomMessageParams customParams = new CustomMessageParams();
//notifyParams.
//传入json字符串
String extras = null;
extras = "{\"ios\":{\"badge\":88, \"sound\":\"happy\"}}";//ios设备推送时
//extras中有中文请用HttpUtility.UrlEncode编码
//System.Web.HttpUtility.UrlEncode(notificationContent, Encoding.UTF8);
//Console.WriteLine("*****发送带tag通知******");
/**
*发送类型
*APP_KEY 通知
*TAG TAG
*ALIAS ALIAS
*REGISTRATION_ID REGISTRATION_ID
*/
notifyParams.ReceiverType = ReceiverTypeEnum.REGISTRATION_ID;
notifyParams.ReceiverValue = "4455cda4f16";//单个用户设备标识
notifyParams.SendNo = 256;
/*****单个用户推送****/
//result = client.sendNotification("测试单个用户的推送消息", notifyParams, extras);//给某个用户推送消息
/*****广播形式****/
result = client.sendNotificationAll("测试广播信息");//广播--全体推送
Console.WriteLine("sendNotification by tag:**返回状态:" + result.getErrorCode().ToString() +
" **返回信息:" + result.getErrorMessage() +
" **Send No.:" + result.getSendNo() +
" msg_id:" + result.getMessageId() +
" 频率次数:" + result.getRateLimitQuota() +
" 可用频率:" + result.getRateLimitRemaining() +
" 重置时间:" + result.getRateLimitReset());
}
public class IOSExtras
{
public int badge = 888;
public String sound = "happy";
}
}
}