Home >WeChat Applet >WeChat Development >C# development of WeChat portal and application-WeChat store shelf information management
In the previous WeChat Store series article "C# Development of WeChat Portal and Application (22) - Development and Use of WeChat Store", some basic knowledge of WeChat Store is introduced, as well as "C# Development of WeChat Portal and Application (23) )-Encapsulation and Testing of WeChat Store Product Management Interface" details the interface definition, implementation and testing of WeChat store products. This article mainly introduces WeChat store shelf information management. This module is the most complex and difficult to understand among the WeChat store objects. Its object modeling requires repeated testing before it can be perfected. Therefore, this shelf management module can be said to be the most technical one. module.
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.
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.
##Through the above 5 control models, we can see They represent different layout effects respectively, and they can be used in combination on the shelves. 3. Object modeling of shelf informationAccording to the interface description of WeChat store, the shelf entity object information we finally defined is very rich and flexible in content. By referring to the API description of the WeChat store, we can see that the shelf information JSON data is very complex, and the specific definition is as follows.{ "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": "测试货架"}
View Code
We define based on the definition of JSON data There are several shelf control objects, and their relationships are as follows.
We can model entity objects based on JSON data, and then with these objects, we can further define the relevant operation interfaces of the shelves. The interface definition is as follows Show.
#region 货架管理 /// <summary> /// 增加货架 /// </summary> /// <param name="accessToken">调用接口凭证</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">调用接口凭证</param> /// <param name="shelfId">货架Id</param> /// <returns></returns> CommonResult DeleteShelf(string accessToken, int shelfId); /// <summary> /// 修改货架 /// </summary> /// <param name="accessToken">调用接口凭证</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">调用接口凭证</param> /// <returns></returns> List<ShelfJson> GetAllShelf(string accessToken); /// <summary> /// 根据货架ID获取货架信息 /// </summary> /// <param name="accessToken">调用接口凭证</param> /// <param name="shelfId">货架Id</param> /// <returns></returns> ShelfJson GetShelfById(string accessToken, int shelfId); #endregion
With the definition of these interfaces, we need to implement the corresponding interfaces to achieve our encapsulation to the WeChat API.
The shelf management implementation content of WeChat store is as follows (part of the content, additions, deletions and modifications).
/// <summary> /// 增加货架 /// </summary> /// <param name="accessToken">调用接口凭证</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("http://www.php.cn/{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">调用接口凭证</param> /// <param name="shelfId">货架Id</param> /// <returns></returns> public CommonResult DeleteShelf(string accessToken, int shelfId) { var url = string.Format("http://www.php.cn/{0}", accessToken); var data = new { shelf_id = shelfId }; string postData = data.ToJson(); return Helper.GetExecuteResult(url, postData); } /// <summary> /// 修改货架 /// </summary> /// <param name="accessToken">调用接口凭证</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("http://www.php.cn/{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); }
Since the object and interface definitions of shelf management are more complicated, it must be carried out Only after repeated testing can it be officially used. If you don't pay attention, it is possible that the entity class you defined may not be able to obtain certain field information.
For convenience, I created a Winform project to test each interface separately.
For the interface test of shelf management content, the test code is as follows.
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://www.php.cn/"; string shelf_name = "测试货架"; 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 = "测试货架-修改"; 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 ? "成功" : "失败"); } }
More C# development of WeChat portals and applications-WeChat store shelf information management related Please pay attention to the PHP Chinese website for articles!