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

73 lines
2.7 KiB

3 years ago
using BBWY.Common.Models;
using BBWY.JDSDK.Request;
using BBWY.Server.Model.Db;
3 years ago
using BBWY.Server.Model.Dto;
3 years ago
using Jd.Api;
3 years ago
using Jd.Api.Request;
3 years ago
using Jd.Api.Response;
3 years ago
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using io = System.IO;
namespace BBWY.Test
{
internal class Program
{
3 years ago
private static IJdClient GetJdClient(string appKey, string appSecret)
{
return new DefaultJdClient("https://api.jd.com/routerjson", appKey, appSecret);
}
static void Main(string[] args)
{
3 years ago
var appKey = "120EA9EC65AB017567D78CC1139EEEA5";
var appSecret = "866a9877f5f24b03b537483b4defe75d";
3 years ago
var token = "2ace3023200c4ea9aa682bbf8bffee18jztm";
3 years ago
var jdClient = GetJdClient(appKey, appSecret);
3 years ago
SearchProductSkuRequest searchProductRequest = new SearchProductSkuRequest()
{
AppKey = appKey,
AppSecret = appSecret,
AppToken = token,
Platform = Server.Model.Enums.Platform.,
Spu = "10022849663452"
};
3 years ago
3 years ago
3 years ago
//var jdClient = GetJdClient(searchProductRequest.AppKey, searchProductRequest.AppSecret);
var req_skuList = new SkuReadSearchSkuListRequest()
{
pageSize = 50,//50
field = "logo,saleAttrs,status"
};
3 years ago
3 years ago
if (!string.IsNullOrEmpty(searchProductRequest.Spu))
req_skuList.wareId = searchProductRequest.Spu;
else if (!string.IsNullOrEmpty(searchProductRequest.Sku))
req_skuList.skuId = searchProductRequest.Sku;
3 years ago
3 years ago
var rep_skuList = jdClient.Execute(req_skuList, searchProductRequest.AppToken, DateTime.Now.ToLocalTime());
if (rep_skuList.IsError)
throw new BusinessException(string.IsNullOrEmpty(rep_skuList.ErrorMsg) ? rep_skuList.ErrMsg : rep_skuList.ErrorMsg);
var response = ((JArray)rep_skuList.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"]).Select(s => new ProductSkuResponse()
{
Id = s.Value<string>("skuId"),
ProductId = s.Value<string>("wareId"),
Price = s.Value<decimal>("jdPrice"),
Title = string.Join("-", s["saleAttrs"].Select(a => a["attrValueAlias"][0].ToString())),
Logo = $"https://img13.360buyimg.com/n9/s80x80_{s.Value<string>("logo")}",
State = s.Value<int>("status")
}).ToList();
3 years ago
Console.WriteLine(JsonConvert.SerializeObject(response));
Console.ReadKey();
}
}
}