16 changed files with 432 additions and 106 deletions
@ -0,0 +1,58 @@ |
|||||
|
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 }; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
using BBWY.Common.Http; |
||||
|
using QuanTan.SDK.Model.Response; |
||||
|
using QuanTan.SDK.Model.Response.Product; |
||||
|
namespace QuanTan.SDK.Client |
||||
|
{ |
||||
|
public class QuanTanProductClient : BaseClient |
||||
|
{ |
||||
|
public QuanTanProductClient(RestApiService restApiService) : base(restApiService) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public QuanTanResponse<QuanTanProductResponse> GetProductInfo(string productId, string appId, string appSecret) |
||||
|
{ |
||||
|
return SendRequest<QuanTanProductResponse>($"api/platform/product/spu/{productId}", null, appId, appSecret); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,85 @@ |
|||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Security.Cryptography; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace QuanTan.SDK.Extensions |
||||
|
{ |
||||
|
public static class EncryptionExtension |
||||
|
{ |
||||
|
|
||||
|
public static string Md5Encrypt(this string originStr) |
||||
|
{ |
||||
|
using (var md5 = MD5.Create()) |
||||
|
{ |
||||
|
return string.Join(string.Empty, md5.ComputeHash(Encoding.UTF8.GetBytes(originStr)).Select(x => x.ToString("x2"))); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//AES加密 传入,要加密的串和, 解密key
|
||||
|
public static string AESEncrypt(this string input) |
||||
|
{ |
||||
|
var key = "dataplatform2019"; |
||||
|
var ivStr = "1012132405963708"; |
||||
|
|
||||
|
var encryptKey = Encoding.UTF8.GetBytes(key); |
||||
|
var iv = Encoding.UTF8.GetBytes(ivStr); //偏移量,最小为16
|
||||
|
using (var aesAlg = Aes.Create()) |
||||
|
{ |
||||
|
using (var encryptor = aesAlg.CreateEncryptor(encryptKey, iv)) |
||||
|
{ |
||||
|
using (var msEncrypt = new MemoryStream()) |
||||
|
{ |
||||
|
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, |
||||
|
CryptoStreamMode.Write)) |
||||
|
|
||||
|
using (var swEncrypt = new StreamWriter(csEncrypt)) |
||||
|
{ |
||||
|
swEncrypt.Write(input); |
||||
|
} |
||||
|
var decryptedContent = msEncrypt.ToArray(); |
||||
|
|
||||
|
return Convert.ToBase64String(decryptedContent); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static string AESDecrypt(this string cipherText) |
||||
|
{ |
||||
|
var fullCipher = Convert.FromBase64String(cipherText); |
||||
|
|
||||
|
var ivStr = "1012132405963708"; |
||||
|
var key = "dataplatform2019"; |
||||
|
|
||||
|
var iv = Encoding.UTF8.GetBytes(ivStr); |
||||
|
var decryptKey = Encoding.UTF8.GetBytes(key); |
||||
|
|
||||
|
using (var aesAlg = Aes.Create()) |
||||
|
{ |
||||
|
using (var decryptor = aesAlg.CreateDecryptor(decryptKey, iv)) |
||||
|
{ |
||||
|
string result; |
||||
|
using (var msDecrypt = new MemoryStream(fullCipher)) |
||||
|
{ |
||||
|
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) |
||||
|
{ |
||||
|
using (var srDecrypt = new StreamReader(csDecrypt)) |
||||
|
{ |
||||
|
result = srDecrypt.ReadToEnd(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static string Base64Encrypt(this string originStr) |
||||
|
{ |
||||
|
return Convert.ToBase64String(Encoding.UTF8.GetBytes(originStr)); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
using Newtonsoft.Json; |
||||
|
|
||||
|
namespace QuanTan.SDK.Model.Request |
||||
|
{ |
||||
|
public class QuanTanSignParam |
||||
|
{ |
||||
|
public string appId { get; set; } |
||||
|
public string appSecret { get; set; } |
||||
|
|
||||
|
public string callTime { get; set; } |
||||
|
|
||||
|
[JsonProperty(PropertyName = "params")] |
||||
|
public object _params { get; set; } |
||||
|
|
||||
|
public string randomNum { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class QuanTanRequestParam |
||||
|
{ |
||||
|
[JsonProperty(PropertyName = "params")] |
||||
|
public object Params { get; set; } |
||||
|
|
||||
|
public string token { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
using QuanTan.SDK.Model.Vender; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace QuanTan.SDK.Model.Response.Product |
||||
|
{ |
||||
|
public class QuanTanProductResponse |
||||
|
{ |
||||
|
public Supplier Supplier { get; set; } |
||||
|
|
||||
|
public QuanTanProduct Product { get; set; } |
||||
|
|
||||
|
public IList<QuanTanProductSku> ProductSku { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class QuanTanProduct |
||||
|
{ |
||||
|
public string ProductId { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 商品名称(完整标题)
|
||||
|
/// </summary>
|
||||
|
public string ProductName { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 商品简介
|
||||
|
/// </summary>
|
||||
|
public string ProductBrief { get; set; } |
||||
|
public decimal Price { get; set; } |
||||
|
public string UnitName { get; set; } |
||||
|
public string Image { get; set; } |
||||
|
//public string Sliderimage { get; set; }
|
||||
|
public string VideoLink { get; set; } |
||||
|
public string Stock { get; set; } |
||||
|
public string Context { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class QuanTanProductSku |
||||
|
{ |
||||
|
public string SkuId { get; set; } |
||||
|
public string ProductId { get; set; } |
||||
|
public string Title { get; set; } |
||||
|
public string Logo { get; set; } |
||||
|
public decimal Price { get; set; } |
||||
|
//public decimal RetailPrice { get; set; }
|
||||
|
public int Stock { get; set; } |
||||
|
//public decimal Volume { get; set; }
|
||||
|
//public string weight { get; set; }
|
||||
|
public string BarCode { get; set; } |
||||
|
//public string skuArr { get; set; }
|
||||
|
} |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
namespace QuanTan.SDK.Model.Response |
||||
|
{ |
||||
|
public class QuanTanResponse |
||||
|
{ |
||||
|
public int Status { get; set; } |
||||
|
|
||||
|
public string Message { get; set; } |
||||
|
|
||||
|
public object Data { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class QuanTanResponse<T> : QuanTanResponse |
||||
|
{ |
||||
|
public new T Data { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
namespace QuanTan.SDK.Model.Vender |
||||
|
{ |
||||
|
public class Supplier |
||||
|
{ |
||||
|
public string Location { get; set; } |
||||
|
|
||||
|
public string VenderId { get; set; } |
||||
|
|
||||
|
public string VerdenName { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.1</TargetFramework> |
||||
|
<Nullable>enable</Nullable> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\BBWY.Common\BBWY.Common.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
Loading…
Reference in new issue