63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Getf.Service.Transfer.Client.WinService.Entities;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Getf.Service.Transfer.Client.WinService.HttpHandler
|
|
{
|
|
public class HttpDataHandler : 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
|
|
};
|
|
}
|
|
}
|
|
}
|