


C# development of WeChat portal and application-WeChat store shelf information management
Feb 18, 2017 am 09:58 AMIn 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.
1. 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":?"測試貨架"}
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">調(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
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">調(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("http://ipnx.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">調(diào)用接口憑證</param> ????????///?<param name="shelfId">貨架Id</param> ????????///?<returns></returns> ????????public?CommonResult?DeleteShelf(string?accessToken,?int?shelfId) ????????{????????????var?url?=?string.Format("http://ipnx.cn/{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("http://ipnx.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); ????????}
4. Interface testing of WeChat store shelf management
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://ipnx.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!

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)
