iOS shortcut command: one-click login/logout of Nanjing University Campus Network

Software version requirements: iOS13 and above

Demo model: iPhone 12 mini

Demo system version: iOS14.6

preface

If you only log in to the campus network as needed, log out when you are done using it, and feel that it is troublesome to open it with a browser every time you log in/out p.nju.edu.cn, then congratulations, this article will perfectly solve your problem . If you have not encountered the above problems (for example, you are a local tyrant who never logs out of the campus network and pays a fixed monthly network fee of 20 yuan), but you want to learn how to make an iOS shortcut (provided that you must have a NTU campus network account), then you are also one of the target readers of this article. This article will build a shortcut command from scratch, with a lot of gif pictures for demonstration. We hope this article was helpful to you.

The core steps of one-click login/logout of the campus network are inspired by this blogp.nju.edu.cn/portal_io/login , and the most critical operation is to send POSTa request to . In this article, we first write the core steps of one-click login to the campus network as a shortcut command to demonstrate its principle. Then we will start from the core steps and recreate the automatic login instructions to achieve a simpler and more elegant login method. Finally, we will introduce the shortcut command to log out of the campus network with one click. On the basis of understanding the one-click login command, creating a one-click logout command will become very simple.


Core steps: the simplest one-click login instruction

Shortcuts is an app that comes with the iOS system. If you can’t find it, you can search for “shortcuts” in the appstore and download it again. In this part, the function we want to achieve is, under the premise of connecting to NJU-WLAN, when we click an icon on the home screen (our goal is to create an icon with this function), our device will automatically log in Campus Network.

First, we open the shortcut command app, click +the number in the upper right corner, and create a new shortcut command.
insert image description here

Let's add the first operation to the shortcut command, which is also the core operation. Click 添加操作the button, find 获取URL内容this operation, and click it to add it.
insert image description here

Click on the Chinese character of the operation URL, we find that this is an input box, so fill p.nju.edu.cn/portal_io/loginin this URL. Then click in the operation 展开and 方法change to POST.
insert image description here

Click 请求体in one column 表单, and then click to add two fields 添加新字段with text as and . The fields are the account number and password to log in to the campus network, which is what you enter in this interface:类型usernamepassword文本
insert image description here
insert image description here

With this, we have created our first action. We add a second action to display the results of logging into the campus network. Click the number below the first operation +, find 显示结果this operation, and add it. It will automatically take the URL content just obtained as the result to be displayed.
insert image description here

Now, the core operations have been added. We go to the settings of the iOS device to open the wireless LAN and connect to NJU-WLAN. Then go back to the shortcut command, click the small triangle in the lower right corner to test and run the two operations just added. At this time, a prompt to allow access to the campus network will appear, click .
insert image description here

If it is stuck at the first operation, it is likely that the NJU-WLAN is not connected properly. Once the login is complete, the login success message as shown in the figure below will be displayed. Now we can open it with a browser p.nju.edu.cnto verify that we have logged in.
insert image description here

It doesn't matter if you clicked to not allow shortcuts to access the campus network in the previous step. We click on the three dots in the upper right corner ( 下一步under ) to open 互联网the option (this option will not appear until after running this shortcut command, that is, after clicking the small triangle in the lower right corner), and then click the small triangle in the lower right corner to retest Just run it.
insert image description here

After the test runs successfully, we click Next to give this shortcut a name. In this way, a complete shortcut command is created.
insert image description here

We can add it to the home screen of the device. In , find the shortcut instruction 所有快捷指令just made , click the three dots in the upper right corner of it, and we will come to the editing interface of the instruction again. 一键登录Tap the three dots in the upper right corner of the interface, tap again 添加到主屏幕, and it will be added to the home screen.
insert image description here

Whenever you need to log in to the campus network, you only need to click 一键登录the icon on the main screen to complete the login.
insert image description here


Automation: Automatic login after connecting to NJU-WLAN

In this part, the effect we want to achieve is that as long as it is connected to NJU-WLAN, the device can automatically execute the shortcut commands created in the previous part, instead of manually clicking the icon on the home screen 一键登录. The tools we are going to use here are shortcut commands 自动化.

First open the shortcut command app, click on the menu bar below 自动化to enter the automation interface. Then click 创建个人自动化, select 无线局域网, click 选取, find NJU-WLAN, click it to tick. Then click in the upper right corner 完成, and then click in the upper right corner 下一步, so that we enter the editing interface for adding operations.
insert image description here

The steps we have just carried out are setting the conditions for automation. That is to say, when our device is connected to NJU-WLAN, the condition is met, and then the device should automatically start to perform a series of operations (that is, the operations we will add in this editing interface next). Think about it, what should the device do after connecting to NJU-WLAN? That's right, it is to log in to the campus network. The content is exactly the same as that described in the previous part of the article, we add two operations of logging in to the campus network in this editing interface. After the addition is complete, we click 下一步and 完成, and the automation is created. We can connect to NJU-WLAN to test whether the automation works successfully.
Please add a picture description


Modify the details: make the instruction more elegant

In the above, whether it is a shortcut command or an automation, the last operation of our command is 显示结果, that is, the following information is displayed:
Please add a picture description

In fact, the only information we want to see is "login successful", and the rest of the information is redundant information. We want to filter out these redundant information and only display "login successful" or "login failed". So we click on 显示结果the upper right corner of this operation xto delete it, and then add the operation 从输入中获取文本. Then add operations 如果, and two 显示结果. The contents of the two 显示结果are "login successful" and "login failed". We need to drag these two 显示结果to the bottom of 如果and respectively 否则. There is also a little trick here: long press the icon in the upper left corner of an operation, and then select 复制, we can get a copy of the operation.
Please add a picture description
Please add a picture description

Test run your shortcut or automation again to see if the result is what you expected?


Small exercise: Create a shortcut command for "one-click logout"

Referring to the effect achieved in the "core steps", we implemented a shortcut command for logging out of the campus network and added it to the home screen. When you need to log out of the campus network, you can log out by clicking the icon on the main screen. We give the complete shortcut instructions in the form of pictures. We leave it as a small exercise and invite the reader to implement it himself.

hint

To log out of the campus network, you only need to send a request to p.nju.edu.cn/portal_io/logout(note that this is not the same URLas logging in to the campus network URL) , and you do not need to fill in the user name and password. POSTIf there is no response after sending this request, please check whether you have connected to NJU-WLAN and logged into the campus network.

Please add a picture description

Guess you like

Origin blog.csdn.net/Qmj2333333/article/details/120785454