


C# development of WeChat portal and application of WeChat store shelf information management
Mar 01, 2017 am 10:43 AM1. Introduction to WeChat store shelves
In the background of the WeChat official account, shelf information can be maintained, and the interface is as follows. The concept of a shelf is to display products in categories to customers. A shelf is similar to a well-layed showcase. We can define different shelves and then publish different URLs for experience.
In addition, we generally create shelves based on the shelf template library. The shelf template allows us to quickly build a shelf and provides a visual reference interface. The shelf template interface is shown below.
2. Development model of shelf management
For the development of WeChat stores using APIs, the shelf management operation interface of WeChat stores, It is similar to a regular module and has the following functional operations.
Although it looks similar to the previous object model, the shelf information is very complex, so if you need to restore it to an entity object based on Json data, you need to repeat it. Consider it carefully, otherwise it is easy to model errors.
Corresponds to the shelf template of the WeChat store management interface. The object information of the shelf includes 5 different control models, and some of them can be used in combination.
The model display of several shelves is shown below.
{ "shelf_data": { "module_infos": [ { "group_info": { "filter": { "count": 2 }, "group_id": 50 }, "eid": 1 }, { "group_infos": { "groups": [ { "group_id": 49 }, { "group_id": 50 }, { "group_id": 51 } ] }, "eid": 2 }, { "group_info": { "group_id": 52, "img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5Jm64z4I0TTicv0TjN7Vl9bykUUibYKIOjicAwIt6Oy0Y6a1Rjp5Tos8tg/0" }, "eid": 3 }, { "group_infos": { "groups": [ { "group_id": 49, "img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5uUQx7TLx4tB9qZfbe3JmqR4NkkEmpb5LUWoXF1ek9nga0IkeSSFZ8g/0" }, { "group_id": 50, "img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5G1kdy3ViblHrR54gbCmbiaMnl5HpLGm5JFeENyO9FEZAy6mPypEpLibLA/0" }, { "group_id": 52, "img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5uUQx7TLx4tB9qZfbe3JmqR4NkkEmpb5LUWoXF1ek9nga0IkeSSFZ8g/0" } ] }, "eid": 4 }, { "group_infos": { "groups": [ { "group_id": 43 }, { "group_id": 44 }, { "group_id": 45 }, { "group_id": 46 } ], "img_background": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5uUQx7TLx4tB9qZfbe3JmqR4NkkEmpb5LUWoXF1ek9nga0IkeSSFZ8g/0" }, "eid": 5 } ] }, "shelf_banner": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2ibrWQn8zWFUh1YznsMV0XEiavFfLzDWYyvQOBBszXlMaiabGWzz5B2KhNn2IDemHa3iarmCyribYlZYyw/0", "shelf_name": "測(cè)試貨架" }We have defined several shelf control objects based on the definition of JSON data. Their relationship is as follows.
#region 貨架管理 /// <summary> /// 增加貨架 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <param name="shelfBanner">貨架招牌圖片Url</param> /// <param name="shelfName">貨架名稱</param> /// <param name="controls">貨架控件1,2,3,4,5類型的集合</param> /// <returns></returns> AddShelfResult AddShelf(string accessToken, string shelfBanner, string shelfName, List<ShelfControlBase> controls); /// <summary> /// 刪除貨架 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <param name="shelfId">貨架Id</param> /// <returns></returns> CommonResult DeleteShelf(string accessToken, int shelfId); /// <summary> /// 修改貨架 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <param name="shelfId">貨架Id</param> /// <param name="shelfBanner">貨架招牌圖片Url</param> /// <param name="shelfName">貨架名稱</param> /// <param name="controls">貨架控件1,2,3,4,5類型的集合</param> /// <returns></returns> CommonResult UpdateShelf(string accessToken, int shelfId, string shelfBanner, string shelfName, List<ShelfControlBase> controls); /// <summary> /// 獲取所有貨架 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <returns></returns> List<ShelfJson> GetAllShelf(string accessToken); /// <summary> /// 根據(jù)貨架ID獲取貨架信息 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <param name="shelfId">貨架Id</param> /// <returns></returns> ShelfJson GetShelfById(string accessToken, int shelfId); #endregion
有了這些接口的定義,我們就需要實(shí)現(xiàn)對(duì)應(yīng)的接口,從而實(shí)現(xiàn)我們向微信API的封裝處理了。
微信小店的貨架管理實(shí)現(xiàn)內(nèi)容如下所示(部分內(nèi)容,增刪改)。
/// <summary> /// 增加貨架 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <param name="shelfBanner">貨架招牌圖片Url</param> /// <param name="shelfName">貨架名稱</param> /// <param name="controls">貨架控件1,2,3,4,5類型的集合</param> /// <returns></returns> public AddShelfResult AddShelf(string accessToken, string shelfBanner, string shelfName, List<ShelfControlBase> controls) { var url = string.Format("https://api.weixin.qq.com/merchant/shelf/add?access_token={0}", accessToken); var data = new { shelf_data = new { module_infos = controls }, shelf_banner = shelfBanner, shelf_name = shelfName }; string postData = data.ToJson(); return JsonHelper<AddShelfResult>.ConvertJson(url, postData); } /// <summary> /// 刪除貨架 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <param name="shelfId">貨架Id</param> /// <returns></returns> public CommonResult DeleteShelf(string accessToken, int shelfId) { var url = string.Format("https://api.weixin.qq.com/merchant/shelf/del?access_token={0}", accessToken); var data = new { shelf_id = shelfId }; string postData = data.ToJson(); return Helper.GetExecuteResult(url, postData); } /// <summary> /// 修改貨架 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <param name="shelfId">貨架Id</param> /// <param name="shelfBanner">貨架招牌圖片Url</param> /// <param name="shelfName">貨架名稱</param> /// <param name="controls">貨架控件1,2,3,4,5類型的集合</param> /// <returns></returns> public CommonResult UpdateShelf(string accessToken, int shelfId, string shelfBanner, string shelfName, List<ShelfControlBase> controls) { var url = string.Format("https://api.weixin.qq.com/merchant/shelf/mod?access_token={0}", accessToken); var data = new { shelf_id = shelfId, shelf_data = new { module_infos = controls }, shelf_banner = shelfBanner, shelf_name = shelfName }; string postData = data.ToJson(); return Helper.GetExecuteResult(url, postData); }
4、微信小店貨架管理的接口測(cè)試
由于貨架管理的對(duì)象和接口定義比較復(fù)雜一些,一定需要進(jìn)行反復(fù)的測(cè)試才能正式使用,如果不注意有可能你定義的實(shí)體類,獲取不到某個(gè)字段信息。
我為了方便,創(chuàng)建了一個(gè)Winform項(xiàng)目,分別對(duì)各個(gè)接口進(jìn)行測(cè)試。
對(duì)于貨架管理內(nèi)容的接口測(cè)試,測(cè)試代碼如下所示。
private void btnShelf_Click(object sender, EventArgs e) { IMerchantApi api = new MerchantApi(); List<ShelfJson> list = api.GetAllShelf(token); Console.WriteLine(list.ToJson()); foreach(ShelfJson json in list) { Console.WriteLine("貨架信息:"); ShelfJson getJson = api.GetShelfById(token, json.shelf_id.Value); Console.WriteLine(getJson.ToJson()); } string shelf_banner = "http://mmbiz.qpic.cn/mmbiz/mLqH9gr11Gyb2sgiaelcsxYtQENGePp0RgeNlAQicfZQokjbJMUq4h8MHtjpekJNEWKuMN3gdRz5RxfkYb7NlIrw/0"; string shelf_name = "測(cè)試貨架"; ShelfControl1 c11 = new ShelfControl1(6, 202797386); ShelfControl1 c12 = new ShelfControl1(4, 202797397); List<ShelfControlBase> controlList = new List<ShelfControlBase>(){c11, c12}; AddShelfResult result = api.AddShelf(token, shelf_banner, shelf_name, controlList); if (result != null && result.shelf_id > 0) { Console.WriteLine("增加的貨架信息:"); ShelfJson getJson = api.GetShelfById(token, result.shelf_id); Console.WriteLine(getJson.ToJson()); shelf_name = "測(cè)試貨架-修改"; controlList = new List<ShelfControlBase>(){c11}; CommonResult updateReuslt = api.UpdateShelf(token, result.shelf_id, shelf_banner, shelf_name, controlList); Console.WriteLine("修改貨架操作:{0}", updateReuslt.Success ? "成功" : "失敗"); CommonResult deleteResult = api.DeleteShelf(token, result.shelf_id); Console.WriteLine("刪除貨架操作:{0}", deleteResult.Success ? "成功" : "失敗"); } }
?
更多C# development of WeChat portal and application of WeChat store shelf information management相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)