You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.0 KiB
58 lines
2.0 KiB
using BBWY.Common.Http;
|
|
using Newtonsoft.Json;
|
|
using QuanTan.SDK.Extensions;
|
|
using QuanTan.SDK.Model.Request;
|
|
using QuanTan.SDK.Model.Response;
|
|
using System;
|
|
using System.Net.Http;
|
|
|
|
namespace QuanTan.SDK.Client
|
|
{
|
|
public class BaseClient
|
|
{
|
|
protected RestApiService restApiService;
|
|
|
|
protected readonly string host = "https://qt.qiyue666.com/";
|
|
|
|
public BaseClient(RestApiService restApiService)
|
|
{
|
|
this.restApiService = restApiService;
|
|
}
|
|
|
|
public QuanTanResponse<T> SendRequest<T>(string apiPath, object param, string appId, string appSecret)
|
|
{
|
|
var callTime = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
var randomNum = new Random(Guid.NewGuid().GetHashCode()).Next(100000, 999999).ToString();
|
|
if (param == null)
|
|
param = new object[] { };
|
|
|
|
var jmStr = JsonConvert.SerializeObject(new QuanTanSignParam()
|
|
{
|
|
appId = appId,
|
|
appSecret = appSecret,
|
|
callTime = callTime,
|
|
_params = JsonConvert.SerializeObject(param),
|
|
randomNum = randomNum
|
|
});
|
|
var md5Str = jmStr.Md5Encrypt();
|
|
var qtToken = $"{appId}-{callTime}-{md5Str}-{randomNum}";
|
|
var requestParam = new QuanTanRequestParam()
|
|
{
|
|
Params = param,
|
|
token = qtToken
|
|
};
|
|
|
|
try
|
|
{
|
|
var restApiResult = restApiService.SendRequest(host, apiPath, requestParam, null, HttpMethod.Post);
|
|
if (restApiResult.StatusCode != System.Net.HttpStatusCode.OK)
|
|
throw new Exception(restApiResult.Content);
|
|
return JsonConvert.DeserializeObject<QuanTanResponse<T>>(restApiResult.Content);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new QuanTanResponse<T>() { Status = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|