Software version requirements: iOS13 and above
Demo model: iPhone 12 mini
Demo system version: iOS14.6
Article directory
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 POST
a 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.
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.
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/login
in this URL. Then click in the operation 展开
and 方法
change to POST
.
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:类型
键
username
password
文本
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.
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 好
.
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.cn
to verify that we have logged in.
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.
After the test runs successfully, we click Next to give this shortcut a name. In this way, a complete shortcut command is created.
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.
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.
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.
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.
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:
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 x
to 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.
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 sameURL
as logging in to the campus networkURL
) , and you do not need to fill in the user name and password.POST
If there is no response after sending this request, please check whether you have connected to NJU-WLAN and logged into the campus network.