using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using Codeplex.Data;
namespace LYFZ.Weixin.SDK.Merchant
{
///
/// 库存管理接口
///
public class StockAPI
{
///
/// 增加库存
///
///
/// 商品ID
/// sku信息,格式"id1:vid1;id2:vid2",如商品为统一规格,则此处赋值为空字符串即可
/// 增加的库存数量
///
/// {
/// "errcode":0,
/// "errmsg":"success"
/// }
///
public static dynamic Add(string access_token, string product_id, string sku_info, int quantity)
{
var client = new HttpClient();
var content = new StringBuilder();
content.Append("{")
.Append('"' + "product_id" + '"' + ": " + '"' + product_id + '"').Append(",")
.Append('"' + "sku_info" + '"' + ": " + '"' + product_id + '"').Append(",")
.Append('"' + "quantity" + '"' + ": " + quantity).Append(",")
.Append("}");
var result = client.PostAsync(string.Format("https://api.weixin.qq.com/merchant/stock/add?access_token={0}", access_token),
new StringContent(content.ToString())).Result;
return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
}
///
/// 减少库存
///
///
/// 商品ID
/// sku信息,格式"id1:vid1;id2:vid2"
/// 减少的库存数量
///
/// {
/// "errcode":0,
/// "errmsg":"success"
/// }
///
public static dynamic Reduce(string access_token, string product_id, string sku_info, int quantity)
{
var client = new HttpClient();
var content = new StringBuilder();
content.Append("{")
.Append('"' + "product_id" + '"' + ": " + '"' + product_id + '"').Append(",")
.Append('"' + "sku_info" + '"' + ": " + '"' + product_id + '"').Append(",")
.Append('"' + "quantity" + '"' + ": " + quantity).Append(",")
.Append("}");
var result = client.PostAsync(string.Format("https://api.weixin.qq.com/merchant/stock/reduce?access_token={0}", access_token),
new StringContent(content.ToString())).Result;
return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
}
}
}