基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using Lskj.Push.Common;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lskj.Push.Report
|
||||
{
|
||||
public class MessagesResult : BaseResult
|
||||
{
|
||||
public List<Message> messages = new List<Message>();
|
||||
public static MessagesResult fromResponse(ResponseWrapper responseWrapper)
|
||||
{
|
||||
MessagesResult receivedsResult = new MessagesResult();
|
||||
if (responseWrapper.responseCode==HttpStatusCode.OK)
|
||||
{
|
||||
receivedsResult.messages = JsonConvert.DeserializeObject<List<Message>>(responseWrapper.responseContent);
|
||||
}
|
||||
receivedsResult.ResponseResult = responseWrapper;
|
||||
return receivedsResult;
|
||||
}
|
||||
public override bool isResultOK()
|
||||
{
|
||||
if (Equals(ResponseResult.responseCode, HttpStatusCode.OK))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public class Message
|
||||
{
|
||||
public Message()
|
||||
{
|
||||
msg_id = 0;
|
||||
android = null;
|
||||
ios = null;
|
||||
}
|
||||
public long msg_id;
|
||||
public Android android;
|
||||
public Ios ios;
|
||||
}
|
||||
public class Android
|
||||
{
|
||||
|
||||
public Android()
|
||||
{
|
||||
received = 0;
|
||||
target = 0;
|
||||
online_push = 0;
|
||||
click = 0;
|
||||
}
|
||||
public int received;
|
||||
public int target;
|
||||
public int online_push;
|
||||
public int click;
|
||||
}
|
||||
public class Ios
|
||||
{
|
||||
public Ios()
|
||||
{
|
||||
apns_sent = 0;
|
||||
apns_target = 0;
|
||||
click = 0;
|
||||
}
|
||||
public int apns_sent;
|
||||
public int apns_target;
|
||||
public int click;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Lskj.Push.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lskj.Push.Report
|
||||
{
|
||||
public class ReceivedResult : BaseResult
|
||||
{
|
||||
|
||||
private List<Received> receivedList = new List<Received>();
|
||||
|
||||
public List<Received> ReceivedList
|
||||
{
|
||||
get { return receivedList; }
|
||||
set { receivedList = value; }
|
||||
}
|
||||
|
||||
public class Received {
|
||||
public long msg_id;
|
||||
public String android_received;
|
||||
public String ios_apns_sent;
|
||||
}
|
||||
|
||||
public override bool isResultOK()
|
||||
{
|
||||
if (Equals(ResponseResult.responseCode, HttpStatusCode.OK))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public HttpStatusCode getErrorCode()
|
||||
{
|
||||
if (null != ResponseResult)
|
||||
{
|
||||
return ResponseResult.responseCode;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public string getErrorMessage()
|
||||
{
|
||||
if (null != ResponseResult)
|
||||
{
|
||||
return ResponseResult.exceptionString;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
using Lskj.Push.Common;
|
||||
using Lskj.Push.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lskj.Push.Report
|
||||
{
|
||||
class ReportClient:BaseHttpClient
|
||||
{
|
||||
private const String REPORT_HOST_NAME = "https://report.jpush.cn";
|
||||
private const String REPORT_RECEIVE_PATH = "/v2/received";
|
||||
private const String REPORT_RECEIVE_PATH_V3 = "/v3/received";
|
||||
private const String REPORT_USER_PATH = "/v3/users";
|
||||
|
||||
private String appKey;
|
||||
private String masterSecret;
|
||||
public ReportClient(String appKey, String masterSecret)
|
||||
{
|
||||
this.appKey = appKey;
|
||||
this.masterSecret = masterSecret;
|
||||
}
|
||||
public ReceivedResult getReceiveds(String msg_ids)
|
||||
{
|
||||
checkMsgids(msg_ids);
|
||||
return getReceiveds_common(msg_ids, REPORT_RECEIVE_PATH);
|
||||
}
|
||||
public ReceivedResult getReceiveds_v3(String msg_ids)
|
||||
{
|
||||
checkMsgids(msg_ids);
|
||||
return getReceiveds_common(msg_ids, REPORT_RECEIVE_PATH_V3);
|
||||
}
|
||||
public UsersResult getUsers(TimeUnit timeUnit, String start, int duration)
|
||||
{
|
||||
String url = REPORT_HOST_NAME + REPORT_USER_PATH
|
||||
+ "?time_unit=" + timeUnit.ToString()
|
||||
+ "&start=" + start + "&duration=" + duration;
|
||||
String auth = Base64.getBase64Encode(this.appKey + ":" + this.masterSecret);
|
||||
ResponseWrapper response = this.sendGet(url, auth, null);
|
||||
|
||||
return UsersResult.fromResponse(response);
|
||||
}
|
||||
public MessagesResult getReportMessages(params String[] msgIds)
|
||||
{
|
||||
return getReportMessages(StringUtil.arrayToString(msgIds));
|
||||
}
|
||||
public String checkMsgids(String msgIds)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(msgIds)) {
|
||||
throw new ArgumentException("msgIds param is required.");
|
||||
}
|
||||
Regex reg = new Regex(@"[^0-9, ]");
|
||||
if(reg.IsMatch(msgIds))
|
||||
{
|
||||
throw new ArgumentException("msgIds param format is incorrect. "
|
||||
+ "It should be msg_id (number) which response from JPush Push API. "
|
||||
+ "If there are many, use ',' as interval. ");
|
||||
}
|
||||
msgIds = msgIds.Trim();
|
||||
if (msgIds.EndsWith(",")) {
|
||||
msgIds = msgIds.Substring(0, msgIds.Length - 1);
|
||||
}
|
||||
String[] splits = msgIds.Split(',');
|
||||
List<string> list = new List<string>();
|
||||
try {
|
||||
foreach (String s in splits) {
|
||||
string trim = s.Trim();
|
||||
if (!string.IsNullOrEmpty(trim))
|
||||
{
|
||||
int.Parse(trim);
|
||||
list.Add(trim);
|
||||
}
|
||||
}
|
||||
return StringUtil.arrayToString(list.ToArray());
|
||||
} catch (Exception) {
|
||||
throw new Exception("Every msg_id should be valid Integer number which splits by ','");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ReceivedResult getReceiveds_common(String msg_ids, string path)
|
||||
{
|
||||
String url = REPORT_HOST_NAME + path + "?msg_ids=" + msg_ids;
|
||||
String auth = Base64.getBase64Encode(this.appKey + ":" + this.masterSecret);
|
||||
ResponseWrapper rsp = this.sendGet(url, auth, null);
|
||||
ReceivedResult result = new ReceivedResult();
|
||||
List<ReceivedResult.Received> list = new List<ReceivedResult.Received>();
|
||||
|
||||
Console.WriteLine("recieve content==" + rsp.responseContent);
|
||||
if (rsp.responseCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
list = (List<ReceivedResult.Received>)JsonTool.JsonToObject(rsp.responseContent, list);
|
||||
String content = rsp.responseContent;
|
||||
}
|
||||
result.ResponseResult = rsp;
|
||||
result.ReceivedList = list;
|
||||
return result;
|
||||
}
|
||||
private MessagesResult getReportMessages(String msgIds)
|
||||
{
|
||||
String checkMsgId = checkMsgids(msgIds);
|
||||
String url = REPORT_HOST_NAME + REPORT_RECEIVE_PATH + "?msg_ids=" + checkMsgId;
|
||||
String auth = Base64.getBase64Encode(this.appKey + ":" + this.masterSecret);
|
||||
ResponseWrapper response = this.sendGet(url, auth, null);
|
||||
|
||||
return MessagesResult.fromResponse(response);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using Lskj.Push.Common;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lskj.Push.Report
|
||||
{
|
||||
public class UsersResult : BaseResult
|
||||
{
|
||||
public TimeUnit time_unit;
|
||||
public String start;
|
||||
public int duration;
|
||||
public UsersResult()
|
||||
{
|
||||
time_unit = TimeUnit.DAY;
|
||||
start = null;
|
||||
duration = 0;
|
||||
}
|
||||
public List<User> items = new List<User>();
|
||||
|
||||
public static UsersResult fromResponse(ResponseWrapper responseWrapper)
|
||||
{
|
||||
UsersResult usersResult = new UsersResult();
|
||||
if (responseWrapper.isServerResponse()) {
|
||||
usersResult = JsonConvert.DeserializeObject<UsersResult> (responseWrapper.responseContent);
|
||||
}
|
||||
usersResult.ResponseResult=responseWrapper;
|
||||
return usersResult;
|
||||
}
|
||||
public override bool isResultOK()
|
||||
{
|
||||
if (Equals(ResponseResult.responseCode, HttpStatusCode.OK))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public class User
|
||||
{
|
||||
|
||||
public String time;
|
||||
public Android android;
|
||||
public Ios ios;
|
||||
public User()
|
||||
{
|
||||
time = null;
|
||||
android = null;
|
||||
ios = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Android
|
||||
{
|
||||
|
||||
[JsonProperty(PropertyName = "new")]
|
||||
public long add;
|
||||
public int online;
|
||||
public int active;
|
||||
public Android()
|
||||
{
|
||||
add = 0;
|
||||
online = 0;
|
||||
active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class Ios
|
||||
{
|
||||
[JsonProperty(PropertyName = "new")]
|
||||
public long add;
|
||||
public int online;
|
||||
public int active;
|
||||
public Ios()
|
||||
{
|
||||
add = 0;
|
||||
online = 0;
|
||||
active = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user