极光推送(C#)
推荐使用appSetting 加载这两个参数
webConfig:
<appSettings>
<add key="AppKey" value="cccd6fdda0861377ac46cef"/>
<add key="MasterSecret" value="9083f51304b8d9723bc5d58"/>
</appSettings>
C#:
string AppKey = ConfigurationManager.AppSettings["AppKey"];
string MasterSecret = ConfigurationManager.AppSettings["MasterSecret"];
极光推送需要的dll文件下载链接:Jpush_Newtonsoft
将文件解压后的dll引入项目,并且添加响应的命名空间
C#:
using cn.jpush.api;
using cn.jpush.api.push.mode;
using cn.jpush.api.push.notification;
产生推送:
C#:
JPushClient client = new JPushClient( AppKey, MasterSecret);//根据app信息生成推送client
PushPayload payLoad = JPushObjecWithExtrasAndMessage();//设置推送的具体参数
try
{
var reslut = client.SendPush(payLoad);//推送
var apiReslut = client.getReceivedApi(reslut.msg_id.ToString());//接收推送结果
Alert.Show(apiReslut.isResultOK().ToString() + ":" + apiReslut.getErrorMessage());
}
catch (Exception ex)
{
Alert.Show(ex.Message);
}
推送的具体参数实例:
C#:
public PushPayload JPushObjecWithExtrasAndMessage()
{
PushPayload pushPayload = new PushPayload();
pushPayload.platform = Platform.all();
pushPayload.audience = Audience.all();
pushPayload.notification = new Notification().setAlert(ALERT);
return pushPayload;
}
推送具体参数的讲解:
platform :推送平台
public static Platform all();//全部
public static Platform android();//安卓
public static Platform android_ios();//安卓和苹果
public static Platform android_winphone();//安卓和winp
public static Platform ios();//苹果
public static Platform ios_winphone();//苹果和winp
public static Platform winphone();//winp
audience:推送目标
public static Audience s_alias(HashSet<string> values);//别名
public static Audience s_alias(params string[] values);
public static Audience s_registrationId(HashSet<string> values);//注册id
public static Audience s_registrationId(params string[] values);
public static Audience s_segment(HashSet<string> values);//用户分群id
public static Audience s_segment(params string[] values);
public static Audience s_tag(HashSet<string> values);//标签
public static Audience s_tag(params string[] values);
public static Audience s_tag_and(HashSet<string> values);//标签,并集
public static Audience s_tag_and(params string[] values);
notification:推送消息
public Notification setAlert(string alert);//所有设备类型公用,推送消息内容
public Notification setAndroid(AndroidNotification android);//针对三个平台更详细的设置
public Notification setIos(IosNotification ios);
public Notification setWinphone(WinphoneNotification winphone);
//ios例子,很多具体的参数
public IosNotification AddExtra(string key, bool value);
public IosNotification AddExtra(string key, int value);
public IosNotification AddExtra(string key, object value);
public IosNotification AddExtra(string key, string value);
public IosNotification autoBadge();
public IosNotification disableBadge();
public IosNotification disableSound();
public IosNotification incrBadge(int badge);
public IosNotification setAlert(object alert);
public IosNotification setBadge(int badge);
public IosNotification setCategory(string category);
public IosNotification setContentAvailable(bool contentAvailable);
public IosNotification setMutableContent(bool mutableContent);
public IosNotification setSound(string sound)
message:自定义消息
public Message AddExtras(string key, bool value);//额外参数
public Message AddExtras(string key, int value);
public Message AddExtras(string key, string value);
public static Message content(string msgContent);//内容,(相当于message的构造方法,static)
public Message setTitle(string title);//标题