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;
}
///
/// 产品详细信息接口
///
/// 1699/jd/taobao 更多值参阅https://open.onebound.cn/help/api/
///
///
///
///
public ApiResponse 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
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);
if (result.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception($"{result.StatusCode} {result.Content}");
var j = JObject.Parse(result.Content);
return new ApiResponse()
{
Data = j,
Code = j.Value("error_code") == "0000" ? 200 : 0,
Msg = j.Value("error")
};
}
catch (Exception ex)
{
return ApiResponse.Error(0, ex.Message);
}
}
}
}