基线 SVN r240

SVN-Revision: r240
This commit is contained in:
cyf
2025-02-06 06:46:06 +00:00
commit ab56a9bcf7
5317 changed files with 902274 additions and 0 deletions
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lskj.Push.Util;
namespace Lskj.Push.Push.Audience
{
public class AudienceTarget
{
public AudienceType audienceType{get;private set;}
public HashSet<string> valueBuilder { get; private set; }
private AudienceTarget(AudienceType audienceType, HashSet<string> values)
{
this.audienceType = audienceType;
this.valueBuilder = values;
}
public static AudienceTarget tag(HashSet<string> values)
{
return new AudienceTarget(AudienceType.tag,values).Check();
}
public static AudienceTarget tag_and(HashSet<string> values)
{
return new AudienceTarget(AudienceType.tag_and, values).Check();
}
public static AudienceTarget alias(HashSet<string> values)
{
return new AudienceTarget(AudienceType.alias, values).Check();
}
public static AudienceTarget segment(HashSet<string> values)
{
return new AudienceTarget(AudienceType.segment, values).Check();
}
public static AudienceTarget registrationId(HashSet<string> values)
{
return new AudienceTarget(AudienceType.registration_id, values).Check();
}
public AudienceTarget Check()
{
Preconditions.checkArgument(null != valueBuilder, "Target values should be set one at least.");
return this;
}
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Audience
{
public enum AudienceType
{
tag,
tag_and,
alias,
segment,
registration_id
}
}
+46
View File
@@ -0,0 +1,46 @@
using Lskj.Push.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace Lskj.Push.Push
{
public class MessageResult : BaseResult
{
public Int64 msg_id{get;set;}
public int sendno{ get; set; }
override public bool isResultOK()
{
if (Equals(ResponseResult.responseCode, HttpStatusCode.OK))
{
return true;
}
return false;
}
public override string ToString()
{
return string.Format("sendno:{0},message_id:{1}", sendno, msg_id);
}
}
//"{\"sendno\":\"0\",\"msg_id\":\"1704649583\"}"
public class JpushSuccess
{
public string sendno;
public string msg_id;
}
public class JpushError
{
public JpushErrorObject error;
public long msg_id;
}
public class JpushErrorObject
{
public int code;
public String message;
}
}
+215
View File
@@ -0,0 +1,215 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lskj.Push.Push.Audience;
using System.Diagnostics;
using Lskj.Push.Util;
namespace Lskj.Push.Push.Mode
{
public class Audience
{
private const String ALL = "all";
public string allAudience;
private void AddWithAudienceTarget(AudienceTarget target)
{
Debug.Assert(target != null && target.valueBuilder != null);
if (target != null && target.valueBuilder != null)
{
this.allAudience = null;
if (dictionary == null)
{
dictionary = new Dictionary<string, HashSet<string>>();
}
if (dictionary.ContainsKey(target.audienceType.ToString()))
{
HashSet<string> origin = dictionary[target.audienceType.ToString()];
foreach (var item in target.valueBuilder)
{
origin.Add(item);
}
}
else
{
dictionary.Add(target.audienceType.ToString(), target.valueBuilder);
}
}
}
public Dictionary<string, HashSet<string>> dictionary;
private Audience()
{
allAudience = ALL;
dictionary = null;
}
public static Audience all()
{
return new Audience() { allAudience = ALL, dictionary = null }.Check();
}
public static Audience s_tag(HashSet<string> values)
{
return new Audience().tag(values);
}
public static Audience s_tag(params string[] values)
{
return new Audience().tag(values);
}
public static Audience s_tag_and(HashSet<string> values)
{
return new Audience().tag_and(values);
}
public static Audience s_tag_and(params string[] values)
{
return new Audience().tag_and(values);
}
public static Audience s_alias(HashSet<string> values)
{
return new Audience().alias(values);
}
public static Audience s_alias(params string[] values)
{
return new Audience().alias(values);
}
public static Audience s_segment(HashSet<string> values)
{
return new Audience().segment(values);
}
public static Audience s_segment(params string[] values)
{
return new Audience().segment(values);
}
public static Audience s_registrationId(HashSet<string> values)
{
return new Audience().registrationId(values);
}
public static Audience s_registrationId(params string[] values)
{
return new Audience().registrationId(values);
}
public Audience tag(HashSet<string> values)
{
if (allAudience != null)
{
allAudience = null;
}
AudienceTarget target = AudienceTarget.tag(values);
AddWithAudienceTarget(target);
return this.Check();
}
public Audience tag(params string[] values)
{
if (allAudience != null)
{
allAudience = null;
}
var valueList = new HashSet<string>(values);
return tag(valueList);
}
public Audience tag_and(HashSet<string> values)
{
if (allAudience != null)
{
allAudience = null;
}
AudienceTarget target = AudienceTarget.tag_and(values);
this.allAudience = null;
if (dictionary == null)
{
dictionary = new Dictionary<string, HashSet<string>>();
}
if (dictionary.ContainsKey(target.audienceType.ToString()))
{
HashSet<string> origin = dictionary[target.audienceType.ToString()];
foreach (var item in values)
{
origin.Add(item);
}
}
else
{
dictionary.Add(target.audienceType.ToString(), values);
}
return this.Check();
}
public Audience tag_and(params string[] values)
{
if (allAudience != null)
{
allAudience = null;
}
HashSet<string> list = new HashSet<string>(values);
return tag_and(list);
}
public Audience alias(HashSet<string> values)
{
if (allAudience != null)
{
allAudience = null;
}
AddWithAudienceTarget( AudienceTarget.alias(values));
return this.Check();
}
public Audience alias(params string[] values)
{
if (allAudience != null)
{
allAudience = null;
}
return alias(new HashSet<string>(values));
}
public Audience segment(HashSet<string> values)
{
if (allAudience != null)
{
allAudience = null;
}
AddWithAudienceTarget(AudienceTarget.segment(values));
return this.Check();
}
public Audience segment(params string[] values)
{
if (allAudience != null)
{
allAudience = null;
}
return segment(new HashSet<string>(values));
}
public Audience registrationId(HashSet<string> values)
{
if (allAudience != null)
{
allAudience = null;
}
AddWithAudienceTarget(AudienceTarget.registrationId(values));
return this.Check();
}
public Audience registrationId(params string[] values)
{
if (allAudience != null)
{
allAudience = null;
}
return registrationId(new HashSet<string>(values));
}
public bool isAll(){
return allAudience != null;
}
public Audience Check()
{
Preconditions.checkArgument(!(isAll() && null != dictionary), "Since all is enabled, any platform should not be set.");
Preconditions.checkArgument(!(!isAll() && null == dictionary), "No any deviceType is set.");
return this;
}
}
}
+101
View File
@@ -0,0 +1,101 @@
using Lskj.Push.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Mode
{
public class Message
{
public String title{get;set;}
public String msg_content { get; set; }
public String content_type { get; set; }
[JsonProperty]
private Dictionary<string, object> extras { get; set; }
private Message()
{
}
private Message(String msgContent)
{
Preconditions.checkArgument(!(msgContent==null), "msgContent should be set");
this.title = null;
this.msg_content = msgContent;
this.content_type = null;
this.extras = null;
}
private Message(String msgContent, String title, String contentType)
{
Preconditions.checkArgument(!(msgContent == null), "msgContent should be set");
this.title = title;
this.msg_content = msgContent;
this.content_type = contentType;
}
public static Message content(string msgContent)
{
return new Message(msgContent).Check();
}
public Message setTitle(String title)
{
this.title = title;
return this;
}
public Message setContentType(String ContentType)
{
this.content_type = ContentType;
return this;
}
public Message AddExtras(string key, string value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
if (value != null)
{
extras.Add(key, value);
}
return this;
}
public Message AddExtras(string key, int value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
public Message AddExtras(string key, bool value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
public Message AddExtras(string key, object value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
public Message Check()
{
Preconditions.checkArgument(!(msg_content==null), "msgContent should be set");
return this;
}
}
}
@@ -0,0 +1,129 @@
using Lskj.Push.Push.Notification;
using Lskj.Push.Util;
using Newtonsoft.Json;
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
namespace Lskj.Push.Push.Mode
{
public class Notification
{
public String alert{get;set;}
[JsonProperty(PropertyName = "ios")]
public IosNotification IosNotification { get; set; }
[JsonProperty(PropertyName = "android")]
public AndroidNotification AndroidNotification { get; set; }
[JsonProperty(PropertyName = "winphone")]
public WinphoneNotification WinphoneNotification { get; set; }
public Notification()
{
this.alert = null;
this.IosNotification = null;
this.AndroidNotification = null;
this.WinphoneNotification = null;
}
public Notification setAlert(string alert)
{
this.alert = alert;
return this;
}
public Notification setAndroid(AndroidNotification android)
{
this.AndroidNotification = android;
return this;
}
public Notification setIos(IosNotification ios)
{
this.IosNotification = ios;
return this;
}
public Notification setWinphone(WinphoneNotification winphone)
{
this.WinphoneNotification = winphone;
return this;
}
public static Notification android(String alert, String title)
{
var platformNotification = new AndroidNotification().setAlert(alert).setTitle(title);
var notificaiton = new Notification().setAlert(alert);
notificaiton.AndroidNotification = platformNotification;
return notificaiton;
}
public static Notification ios(String alert)
{
var iosNotification = new IosNotification().setAlert(alert);
var notification = new Notification().setAlert(alert);
notification.IosNotification = iosNotification;
return notification;
}
public static Notification ios_auto_badge()
{
var platformNotification = new IosNotification();
platformNotification.autoBadge();
var notificaiton = new Notification().setAlert("");;
notificaiton.IosNotification = platformNotification;
return notificaiton;
}
public static Notification ios_set_badge(int badge)
{
var platformNotification = new IosNotification();
platformNotification.setBadge(badge);
var notificaiton = new Notification();
notificaiton.IosNotification = platformNotification;
return notificaiton;
}
public static Notification ios_incr_badge(int badge)
{
var platformNotification = new IosNotification();
platformNotification.incrBadge(badge);
var notificaiton = new Notification();
notificaiton.IosNotification = platformNotification;
return notificaiton;
}
public static Notification winphone(String alert)
{
var platformNotification = new WinphoneNotification().setAlert(alert);
var notificaiton = new Notification().setAlert(alert);
notificaiton.WinphoneNotification = platformNotification;
return notificaiton;
}
public Notification Check()
{
Preconditions.checkArgument(!(isPlatformEmpty() && null == alert), "No notification payload is set.");
if (IosNotification!=null)
{
Preconditions.checkArgument(!(null==IosNotification.alert && null == alert), "No notification payload is set.");
}
if(AndroidNotification!=null)
{
Preconditions.checkArgument(!(null == AndroidNotification.alert && null == alert), "No notification payload is set.");
}
if (WinphoneNotification!=null)
{
Preconditions.checkArgument(!(null == WinphoneNotification.alert && null == alert), "No notification payload is set.");
}
return this;
}
private bool isPlatformEmpty()
{
return (IosNotification == null && AndroidNotification == null && WinphoneNotification == null);
}
}
}
+95
View File
@@ -0,0 +1,95 @@
using Lskj.Push.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Mode
{
public class Options
{
private const long NONE_TIME_TO_LIVE = -1;
public Options()
{
this.sendno = 0;
this.override_msg_id = 0;
this.time_to_live = NONE_TIME_TO_LIVE;
this.big_push_duration = 0;
this.apns_production = false;
}
public Options(int sendno,
long overrideMsgId,
long timeToLive,
int bigPushDuration,
bool apnsProduction=false)
{
this.sendno = sendno;
this.override_msg_id = overrideMsgId;
this.time_to_live = timeToLive;
this.big_push_duration = bigPushDuration;
this.apns_production = apnsProduction;
}
private int _sendno;
[DefaultValue(0)]
public int sendno
{
get
{
return _sendno;
}
set
{
Preconditions.checkArgument(value >= 0, "sendno should be greater than 0.");
_sendno = value;
}
}
private long _override_msg_id;
[DefaultValue(0)]
public long override_msg_id
{
get
{
return _override_msg_id;
}
set
{
Preconditions.checkArgument(value >= 0, "override_msg_id should be greater than 0.");
_override_msg_id = value;
}
}
private long _time_to_live;
[DefaultValue(NONE_TIME_TO_LIVE)]
public long time_to_live
{
get
{
return _time_to_live;
}
set
{
Preconditions.checkArgument(value >= NONE_TIME_TO_LIVE, "time_to_live should be greater than 0.");
_time_to_live = value;
}
}
private long _big_push_duration;
[DefaultValue(0)]
public long big_push_duration
{
get
{
return _big_push_duration;
}
set
{
Preconditions.checkArgument(value >= 0, "big_push_duration should be greater than 0.");
_big_push_duration = value;
}
}
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
public bool apns_production { get; set; }
}
}
+117
View File
@@ -0,0 +1,117 @@
using Lskj.Push.Common;
using Lskj.Push.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Mode
{
public class Platform
{
private const String ALL = "all";
[JsonProperty(PropertyName = "winphone")]
public string allPlatform{get;set;}
private HashSet<string> _deviceTypes;
public HashSet<string> deviceTypes
{
get
{
return _deviceTypes;
}
set
{
if (value != null)
{
allPlatform = null;
}
_deviceTypes = value;
}
}
private Platform()
{
allPlatform = ALL;
deviceTypes = null;
}
private Platform(bool all, HashSet<string> deviceTypes)
{
//用来判断all=true时deviceTypes必须为空,反之当all=false时deviceTypes有值,不然json序列化会出错
Debug.Assert(all && deviceTypes == null || !all && deviceTypes != null);
if (all)
{
allPlatform = ALL;
}
this.deviceTypes = deviceTypes;
}
public static Platform all()
{
return new Platform(true, null).Check();
}
public static Platform ios()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.ios.ToString());
return new Platform(false,types).Check();
}
public static Platform android()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.android.ToString());
return new Platform(false, types).Check();
}
public static Platform winphone()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.winphone.ToString());
return new Platform(false, types).Check();
}
public static Platform android_ios()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.android.ToString());
types.Add(DeviceType.ios.ToString());
return new Platform(false, types).Check();
}
public static Platform android_winphone()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.android.ToString());
types.Add(DeviceType.winphone.ToString());
return new Platform(false, types).Check();
}
public static Platform ios_winphone()
{
HashSet<string> types = new HashSet<string>();
types.Add(DeviceType.ios.ToString());
types.Add(DeviceType.winphone.ToString());
return new Platform(false, types).Check();
}
public bool isAll()
{
return allPlatform != null;
}
public void setAll(bool all)
{
if (all)
{
allPlatform = ALL;
}
else
{
allPlatform = null;
}
}
public Platform Check()
{
Preconditions.checkArgument(!(isAll() && null != deviceTypes), "Since all is enabled, any platform should not be set.");
Preconditions.checkArgument(!(!isAll() && null == deviceTypes), "No any deviceType is set.");
return this;
}
}
}
@@ -0,0 +1,214 @@
using Lskj.Push.Common;
using Lskj.Push.Push.Notification;
using Lskj.Push.Util;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Mode
{
public class PushPayload
{
private JsonSerializerSettings jSetting;
private const String PLATFORM = "platform";
private const String AUDIENCE = "audience";
private const String NOTIFICATION = "notification";
private const String MESSAGE = "message";
private const String OPTIONS = "options";
private const int MAX_GLOBAL_ENTITY_LENGTH = 1200; // Definition acording to JPush Docs
private const int MAX_IOS_PAYLOAD_LENGTH = 220; // Definition acording to JPush Docs
//serializaiton property
[JsonConverter(typeof(PlatformConverter))]
public Platform platform{get;set;}
[JsonConverter(typeof(AudienceConverter))]
public Audience audience{get;set;}
public Notification notification { get; set; }
public Message message { get; set; }
public Options options { get; set; }
//construct
public PushPayload()
{
platform = null;
audience = null;
notification = null;
message = null;
options = new Options();
jSetting = new JsonSerializerSettings();
jSetting.NullValueHandling = NullValueHandling.Ignore;
jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
}
public PushPayload(Platform platform, Audience audience, Notification notification, Message message = null, Options options = null)
{
Debug.Assert(platform != null);
Debug.Assert(audience != null);
Debug.Assert(notification != null || message != null);
this.platform = platform;
this.audience = audience;
this.notification = notification;
this.message = message;
this.options = options;
jSetting = new JsonSerializerSettings();
jSetting.NullValueHandling = NullValueHandling.Ignore;
jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
}
/**
* The shortcut of building a simple alert notification object to all platforms and all audiences
*/
public static PushPayload AlertAll(String alert)
{
return new PushPayload(Platform.all(),
Audience.all(),
new Notification().setAlert(alert),
null,
new Options());
}
//* The shortcut of building a simple message object to all platforms and all audiences
//*/
public static PushPayload MessageAll(String msgContent)
{
return new PushPayload( Platform.all(),
Audience.all(),
null,
Message.content(msgContent),
new Options());
}
public static PushPayload FromJSON(String payloadString)
{
try
{
var jSetting = new JsonSerializerSettings();
jSetting.NullValueHandling = NullValueHandling.Ignore;
jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
var jsonObject = JsonConvert.DeserializeObject<PushPayload>(payloadString, jSetting);
return jsonObject.Check();
}
catch (Exception e)
{
Console.WriteLine("JSON to PushPayLoad occur error:" + e.Message);
return null;
}
}
public void ResetOptionsApnsProduction(bool apnsProduction)
{
if (this.options == null)
{
this.options = new Options();
}
this.options.apns_production = apnsProduction;
}
public void ResetOptionsTimeToLive(long timeToLive)
{
if (this.options == null)
{
this.options = new Options();
}
this.options.time_to_live = timeToLive;
}
public int GetSendno()
{
if (this.options != null)
return this.options.sendno;
return 0;
}
public bool IsGlobalExceedLength()
{
int messageLength = 0;
if (message!= null)
{
var messageJson = JsonConvert.SerializeObject(this.message, jSetting);
messageLength += UTF8Encoding.UTF8.GetBytes(messageJson).Length;
}
if (this.notification == null)
{
return messageLength > MAX_GLOBAL_ENTITY_LENGTH;
}
else
{
var notificationJson = JsonConvert.SerializeObject(this.notification);
if (notificationJson != null)
{
messageLength += UTF8Encoding.UTF8.GetBytes(notificationJson).Length;
}
return messageLength > MAX_GLOBAL_ENTITY_LENGTH;
}
}
public bool IsIosExceedLength()
{
if (this.notification != null)
{
if (this.notification.IosNotification != null)
{
var iosJson = JsonConvert.SerializeObject(this.notification.IosNotification, jSetting);
if (iosJson != null)
{
return UTF8Encoding.UTF8.GetBytes(iosJson).Length > MAX_IOS_PAYLOAD_LENGTH;
}
}
else
{
if (!(this.notification.alert==null))
{
string jsonText;
using (StringWriter sw = new StringWriter())
{
JsonWriter writer = new JsonTextWriter(sw);
writer.WriteValue(this.notification.alert);
writer.Flush();
jsonText = sw.GetStringBuilder().ToString();
}
return UTF8Encoding.UTF8.GetBytes(jsonText).Length > MAX_IOS_PAYLOAD_LENGTH;
}
else
{
// No iOS Payload
}
}
}
return false;
}
public string ToJson()
{
return JsonConvert.SerializeObject(this, jSetting);
}
public PushPayload Check()
{
Preconditions.checkArgument(!(null == audience || null == platform), "audience and platform both should be set.");
Preconditions.checkArgument(!(null == notification && null == message), "notification or message should be set at least one.");
if (audience!=null)
{
audience.Check();
}
if (platform != null)
{
platform.Check();
}
if (message != null)
{
message.Check();
}
if (notification != null)
{
notification.Check();
}
return this;
}
}
}
+14
View File
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lskj.Push.Push.Mode
{
public class PushUserObj
{
public string username { get; set; }
public string password { get; set; }
public string nickname { get; set; }
}
}
@@ -0,0 +1,84 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Notification
{
public class AndroidNotification:PlatformNotification
{
public const String NOTIFICATION_ANDROID = "android";
private const String TITLE = "title";
private const String BUILDER_ID = "builder_id";
[JsonProperty]
public String title{get;private set;}
[JsonProperty]
public int builder_id { get; private set; }
public AndroidNotification():base()
{
this.title = null;
this.builder_id = 0;
}
public AndroidNotification setTitle(string title)
{
this.title = title;
return this;
}
public AndroidNotification setBuilderID(int builder_id)
{
this.builder_id = builder_id;
return this;
}
public AndroidNotification setAlert(String alert)
{
this.alert = alert;
return this;
}
public AndroidNotification AddExtra(string key, string value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
if (value != null)
{
extras.Add(key, value);
}
return this;
}
public AndroidNotification AddExtra(string key, int value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
public AndroidNotification AddExtra(string key, bool value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
public AndroidNotification AddExtra(string key, object value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
}
}
@@ -0,0 +1,166 @@
using Lskj.Push.Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Notification
{
public class IosNotification : PlatformNotification
{
public const String NOTIFICATION_IOS = "ios";
private const String DEFAULT_SOUND = "";
private const String DEFAULT_BADGE = "+1";
private const String BADGE = "badge";
private const String SOUND = "sound";
private const String CONTENT_AVAILABLE = "content-available";
private const String CATEGORY = "category";
private const String ALERT_VALID_BADGE = "Badge number should be 0~99999, "
+ "and badgeDisabled property must be false";
private const String SOUNd_VALID_BADGE = "Sound should not be null or empty, "
+ "and disableSound property must be false";
private bool soundDisabled;
private bool badgeDisabled;
[JsonProperty]
public String sound { get;private set; }
[JsonProperty]
public String badge { get; private set; }
[JsonProperty(PropertyName = "content-available")]
public bool contentAvailable { get; private set; }
[JsonProperty]
public String category { get; private set; }
public IosNotification()
{
base.alert = null;
base.extras = null;
this.soundDisabled = false;
this.badgeDisabled = false;
this.contentAvailable = false;
this.category = null;
this.badge = DEFAULT_BADGE;
this.sound = DEFAULT_SOUND;
}
public IosNotification disableSound()
{
this.soundDisabled = true;
this.sound = null;
return this;
}
public IosNotification disableBadge()
{
this.badgeDisabled = true;
this.badge = null;
return this;
}
public IosNotification setSound(String sound)
{
if ((sound ==null) || soundDisabled)
{
Console.WriteLine(SOUNd_VALID_BADGE);
return this;
}
this.sound = sound;
return this;
}
public IosNotification setBadge(int badge)
{
if (!ServiceHelper.isValidIntBadge(Math.Abs(badge)) || badgeDisabled)
{
Console.WriteLine(ALERT_VALID_BADGE);
return this;
}
this.badge = badge.ToString();
return this;
}
public IosNotification autoBadge()
{
return incrBadge(1);
}
public IosNotification incrBadge(int badge)
{
if (!ServiceHelper.isValidIntBadge(Math.Abs(badge))|| badgeDisabled)
{
Console.WriteLine(ALERT_VALID_BADGE);
return this;
}
if (badge >= 0)
{
this.badge = "+" + badge;
}
else
{
this.badge = "" + badge;
}
return this;
}
public IosNotification setAlert(String alert)
{
this.alert = alert;
return this;
}
public IosNotification setContentAvailable(bool contentAvailable)
{
this.contentAvailable = contentAvailable;
return this;
}
public IosNotification setCategory(String category)
{
this.category = category;
return this;
}
public IosNotification AddExtra(string key, string value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
if (value !=null)
{
extras.Add(key, value);
}
return this;
}
public IosNotification AddExtra(string key, int value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
public IosNotification AddExtra(string key, bool value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
public IosNotification AddExtra(string key, object value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
}
}
@@ -0,0 +1,29 @@
using Lskj.Push.Push.Mode;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Notification
{
public abstract class PlatformNotification
{
public const String ALERT = "alert";
private const String EXTRAS = "extras";
[JsonProperty]
public String alert{get;protected set;}
[JsonProperty]
public Dictionary<String, object> extras { get; protected set; }
public PlatformNotification()
{
this.alert = null;
this.extras = null;
}
}
}
@@ -0,0 +1,71 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push.Notification
{
public class WinphoneNotification : PlatformNotification
{
[JsonProperty]
private String title;
[JsonProperty(PropertyName = "_open_page")]
public String openPage;
public WinphoneNotification():base()
{
this.title = null;
this.openPage = null;
}
public WinphoneNotification setAlert(String alert)
{
this.alert = alert;
return this;
}
public WinphoneNotification setOpenPage(String openPage)
{
this.openPage = openPage;
return this;
}
public WinphoneNotification setTitle(String title)
{
this.title = title;
return this;
}
public WinphoneNotification AddExtra(string key, string value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
if (value!=null)
{
extras.Add(key, value);
}
return this;
}
public WinphoneNotification AddExtra(string key, int value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
public WinphoneNotification AddExtra(string key, bool value)
{
if (extras == null)
{
extras = new Dictionary<string, object>();
}
extras.Add(key, value);
return this;
}
}
}
+65
View File
@@ -0,0 +1,65 @@
using Lskj.Push.Common;
using Lskj.Push.Push.Mode;
using Lskj.Push.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.Push.Push
{
internal class PushClient:BaseHttpClient
{
private const String HOST_NAME_SSL = "https://api.jpush.cn";
private const String PUSH_PATH = "/v3/push";
private String appKey;
private String masterSecret;
public PushClient(String appKey,String masterSecret)
{
this.appKey = appKey;
this.masterSecret = masterSecret;
}
public MessageResult sendPush(PushPayload payload)
{
Preconditions.checkArgument(payload != null, "pushPayload should not be empty");
payload.Check();
String payloadJson = payload.ToJson();
return sendPush(payloadJson);
}
public MessageResult sendPush(string payloadString)
{
Preconditions.checkArgument(!string.IsNullOrEmpty(payloadString), "payloadString should not be empty");
String url = HOST_NAME_SSL;
url += PUSH_PATH;
ResponseWrapper result = sendPost(url, Authorization(), payloadString);
MessageResult messResult = new MessageResult();
messResult.ResponseResult = result;
JpushSuccess jpushSuccess = JsonConvert.DeserializeObject<JpushSuccess>(result.responseContent);
messResult.sendno = int.Parse(jpushSuccess.sendno);
//messResult.msg_id = int.Parse(jpushSuccess.msg_id);
messResult.msg_id = Convert.ToInt64(jpushSuccess.msg_id);
return messResult;
}
private String Authorization(){
Debug.Assert(!string.IsNullOrEmpty(this.appKey));
Debug.Assert(!string.IsNullOrEmpty(this.masterSecret));
String origin=this.appKey+":"+this.masterSecret;
return Base64.getBase64Encode(origin);
}
}
enum MsgTypeEnum
{
NOTIFICATIFY = 1,
COUSTOM_MESSAGE =2
}
}