This is an API based on the online ordering system owned by Shenzhen Experimental School.
Developers can bypass the originally unnecessary but unavoidable value-passing codes, free themselves from the complicated and incomprehensible logic, and conduct online ordering interaction through the more simplistic interfaces of the packaged szsy-canteen API.
szsy-canteen API is written in Golang which can ensure its efficiency and performance. The API is suitable for the secondary development of the online ordering system 💗
Why use this API
In short, the API is designed to be simple, data-saving and efficient.
For the original intention was aimed at reducing the cost of mobile application development of the school online ordering system, the logic-optimization and data-saving were regard as important indicators in design of the API. Here is an example. The API provides an interface for obtaining a list of “orderable dates” directly, which save the overhead of operations such as “gaining all dates including unnecessary ones” (waste of data traffic) and “judging whether the dates can be ordered” (complex logic).
Of course, some parts of the API is roughly-designed because the developing time is limited and my lack for programming ability. Welcome new contribution, and hope that you can let me know if you made a new implementation of the ordering system and I will update your repo link in the README 😄
How to configure
If you are a developer on 64-bit Windows or Linux, you can download the pre-compiled package of your specific system. Double-click to execute it and the API will be enabled on port 2018
on the local machine by default.
If you attempt to compile it and run it yourself, you need to install the developing environment required by Golang, do necessary configurations and download the complete source files to compile. You can execute the following command to generate an executable file for your platform.
|
|
Get started
The szsy-canteen API provides the following interfaces:
login
: Login to the online ordering system to get basic information and the key for further operationsdates
: Obtain the list of all the dates that can be ordered currently (i.e. the dates before the order deadline)menu
: Get details and order status of the menu for the specific dateorder
: Submit the order request for the specific datelogout
: Log out of the online ordering system
The URL of the API in default configuration should be
|
|
Login to online ordering system
Write username and password encrypted with the MD5 algorithm to the JSON field. Here is an example.
|
|
For security reasons, the encrypting process of the password with MD5 is handed over to the requester on design, that is, you need to encrypted password string yourself and put it into the
密码
(password) item.
Submit to URL with POST method
|
|
The API will return a JSON as follows
|
|
In fact, the value of the
口令
(the key) will be much longer than the one in the example. Here, the key has been shortened for typography.
Obtain orderable dates list
Write the key returned at login to the JSON field
|
|
Submit to URL with POST method
|
|
You will get return data as follows
|
|
The date list will contain all orderable dates, i.e. the API will also try requesting menus for the next month without missing orderable dates in the next month. The school updates at most two months’ menus once. You can leave the job to the szsy-canteen API at ease.
Obtain the specific date menu
Similarly, write the key to the JSON field.
|
|
Submit to the URL with the “specific date” parameter with the POST method
|
|
You can get return JSON as follows
|
|
Each dish includes the following information points
|
|
The item of 不订餐
(not order) should be a null
value in general, as the example above. Of course, if you choose not to order 早餐
(breakfast) or 午餐
(lunch) , then the value of 不订餐
(not order) will supposed to be
|
|
July 10, 2018 is Friday in this example, so the menu for dinner is missing, i.e. the value of
晚餐
(dinner) isnull
Submit an order request
Write the key obtained at login and the order information for breakfast, lunch and dinner to the JSON field.
|
|
There are three formats for order information, and the example has given all the cases.
套餐
(set menu) (i.e. equivalent to “1,0,0,0,0,0,0,0”)不订餐
(not order) (i.e. equivalent to check the “not order” checkbox)Write the number you would like to order of eight dishes with commas as separators
Therefore, in this case, this student chose a “套餐”(set menu) for his breakfast. For lunch, he chose 2 servings of “蒜茸炒黄芽白”, 1 serving of “肉末豆角” and 1 serving of “香辣翅根2个”, and choose “不订餐”(not order) for dinner.
On Friday night, i.e. the menu for dinner is missing, you should serve the
晚餐
(dinner) item anull
value instead of omitting the晚餐
(dinner) item. Here, in order to show the不订餐
(not order) field,晚餐
(dinner) is filled in with it, but it should benull
😂
You may find that the first dish in the eight dishes is
套餐
(set menu). In fact, if one of the dishes following is not0
, the value of套餐
(set menu) will be covered by0
regardless of what the value is.
Then use the POST method to submit to the URL with the “specific date” parameter
|
|
You may get types of return information
提交成功
(the request is submitted successfully, and the order information is written to the system)账户异常
(this account is frozen or stuck in other abnormal situations, often means in arrear)超过订餐时间
(the date is over the order deadline, you can avoid this error by checking whether the date in the “orderable date” list before submitting)提交失败
(failed for the reason that network timeout or school server goes down, etc.)
The time it takes for the school server to deal with the order information is far more than the time needed normally, so you usually have to wait a few seconds to get feedback (students in SZSY should be impressed) Do not submit too often, you might fail, and even worse, get the wrong return information.
Logout online ordering system
Write the key obtained at login to the JSON field
|
|
Submit to URL with POST method
|
|
You will logout after reading 登出成功
.
Error about key expiration
szsy-canteen API error messages are fairly legible, but there is a special explanation for this.
If you are using a key to request dates list, obtain menu, or submit request with receiving 口令错误或过期
error message, it means your key may have expired. In this case, all you need to do is re-login to get the new key.
Tips for ordering multiple servings
The school online ordering system limits 3 servings for each dish maximum, which is conducted by the JavaScript script on the website. However, there is no such restriction if using the API. In theory, you can order more than 3 servings.
The practical tests show that the success rate of 5 servings or less is relatively higher, and the submissions will be accepted in most cases. If the number is too exaggerated, the success rate falls to zero basically, and there will be a 提交失败
(submit failed) error returning. The maximum number which successfully submitted I have tried is 20, yes, 20 servings of 卤鸡腿.
Of course, this is not a bug. 20 servings of 卤鸡腿 means you have to pay them as 20 servings (I won’t state this here if not so)
This text added here is a piece of advice: As a developer, you can offer an entry that can modify the number of servings in an explicit way when developing the client. After all, adding a dish of “净荤菜” occasionally is also a sort of pleasure.
Acknowledgement
Thanks to the above two for your technical and moral supports during development 💗