在“京东价格监控软件开发技术探讨一:C#实现获取京东商品信息(价格、库存)”中,对如何获取商品价格进行了简单的阐述。
根据博主近期的研究,对京东价格体系有了更多的理解,在这里进行一个比较系统的描述。
//通过接口获取所有平台价格
//电脑
string pcPrice = string.Format("https://p.3.cn/prices/mgets?type=1&skuIds=J_{0}", pid);
string pcPrice1 = HttpHelper.GetResponse(pcPrice, "get", string.Empty).Replace("[","").Replace("]\n","");
JdWarePrice pcPrices = JsonConvert.DeserializeObject<JdWarePrice>(pcPrice1);
//手机端
string appPrice = string.Format("https://pm.3.cn/prices/mgets?origin=2&skuids={0}", pid);
string appPrice1 = HttpHelper.GetResponse(appPrice, "get", string.Empty).Replace("[", "").Replace("]\n", "");
JdWarePrice appPrices = JsonConvert.DeserializeObject<JdWarePrice>(appPrice1);
//QQ
string qqPrice = string.Format("https://pe.3.cn/prices/mgets?origin=4&skuids={0}", pid);
string qqPrice1 = HttpHelper.GetResponse(qqPrice, "get", string.Empty).Replace("[", "").Replace("]\n", "");
JdWarePrice qqPrices = JsonConvert.DeserializeObject<JdWarePrice>(qqPrice1);
//微信
string wxPrice = string.Format("https://pe.3.cn/prices/mgets?origin=5&skuids={0}", pid);
string wxPrice1 = HttpHelper.GetResponse(wxPrice, "get", string.Empty).Replace("[", "").Replace("]\n", "");
JdWarePrice wxPrices = JsonConvert.DeserializeObject<JdWarePrice>(wxPrice1);
商品价格的格式定义如下:
/// <summary>
/// 商品价格
/// </summary>
public class JdWarePrice
{
//cnp([{"id":"J_1010527324","p":"129.00","m":"350.00"}]);
//jQuery5068505([{"id":"202459","pcp":"69.00","p":"59.00","m":"121.00"}]);
/// <summary>
/// 商品编号
/// </summary>
public string id { get; set; }
/// <summary>
/// 网站销售价格/手机专享价/折扣价
/// </summary>
public string p { get; set; }
/// <summary>
/// 原始价格
/// </summary>
public string m { get; set; }
}