C # WeChat portal and application development (24)-WeChat store shelf information management,

Source: Internet
Author: User
Tags tojson

C # development portal and application (24)-store shelf information management,

In the previous article "C # development portal and application (22)-Development and Use of stores" in the store series, I introduced some basic knowledge about stores, in addition, the C # development portal and application (23)-packaging and testing of the store product management interface details the interface definition, implementation, and testing of the store product, this article describes how to manage store shelves. This module is the most complex and hard-to-understand module in the store object. For its object modeling, it must be tested repeatedly before it can be improved. Therefore, this shelf management module, it can be said that it is the most technical module.

1. Introduction to store shelves

In the background of the public account, you can maintain the shelf information, as shown in the following figure. The concept of shelves is to present products to customers in different categories. shelves are similar to display cabinets with good layout. 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 provides us with a visual reference interface to quickly build a shelf. The shelf template interface is shown below.

 

2. Development Model of Shelf Management

The shelf management operation interfaces for store and store development by using APIs are similar to those of conventional modules and have the following functions.

Although it looks similar to the previous object model, the shelf information is very complex. Therefore, if you want to restore the information as an object based on Json data, you need to consider it repeatedly, otherwise, modeling errors are easy.

Corresponding to the shelf template on the store management interface, the shelf object information includes five different control models, some of which can be used in combination.

The models of several shelves are shown 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 ":" Test shelf "}View Code

Based on the definition of JSON data, we define several shelf controls. Their relationships are as follows.

We can model object Objects Based on JSON data. With these objects, we can further define shelf-related operation interfaces. The interface definition is as follows.

# Region Shelf Management /// <summary> /// add shelves /// </summary> /// <param name = "accessToken"> call interface creden< </param> /// <param name = "shelfBanner"> shelf sign image Url </param> /// <param name = "shelfName"> shelf name </param> /// <param name = "controls"> shelf controls 1, 2, 3, 4, and 5 collection </param> /// <returns> </returns> AddShelfResult AddShelf (string accessToken, string shelfBanner, string shelfName, List <ShelfControlBase> controls ); /// <summary> /// Delete shelf /// </summary> /// <param name = "accessToken"> call interface creden< </param> /// <param name = "shelfId"> shelf Id </param> // <returns> </returns> CommonResult DeleteShelf (string accessToken, int shelfId ); /// <summary> /// modify the shelf /// </summary> /// <param name = "accessToken"> call interface creden< </param> /// <param name = "shelfId"> shelf Id </param> // <param name = "shelfBanner"> shelf sign image Url </param> // <param name =" shelfName "> shelf name </param> // <param name =" controls "> shelf Control 1, 2, 3, 4, and 5 types </param> /// <returns> </returns> CommonResult UpdateShelf (string accessToken, int shelfId, string shelfBanner, string shelfName, list <ShelfControlBase> controls ); /// <summary> /// obtain all shelves /// </summary> /// <param name = "accessToken"> call interface creden< </param> /// <returns> </returns> List <ShelfJson> GetAllShelf (string accessToken ); /// <summary> /// obtain the shelf information based on the shelf ID /// </summary> /// <param name = "accessToken"> call interface creden< </param> /// <param name = "shelfId"> shelf Id </param> /// <returns> </returns> ShelfJson GetShelfById (string accessToken, int shelfId); # endregion

With the definition of these interfaces, we need to implement the corresponding interfaces so that we can encapsulate and process them into the API.

The content of the store's shelf management implementation is as follows (add, delete, and modify some content ).

/// <Summary> /// add shelves /// </summary> /// <param name = "accessToken"> call interface creden< </param> /// <param name = "shelfBanner"> shelf sign image Url </param> // <param name = "shelfName"> shelf name </param> // <param name =" controls "> shelf controls 1, 2, 3, 4, and 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> /// Delete shelf /// </summary> /// <param name = "accessToken"> call interface creden< </param> /// <param name = "shelfId"> shelf 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> /// modify the shelf /// </summary> /// <param name = "accessToken"> call interface creden< </param> /// <param name = "shelfId"> shelf Id </param> // <param name = "shelfBanner"> shelf sign image Url </param> // <param name =" shelfName "> shelf name </param> // <param name =" controls "> shelf Control 1, 2, 3, 4, and 5 types </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. store shelf Management Interface Test

Because the definition of shelf management objects and interfaces is more complex, you must perform repeated tests before you can use them. If you do not pay attention to the definition, you may not be able to obtain information about a field.

For convenience, I created a Winform project to test each interface.

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 ("Shelf information:"); 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 =" test shelf "; 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 ("added shelf information:"); ShelfJson getJson = api. getShelfById (token, result. shelf_id); Console. writeLine (getJson. toJson (); shelf_name = "test shelf-modify"; controlList = new List <ShelfControlBase> () {c11}; CommonResult updateReuslt = api. updateShelf (token, result. shelf_id, shelf_banner, shelf_name, controlList); Console. writeLine ("Modify shelf operation: {0}", updateReuslt. success? "Successful": "failed"); CommonResult deleteResult = api. deleteShelf (token, result. shelf_id); Console. writeLine ("delete shelf operation: {0}", deleteResult. success? "Successful": "failed ");}}

 

If you are interested in this series of C # development portals and applications, you can follow my other articles as follows:

C # development portal and application (24)-store shelf Information Management

C # development portal and application (23)-packaging and testing of the store product management interface

C # development portal and application (22)-Development and Use of stores

C # development portal and application (21)-receiving, processing, and decryption of enterprise numbers and events

C # development portal and application (20)-menu management of enterprise number

C # development portal and application (19)-sending of enterprise numbers (text, images, files, voice, video, text messages, etc)

C # development portal and application (18)-member management for enterprise address book management and development

C # development portal and application (17)-department management for enterprise address book management and development

C # development portal and application (16)-enterprise number configuration and use

C # development portal and application (15)-added the scan, image sending, and geographic location functions in the menu

C # development portal and application (14)-use redirection in the menu to obtain user data

C # development portal and application (13)-use geographic location Extension

C # development portal and application (12)-use voice processing

C # development portal and application (11)-menu presentation

C # development portal and application (10) -- synchronize user group information in the management system

C # development portal and application (9)-portal menu management and submission to server

C # development portal and application (8)-portal application management system function Introduction

C # development portal and application (7)-Multi-customer service functions and development integration

C # development portal and application (6)-portal menu management operations

C # development portal and application (5) -- User Group Information Management

C # development portal and application (4) -- Focus on the user list and detailed information management

C # development portal and application (3) -- Response to text messages and text messages

C # development portal and application (2) -- Message Processing and response

C # development portal and application (1) -- getting started with Interfaces

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.