步步为盈
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.

52 lines
1.9 KiB

3 years ago
using BBWY.Common.Http;
using BBWY.Common.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
namespace BBWY.Client.APIServices
{
public class OneBoundAPIService : IDenpendency
{
private RestApiService restApiService;
private string key = "t5060712539";
private string secret = "20211103";
public OneBoundAPIService(RestApiService restApiService)
{
this.restApiService = restApiService;
}
/// <summary>
/// 产品详细信息接口
/// </summary>
/// <param name="platform">1699/jd/taobao 更多值参阅https://open.onebound.cn/help/api/</param>
/// <param name="key"></param>
/// <param name="secret"></param>
/// <param name="productId"></param>
/// <returns></returns>
public ApiResponse<JObject> GetProductInfo(string platform, string productId)
{
try
{
//https://api-gw.onebound.cn/1688/item_get/key=t5060712539&secret=20211103&num_iid=649560646832&lang=zh-CN&cache=no
3 years ago
var result = restApiService.SendRequest("https://api-gw.onebound.cn/", $"{platform}/item_get", $"key={key}&secret={secret}&num_iid={productId}&lang=zh-CN&cache=no", null, HttpMethod.Get, paramPosition: ParamPosition.Query, enableRandomTimeStamp: true);
3 years ago
if (result.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception($"{result.StatusCode} {result.Content}");
var j = JObject.Parse(result.Content);
return new ApiResponse<JObject>()
{
Data = j,
Code = j.Value<string>("error_code") == "0000" ? 200 : 0,
Msg = j.Value<string>("error")
};
}
catch (Exception ex)
{
return ApiResponse<JObject>.Error(0, ex.Message);
}
}
}
}