/// <summary> /// 设置订单发货信息 /// </summary> /// <param name="order_id">订单Id</param> /// <param name="delivery_company">物流公司</param> /// <param name="delivery_track_no">运单ID</param> /// <param name="need_delivery">商品是否需要物流(0-不需要,1-需要,无该字段默认为需要物流)</param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode SetOrderDelivery(string order_id, string delivery_company, string delivery_track_no, short need_delivery, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/order/setdelivery?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; object data = null; if (need_delivery == 1) { data = new { need_delivery = need_delivery }; } else { data = new { order_id = order_id, delivery_company = delivery_company, delivery_track_no = delivery_track_no, need_delivery = need_delivery }; } var json = Util.HttpPost2(url, Util.ToJson(data)); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 获取颜色列表 /// </summary> /// <param name="offset">查询卡列表的起始偏移量,从0 开始</param> /// <param name="count">需要查询的卡片的数量(数量最大50)</param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static GetColorsListResult GetColorsList(string appId, string appSecret) { var url = "https://api.weixin.qq.com/card/getcolors?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpGet2(url); return(Util.JsonTo <GetColorsListResult>(json)); }
/// <summary> /// 创建卡券 /// </summary> /// <param name="cardjson"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static AddCardResult AddCard(string cardjson, string appId, string appSecret) { var url = "https://api.weixin.qq.com/card/create?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, cardjson); return(Util.JsonTo <AddCardResult>(json)); }
/// <summary> /// 减少库存 /// </summary> /// <param name="product_id">商品id</param> /// <param name="sku_info">sku信息,格式"id1:vid1;id2:vid2", /// 如商品为统一规格,则此处赋值为空字符串即可</param> /// <param name="quantity">减少库存的数量</param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode ReduceStock(string product_id, string sku_info, int quantity, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/stock/reduce?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { product_id = product_id, sku_info = sku_info, quantity = quantity })); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 获取卡券列表 /// </summary> /// <param name="offset">查询卡列表的起始偏移量,从0 开始</param> /// <param name="count">需要查询的卡片的数量(数量最大50)</param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static GetCardListResult GetCardList(int offset, int count, string appId, string appSecret) { var url = "https://api.weixin.qq.com/card/batchget?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { offset = offset, count = count })); return(Util.JsonTo <GetCardListResult>(json)); }
/// <summary> /// 根据货架id获取货架信息 /// </summary> /// <param name="shelf_id"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static GetShelfResult GetShelf(int shelf_id, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/shelf/getbyid?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { shelf_id = shelf_id })); return(Util.JsonTo <GetShelfResult>(json)); }
/// <summary> /// 货架上下架 /// </summary> /// <param name="shelf_id"></param> /// <param name="status">0下架,1上架</param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static SetShelfStatusResult SetShelfStatus(int shelf_id, byte status, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/shelf/updatestatus?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { shelf_id = shelf_id, status = status })); return(Util.JsonTo <SetShelfStatusResult>(json)); }
/// <summary> /// status:0全部,1上架,2下架 /// </summary> /// <param name="status"></param> public static GetProductListResult GetProductListByStatus(byte status, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/getbystatus?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { status = status })); return(Util.JsonTo <GetProductListResult>(json)); }
/// <summary> /// 商品上下架 /// </summary> /// <param name="product_id">商品id</param> /// <param name="status">0下架,1上架</param> /// <returns></returns> public static ReturnCode SetProductStatus(string product_id, byte status, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/modproductstatus?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { product_id = product_id, status = status })); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 上传图片 /// </summary> /// <param name="filename">图片文件名(带文件类型后缀)</param> /// <param name="data">图片数据</param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static UploadImgResult UploadImg(string filename, byte[] data, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/common/upload_img?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token + "filename=" + filename; var json = Util.HttpPost2(url, data); return(Util.JsonTo <UploadImgResult>(json)); }
/// <summary> /// 查询商品 /// </summary> /// <param name="product_id"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static GetProductResult GetProduct(string product_id, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/get?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { product_id = product_id })); return(Util.JsonTo <GetProductResult>(json)); }
/// <summary> /// 关闭订单 /// </summary> /// <param name="order_id"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode CloseOrder(string order_id, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/order/close?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { order_id = order_id })); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 上传图片 /// </summary> /// <param name="data">图片数据</param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static UploadImgResult UploadImg(string file, string appId, string appSecret) { var url = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpUpload(url, file); return(Util.JsonTo <UploadImgResult>(json)); }
/// <summary> /// 删除卡券 /// </summary> /// <param name="card_id"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode DeleteCard(string card_id, string appId, string appSecret) { var url = "https://api.weixin.qq.com/card/delete?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { card_id = card_id })); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 添加邮费模板 /// </summary> /// <param name="delivery_template"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static AddDeliveryTemplateResult AddDeliveryTemplate(DeliveryTemplate delivery_template, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/express/add?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { delivery_template = delivery_template })); return(Util.JsonTo <AddDeliveryTemplateResult>(json)); }
/// <summary> /// 获取指定分类的所有属性 /// </summary> /// <param name="cate_id"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static GetPropertyListResult GetPropertyListByCate(string cate_id, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/category/getproperty?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { cate_id = cate_id })); return(Util.JsonTo <GetPropertyListResult>(json)); }
/// <summary> /// 获取所有货架 /// </summary> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static GetShelfListResult GetShelfList(string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/shelf/getall?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpGet2(url); return(Util.JsonTo <GetShelfListResult>(json)); }
/// <summary> /// 修改货架 /// </summary> /// <param name="shelf"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode UpdateShelf(Shelf shelf, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/shelf/mod?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(shelf)); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 修改商品信息 /// 从未商家的商品所有信息均可修改,否则商品的名称、商品分类、商品属性这三个字段不可修改 /// </summary> /// <param name="product"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode UpdateProduct(Product product, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/update?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(product)); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 修改分组属性 /// </summary> /// <param name="group"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode UpdateGroupProperty(Group group, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/group/propertymod?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(group)); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 删除分组 /// </summary> /// <param name="group_id"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode DeleteGroup(long group_id, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/group/del?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { group_id = group_id })); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 增加分组 /// </summary> /// <param name="group_detail"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static AddGroupResult AddGroup(Group group_detail, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/group/add?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { group_detail = group_detail })); return(Util.JsonTo <AddGroupResult>(json)); }
/// <summary> /// 获取指定id的邮费模板 /// </summary> /// <param name="template_id"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static GetDeliveryTemplateResult GetDeliveryTemplate(long template_id, string appId, string appSecret) { var url = "https://api.weixin.qq.com/merchant/express/getbyid?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { template_id = template_id })); return(Util.JsonTo <GetDeliveryTemplateResult>(json)); }
/// <summary> /// 更改卡券信息接口 /// </summary> /// <param name="appid">应用ID</param> /// <param name="secret">开发者凭据</param> /// <param name="card_id">卡券ID。</param> /// <param name="increase_stock_value">增加多少库存,可以不填或填0code</param> /// <param name="reduce_stock_value">减少多少库存,可以不填或填0</param> /// <returns></returns> public static ReturnCode UpdateCardInfo(string appId, string appSecret, string jsonstr) { string access_token = WeiXin.GetAccessToken(appId, appSecret); string url = "https://api.weixin.qq.com/card/update?access_token=" + access_token; string data = Util.HttpPost2(url, jsonstr); ReturnCode result = Util.JsonTo <ReturnCode>(data); return(result); }
/// <summary> /// code 解码接口 /// </summary> /// <param name="appid">应用ID</param> /// <param name="secret">开发者凭据</param> /// <param name="encrypt_code">加密的卡券code</param> /// <returns></returns> public static DecryptCodeResult DecryptCode(string appId, string appSecret, string encrypt_code) { string access_token = WeiXin.GetAccessToken(appId, appSecret); string url = "https://api.weixin.qq.com/card/code/decrypt?access_token=" + access_token; string data = Util.HttpPost2(url, Util.ToJson(new { encrypt_code = encrypt_code })); DecryptCodeResult relcode = Util.JsonTo <DecryptCodeResult>(data); return(relcode); }
/// <summary> /// 删除邮费模板 /// </summary> /// <param name="delivery_template"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static ReturnCode UpdateDeliveryTemplate(DeliveryTemplate delivery_template, string appId, string appSecret) { var template_id = delivery_template.Id; var url = "https://api.weixin.qq.com/merchant/express/update?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; var json = Util.HttpPost2(url, Util.ToJson(new { template_id = template_id, delivery_template = delivery_template })); return(Util.JsonTo <ReturnCode>(json)); }
/// <summary> /// 修改库存接口 /// </summary> /// <param name="appid">应用ID</param> /// <param name="secret">开发者凭据</param> /// <param name="card_id">卡券ID。</param> /// <param name="increase_stock_value">增加多少库存,可以不填或填0code</param> /// <param name="reduce_stock_value">减少多少库存,可以不填或填0</param> /// <returns></returns> public static ReturnCode ModifyStock(string appId, string appSecret, string card_id, int increase_stock_value, int reduce_stock_value) { string access_token = WeiXin.GetAccessToken(appId, appSecret); string jsonstr = ""; jsonstr = Util.ToJson(new { card_id = card_id, increase_stock_value = increase_stock_value, reduce_stock_value = reduce_stock_value }); string url = "https://api.weixin.qq.com/card/modifystock?access_token=" + access_token; string data = Util.HttpPost2(url, jsonstr); ReturnCode result = Util.JsonTo <ReturnCode>(data); return(result); }
/// <summary> /// 公众号用于调用微信JS接口的临时票据 /// </summary> /// <param name="appid">应用ID</param> /// <param name="secret">开发者凭据</param> /// <returns></returns> public static string GetJsapiTicket(string appId, string appSecret) { //正常情况下jsapi_ticket有效期为7200秒,这里使用缓存设置短于这个时间即可 string jsapi_ticket = MemoryCacheHelper.GetCacheItem <string>("jsapi_ticket", delegate() { string access_token = WeiXin.GetAccessToken(appId, appSecret); string data = Util.HttpGet2("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + access_token + "&type=jsapi"); JsApiTicket ticket = Util.JsonTo <JsApiTicket>(data); return(ticket.ticket); }, new TimeSpan(0, 0, 600)//300秒过期 , DateTime.Now.AddSeconds(600) ); return(jsapi_ticket); }
/// <summary> /// 获取所有卡券列表 /// </summary> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static GetCardListResult GetAllCardList(string appId, string appSecret) { WeiXin.CheckGlobalCredential(); GetCardListResult allCard = new GetCardListResult(); allCard.total_num = 0; allCard.card_id_list = new List <string>(); allCard.errcode = 0; allCard.errmsg = "ok"; int offset = 0; int count = 50; int totalnum = 0; do { var c = GetCardList(offset, count, appId, appSecret); if (c.errcode != 0) { allCard.errcode = c.errcode; allCard.errmsg = c.errmsg; break; } else { if (c.total_num > 0) { foreach (var cdid in c.card_id_list) { allCard.card_id_list.Add(cdid); } } totalnum = c.total_num; offset = offset + count; } } while (offset < totalnum); allCard.total_num = totalnum; return(allCard); }
/// <summary> /// 查询卡券code 的有效性 /// </summary> /// <param name="code"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static CheckCodeResult CheckCode(string code, string card_id, string appId, string appSecret) { var url = "https://api.weixin.qq.com/card/code/get?access_token="; var access_token = WeiXin.GetAccessToken(appId, appSecret); url = url + access_token; string jsonstr = ""; if (string.IsNullOrEmpty(card_id)) { jsonstr = Util.ToJson(new { code = code }); } else { jsonstr = Util.ToJson(new { code = code, card_id = card_id }); } var json = Util.HttpPost2(url, jsonstr); return(Util.JsonTo <CheckCodeResult>(json)); }