public void SerializeSingleEZRequest() { var ezRequestCount = new EZRequest("ApiKey", new EZStat("TestStat", 1)); var ezRequestValue = new EZRequest("ApiKey", new EZStat("TestStat", value: 1)); Assert.Equal("{ \"ezkey\": \"ApiKey\", \"data\": [{ \"stat\": \"TestStat\", \"count\": 1 }]}", ezRequestCount.ToString()); Assert.Equal("{ \"ezkey\": \"ApiKey\", \"data\": [{ \"stat\": \"TestStat\", \"value\": 1 }]}", ezRequestValue.ToString()); }
public void SerializeMultipleEZStatsAsRequest() { var statList = new List <EZStat>() { new EZStat("TestStat", 1), new EZStat("TestStat", value: 1) }; var ezRequest = new EZRequest("APIKey", statList); Assert.Equal("{ \"ezkey\": \"APIKey\", \"data\": [{ \"stat\": \"TestStat\", \"count\": 1 },{ \"stat\": \"TestStat\", \"value\": 1 }]}", ezRequest.ToString()); }
public static void EZSetRequest(EZRequest request) { StringBuilder signStr = new StringBuilder(); string eZAppSecret = (string)EZJsonObject["EZAppSecret"]; foreach (var item in request._params) { signStr.Append(item.Key + ":" + item.Value + ","); } signStr.Append("method:" + request.method + ","); signStr.Append("time:" + request._system.time + ","); signStr.Append("secret:" + eZAppSecret); //string test = "accessToken:f88c4dbb354711c9bf6597a4987dce90,deviceId:123456789,phone:18899998888,userId:ghhc4dbb354711c9bf6597a4987dce90,method:getDevice,time:1404443389,secret:yuc4dbb354sdsdfj77d76lkd86"; //string s1= MyUtils.MD5ForPHP(test); string ss = signStr.ToString(); request._system.sign = MD5ForPHP(ss); }
private async Task <EZResponse <EZAccessToken> > EZCheck(string phoneNumber) { using (var client = new HttpClient()) { //client.BaseAddress = new Uri(MyAPPs.EZBaseURL); EZRequest request = new EZRequest { id = "123456", _system = new EZSystem { ver = Helper.EZCLOUDVERSION, key = Helper.EZAPPKEY, time = Helper.GetUnixTimeStamp() }, method = Helper.EZGETTOKENMETHOD }; request._params.Add("phone", phoneNumber); Helper.EZSetRequest(request); string ss = JsonConvert.SerializeObject(request); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.PostAsJsonAsync(Helper.EZBASEURL, request); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsAsync <EZResponse <EZAccessToken> >()); } return(null); } }
public void SerializeEnumerable() { var a = new EZRequest("a", Stats().ToArray()); Assert.Equal("" "{" ezkey ":" a "," data ":[{" stat ":" counter "," count ":1},{" stat ":" counter "," count ":2}]}" "", a.ToString()); }
public void SerializeMultipleEZTests() { var a = new EZRequest("a", new[] { new EZStat("counter", 0, 1), new EZStat("counter", 0, 2) }); Assert.Equal("" "{" ezkey ":" a "," data ":[{" stat ":" counter "," value ":1},{" stat ":" counter "," value ":2}]}" "", a.ToString()); }