init commit all code
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using Getf.Service.Transfer.Client.WinService.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Getf.Service.Transfer.Client.WinService.HttpHandler
|
||||
{
|
||||
public class HttpJsonDataHandler : IDataHandler
|
||||
{
|
||||
public TransInfo HandlerData(TransInfo srcData)
|
||||
{
|
||||
var r = new TransInfo();
|
||||
var action = srcData.Body.Action;
|
||||
if (String.IsNullOrWhiteSpace(action))
|
||||
{
|
||||
r.TransResultInfo = GetResult(-320, "Action(url|method)参数不能为空");
|
||||
return r;
|
||||
}
|
||||
var url = action;
|
||||
HttpService httpService = new HttpService();
|
||||
var jsonStr = String.IsNullOrWhiteSpace(srcData.Body.Param) ? "{}" : srcData.Body.Param;
|
||||
var rData = httpService.DoRequest(url, JsonConvert.DeserializeObject<JObject>(jsonStr), out string msg);
|
||||
if (rData == null)
|
||||
{
|
||||
r.TransResultInfo = new TransResult()
|
||||
{
|
||||
Code = -301,
|
||||
Message = msg
|
||||
};
|
||||
return r;
|
||||
}
|
||||
if (rData is string)
|
||||
{
|
||||
r.TransResultInfo = new TransResult()
|
||||
{
|
||||
Code = 0,
|
||||
Message = (string)rData
|
||||
};
|
||||
return r;
|
||||
}
|
||||
|
||||
r.TransResultInfo = new TransResult()
|
||||
{
|
||||
Code = 0
|
||||
};
|
||||
r.Data = (byte[])rData;
|
||||
return r;
|
||||
}
|
||||
|
||||
private TransResult GetResult(int code, string message)
|
||||
{
|
||||
return new TransResult()
|
||||
{
|
||||
Code = code,
|
||||
Message = message
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user