这次公司要我们做一个功能,就是当用户成功注册以后,他登录以后要收到消息,当然这个消息是安装了我们的手机APP应用的手机咯。
极光推送的网站的网址是:https://www.jpush.cn/
极光推送的官方API以及帮助文档都在这里:http://docs.jpush.cn/display/dev/Index
其中服务端的接口以及示例代码都在这里:http://docs.jpush.cn/display/dev/Server-SDKs
大家有兴趣的可以看看,因为这次我做的不是客户端APP,所以一笔带过啦,就跟大家介绍一下C#端的吧。
首先我们下载一下极光推送的C#例子吧,如下图。
然后例子里面有详细的介绍,注释什么的。
极光推送的NET.FRAMEWORK的版本号是4.0的,所以如果我们的网站如果是2.0的,那么就要把极光推送的代码集成到WebService里面,然后从要用的时候直接调用这个WebService就行了。
下面是例子的源码:
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\"}}"; //extras中有中文请用HttpUtility.UrlEncode编码