CN112015383A - Login method and device - Google Patents
Login method and device Download PDFInfo
- Publication number
- CN112015383A CN112015383A CN201910452009.9A CN201910452009A CN112015383A CN 112015383 A CN112015383 A CN 112015383A CN 201910452009 A CN201910452009 A CN 201910452009A CN 112015383 A CN112015383 A CN 112015383A
- Authority
- CN
- China
- Prior art keywords
- login
- address information
- request
- response message
- request message
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/958—Organisation or management of web site content, e.g. publishing, maintaining pages or automatic linking
- G06F16/972—Access to data in other repository systems, e.g. legacy data or dynamic Web page generation
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Computing Systems (AREA)
- Data Mining & Analysis (AREA)
- Information Transfer Between Computers (AREA)
Abstract
本发明公开了一种登录方法和装置,涉及计算机技术领域。该方法的一具体实施方式包括:拦截请求消息以及与请求消息相对应的响应消息;根据预定义的登录判断规则,以及响应消息中的状态码,判断用户是否登录;其中,登录判断规则中设置有状态码和状态码代表的含义;在用户未登录的情况下,从响应消息中获取登录地址信息,以基于登录地址信息进行登录。该方法中客户端在拦截请求消息和对应的响应消息后,基于设定的登录判断规则和响应消息,判定用户未登录时,从响应消息中获取登录地址信息,进而完成登录。该方法实现了一种灵活的登录方式,客户端只需进行好登录拦截,无需关心使用哪个地址登录。
The invention discloses a login method and device, and relates to the technical field of computers. A specific implementation of the method includes: intercepting a request message and a response message corresponding to the request message; judging whether the user is logged in according to a predefined login judgment rule and a status code in the response message; wherein, the login judgment rule sets There are status codes and meanings represented by the status codes; when the user is not logged in, the login address information is obtained from the response message to log in based on the login address information. In this method, after intercepting the request message and the corresponding response message, the client determines that the user has not logged in based on the set login judgment rule and the response message, and obtains the login address information from the response message, and then completes the login. This method implements a flexible login method. The client only needs to intercept the login and does not need to care which address is used to log in.
Description
技术领域technical field
本发明涉及计算机领域,尤其涉及一种登录方法和装置。The present invention relates to the field of computers, and in particular, to a login method and device.
背景技术Background technique
目前大多数的应用程序采用客户端、服务端分离的方式进行开发,客户端使用Vue、React等技术,服务端提供接口。在应用程序中,用户登录是最基本的功能,现有技术一般都只从服务端(也称为后端)或者客户端进行登录处理。从服务端进行登录处理的实现原理为:服务端配置拦截器,拦截所有的页面请求,判断页面请求中是否有登录标识,如果没有,自动跳转到登录页面;如果有,继续完成页面请求。从客户端进行登录处理的实现原理为:由客户端在首次打开的页面中判断是否存在cookie,如果存在,则不做处理;如果不存在,则跳转到登录页面。At present, most applications are developed in a way of separating the client and the server. The client uses Vue, React and other technologies, and the server provides an interface. In an application program, user login is the most basic function, and the prior art generally only performs login processing from a server (also called a backend) or a client. The implementation principle of login processing from the server is as follows: the server configures an interceptor, intercepts all page requests, and determines whether there is a login ID in the page request. If not, it automatically jumps to the login page; if so, continues to complete the page request. The implementation principle of the login processing from the client is: the client determines whether there is a cookie in the page opened for the first time, if it exists, it will not be processed; if it does not exist, it will jump to the login page.
在实现本发明过程中,发明人发现现有技术中至少存在如下问题:In the process of realizing the present invention, the inventor found that there are at least the following problems in the prior art:
(1)从服务端进行登录处理的方式,只适用于服务端渲染或者客户端、服务端不分离的情况,而在客户端、服务端分离的大环境下,该方式由于客户端服务的阻隔或者客户端ajax的原因,会导致无法跳转到登录页面。(1) The method of logging in from the server is only suitable for server-side rendering or when the client and server are not separated. In the environment where the client and server are separated, this method is due to the obstruction of client services. Or the reason of client-side ajax will make it impossible to jump to the login page.
(2)从客户端进行登录处理的方式,需要在页面中判断是否存在cookie才进行下一步的请求,容易造成cookie被伪造,容易暴露cookie解析规则,安全性低;另外,该方式的登录配置灵活性差,在测试环境和线下环境需要经常修改登录配置,如果修改错误会导致上线失败。(2) In the method of login processing from the client, it is necessary to determine whether there is a cookie in the page before proceeding with the next request, which is easy to cause the cookie to be forged, and the cookie parsing rules are easily exposed, and the security is low; in addition, the login configuration of this method is The flexibility is poor. In the test environment and offline environment, the login configuration needs to be modified frequently. If the modification is wrong, the online failure will be caused.
发明内容SUMMARY OF THE INVENTION
有鉴于此,本发明实施例提供一种登录方法和装置,客户端拦截请求消息和对应的响应消息后,基于设定的登录判断规则和响应消息,判定用户未登录时,从响应消息中获取登录地址信息,进而完成登录。本发明实施例实现了一种灵活的登录方式,客户端只需进行登录拦截,无需关心使用哪个地址登录。In view of this, an embodiment of the present invention provides a login method and device. After the client intercepts the request message and the corresponding response message, based on the set login judgment rule and the response message, when it is determined that the user is not logged in, it obtains from the response message. Login address information, and then complete the login. The embodiment of the present invention implements a flexible login method, and the client only needs to perform login interception, and does not need to care which address is used to log in.
为实现上述目的,根据本发明实施例的一个方面,提供了一种登录方法。To achieve the above object, according to an aspect of the embodiments of the present invention, a login method is provided.
本发明实施例的一种登录方法,包括:拦截请求消息以及与所述请求消息相对应的响应消息;根据预定义的登录判断规则,以及所述响应消息中的状态码,判断用户是否登录;其中,所述登录判断规则中设置有状态码和所述状态码代表的含义;在所述用户未登录的情况下,从所述响应消息中获取登录地址信息,以基于所述登录地址信息进行登录。A login method according to an embodiment of the present invention includes: intercepting a request message and a response message corresponding to the request message; judging whether a user is logged in according to a predefined login judgment rule and a status code in the response message; Wherein, the login judgment rule is set with a status code and the meaning represented by the status code; in the case that the user is not logged in, the login address information is obtained from the response message, so as to perform a processing based on the login address information. Log in.
可选地,所述方法还包括:将所述请求消息封装为公共请求类;分别定义与服务端接口相对应的方法,根据所述服务端接口的请求类型,将所述服务端接口的地址信息封装到所述方法中;将封装结果传递到所述公共请求类,并输出所述方法的方法名称。Optionally, the method further includes: encapsulating the request message into a common request class; respectively defining a method corresponding to the server interface, and converting the address of the server interface according to the request type of the server interface. Information is encapsulated into the method; the encapsulation result is passed to the public request class, and the method name of the method is output.
可选地,所述将所述请求消息封装为公共请求类,包括:创建实例对象,输出所述实例对象;使用请求拦截器拦截所述请求消息,在所述请求消息中增加公共的头部信息;使用响应拦截器拦截与所述请求消息相对应的响应消息,对所述响应消息进行处理。Optionally, the encapsulating the request message into a common request class includes: creating an instance object, and outputting the instance object; intercepting the request message with a request interceptor, and adding a public header to the request message information; use a response interceptor to intercept the response message corresponding to the request message, and process the response message.
可选地,所述基于所述登录地址信息进行登录,包括:将所述登录地址信息和所述请求信息对应的当前地址信息进行拼接,按照拼接后的地址信息进行跳转登录。Optionally, the logging in based on the login address information includes: splicing the login address information and the current address information corresponding to the request information, and performing jump login according to the spliced address information.
可选地,所述从所述响应消息中获取登录地址信息,包括:从所述响应消息的头部信息中获取登录地址信息;其中,所述头部信息中包括由服务端提供的所述登录地址信息。Optionally, the obtaining the login address information from the response message includes: obtaining the login address information from header information of the response message; wherein the header information includes the information provided by the server Login address information.
为实现上述目的,根据本发明实施例的另一方面,提供了一种登录装置。To achieve the above object, according to another aspect of the embodiments of the present invention, a login apparatus is provided.
本发明实施例的一种登录装置,包括:拦截模块,用于拦截请求消息以及与所述请求消息相对应的响应消息;判断模块,用于根据预定义的登录判断规则,以及所述响应消息中的状态码,判断用户是否登录;其中,所述登录判断规则中设置有状态码和所述状态码代表的含义;登录模块,用于在所述用户未登录的情况下,从所述响应消息中获取登录地址信息,以基于所述登录地址信息进行登录。A login device according to an embodiment of the present invention includes: an interception module for intercepting a request message and a response message corresponding to the request message; a judgment module for judging rules according to a predefined login and the response message The status code in the log is used to judge whether the user is logged in; wherein, the log-in judgment rule is set with the status code and the meaning represented by the status code; the log-in module is used to log in from the response when the user is not logged in. The login address information is obtained from the message, so as to log in based on the login address information.
可选地,所述装置还包括:封装模块,用于将所述请求消息封装为公共请求类;分别定义与服务端接口相对应的方法,根据所述服务端接口的请求类型,将所述服务端接口的地址信息封装到所述方法中;以及将封装结果传递到所述公共请求类,并输出所述方法的方法名称。Optionally, the device further includes: an encapsulation module, configured to encapsulate the request message into a common request class; respectively define methods corresponding to the server interface, and according to the request type of the server interface, The address information of the server interface is encapsulated into the method; and the encapsulation result is passed to the public request class, and the method name of the method is output.
可选地,所述封装模块,还用于:创建实例对象,输出所述实例对象;使用请求拦截器拦截所述请求消息,在所述请求消息中增加公共的头部信息;使用响应拦截器拦截与所述请求消息相对应的响应消息,对所述响应消息进行处理。Optionally, the encapsulation module is further configured to: create an instance object and output the instance object; use a request interceptor to intercept the request message, and add common header information to the request message; use a response interceptor The response message corresponding to the request message is intercepted, and the response message is processed.
可选地,所述登录模块,还用于:将所述登录地址信息和所述请求信息对应的当前地址信息进行拼接,按照拼接后的地址信息进行跳转登录。Optionally, the login module is further configured to: splicing the login address information and the current address information corresponding to the request information, and performing jump login according to the spliced address information.
可选地,所述判断模块,还用于:从所述响应消息的头部信息中获取登录地址信息;其中,所述头部信息中包括由服务端提供的所述登录地址信息。Optionally, the judging module is further configured to: obtain login address information from header information of the response message; wherein the header information includes the login address information provided by the server.
为实现上述目的,根据本发明实施例的再一方面,提供了一种电子设备。To achieve the above object, according to yet another aspect of the embodiments of the present invention, an electronic device is provided.
本发明实施例的一种电子设备,包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现本发明实施例的一种登录方法。An electronic device according to an embodiment of the present invention includes: one or more processors; and a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, The one or more processors are caused to implement a login method according to an embodiment of the present invention.
为实现上述目的,根据本发明实施例的再一方面,提供了一种计算机可读介质。To achieve the above object, according to yet another aspect of the embodiments of the present invention, a computer-readable medium is provided.
本发明实施例的一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现本发明实施例的一种登录方法。A computer-readable medium of an embodiment of the present invention stores a computer program thereon, and when the program is executed by a processor, implements a login method of the embodiment of the present invention.
上述发明中的一个实施例具有如下优点或有益效果:客户端拦截请求消息和对应的响应消息后,基于设定的登录判断规则和响应消息判定用户未登录时,从响应消息中获取登录地址信息,进而完成登录,实现了一种灵活的登录方式,客户端只需进行登录拦截,无需关心使用哪个地址登录;通过统一的登录判断规则,结合状态码进行登录判断,无需判断cookie是否存在,防止了cookie伪造等问题,进一步提高了客户端的灵活性;通过二次封装的方式,将请求消息统一封装成公共请求类,将服务端接口统一封装成客户端API,实现了对请求消息和响应消息的统一处理,减少了重复代码工作量,轻松实现登录拦截。One embodiment of the above invention has the following advantages or beneficial effects: after the client intercepts the request message and the corresponding response message, when it is determined that the user is not logged in based on the set login judgment rule and the response message, the login address information is obtained from the response message. , and then complete the login, realizing a flexible login method. The client only needs to perform login interception, and does not need to care which address is used to log in; through the unified login judgment rule, combined with the status code, the login judgment is performed without judging whether the cookie exists, preventing It solves problems such as cookie forgery, and further improves the flexibility of the client; through the secondary encapsulation method, the request message is uniformly encapsulated into a common request class, and the server interface is uniformly encapsulated into a client API, which realizes the request message and response message. The unified processing reduces the workload of repetitive code and easily realizes login interception.
上述的非惯用的可选方式所具有的进一步效果将在下文中结合具体实施方式加以说明。Further effects of the above non-conventional alternatives will be described below in conjunction with specific embodiments.
附图说明Description of drawings
附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used for better understanding of the present invention and do not constitute an improper limitation of the present invention. in:
图1是根据本发明实施例的登录方法的主要步骤的示意图;1 is a schematic diagram of the main steps of a login method according to an embodiment of the present invention;
图2是根据本发明实施例的登录方法的主要原理示意图;2 is a schematic diagram of the main principle of a login method according to an embodiment of the present invention;
图3是根据本发明实施例的登录方法的主要流程示意图;3 is a schematic flow chart of a login method according to an embodiment of the present invention;
图4是根据本发明实施例的登录装置的主要模块的示意图;FIG. 4 is a schematic diagram of main modules of a login device according to an embodiment of the present invention;
图5是本发明实施例可以应用于其中的示例性系统架构图;5 is an exemplary system architecture diagram to which an embodiment of the present invention may be applied;
图6是适用于来实现本发明实施例的电子设备的计算机装置的结构示意图。FIG. 6 is a schematic structural diagram of a computer apparatus suitable for implementing the electronic device according to the embodiment of the present invention.
具体实施方式Detailed ways
以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding and should be considered as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted from the following description for clarity and conciseness.
下面对本发明实施例中涉及到的术语进行解释说明。The terms involved in the embodiments of the present invention are explained below.
前端:与用户进行直接交互的网页或者界面,是客户端的一种。Front-end: A web page or interface that directly interacts with users, which is a type of client.
客户端:可以向服务端发起请求的一方,比如一款APP(Application)。Client: A party that can initiate a request to the server, such as an APP (Application).
后端或者服务端:能够响应客户端请求的一方,比如云服务器。Backend or server: A party that can respond to client requests, such as a cloud server.
Vue:是一套用于构建用户界面的渐进式框架。与其它大型框架不同的是,Vue被设计为可以自底向上逐层应用。Vue: is a progressive framework for building user interfaces. Unlike other large frameworks, Vue is designed to be applied layer by layer from the bottom up.
React:是Facebook推出的一个用来构建用户界面的JavaScript库。React: is a JavaScript library launched by Facebook for building user interfaces.
JavaScript:是一种直译式脚本语言,缩写JS,是一种动态类型、弱类型、基于原型的语言,内置支持类型。JavaScript: is a literal scripting language, abbreviated JS, is a dynamically typed, weakly typed, prototype-based language with built-in support for types.
cookie:是指某些网站为了辨别用户身份、进行会话跟踪而储存在用户本地终端上的数据。Cookie: refers to the data stored on the user's local terminal by some websites in order to identify the user's identity and track the session.
ajax:即Asynchronous Javascript And XML(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术。Ajax: Asynchronous Javascript And XML (Asynchronous JavaScript and XML), refers to a web development technology for creating interactive web applications.
XML:即Extensible Markup Language(可扩展标记语言),是一种用于标记电子文件,使其具有结构性的标记语言。XML: Extensible Markup Language (Extensible Markup Language), is a markup language used to mark electronic documents to make them structured.
axios:是一个基于promise(承诺),可以用于浏览器和node.js(是一个Javascript运行环境)中http客户端,能够完成ajax异步请求。axios: is a promise-based http client that can be used in browsers and node.js (which is a Javascript runtime environment), and can complete ajax asynchronous requests.
url:即Uniform Resource Locator(统一资源定位符),是互联网上标准资源的地址。url: Uniform Resource Locator (Uniform Resource Locator), is the address of standard resources on the Internet.
图1是根据本发明实施例的登录方法的主要步骤的示意图。如图1所示,本发明实施例的登录方法,主要包括如下步骤:FIG. 1 is a schematic diagram of main steps of a login method according to an embodiment of the present invention. As shown in FIG. 1, the login method of the embodiment of the present invention mainly includes the following steps:
步骤S101:拦截请求消息以及与所述请求消息相对应的响应消息。预先将请求消息封装为公共请求类,具体为:在该公共请求类中创建实例对象;使用请求拦截器拦截客户端发送的至少一个请求消息,对请求消息进行统一处理;使用响应拦截器拦截服务端返回的与请求消息相对应的响应消息,对响应消息进行统一处理。后续客户端即可通过调用请求拦截器拦截请求消息,通过响应拦截器拦截响应消息。Step S101: Intercept the request message and the response message corresponding to the request message. The request message is encapsulated into a common request class in advance, specifically: creating an instance object in the common request class; using a request interceptor to intercept at least one request message sent by the client, and processing the request message uniformly; using a response interceptor to intercept the service The response message corresponding to the request message returned by the terminal, and the response message is processed uniformly. Subsequent clients can intercept the request message by calling the request interceptor, and intercept the response message by using the response interceptor.
步骤S102:根据预定义的登录判断规则以及所述响应消息中的状态码,判断用户是否登录。客户端和服务端统一登录判断规则,该规则中设置有状态码和各状态码对应的含义,比如定义状态码401,代表用户未登录。服务端在用户未登录的情况下,在响应消息的头部信息中增加登录地址信息;客户端在拦截到响应消息后,即可根据登录判断规则和响应消息中的状态码,判定用户是否登录。Step S102: According to the predefined login determination rule and the status code in the response message, determine whether the user is logged in. The client and the server have unified login judgment rules. The rules are set with status codes and the meanings corresponding to each status code. For example, the
步骤S103:在所述用户未登录的情况下,从所述响应消息中获取登录地址信息,以基于所述登录地址信息进行登录。预先将服务端请求的接口进行封装,具体为:分别定义与服务端接口相对应的方法,根据服务端接口的请求类型,将服务端接口的地址信息封装到方法中;将封装结果传递到公共请求类,输出方法的方法名称。后续如果客户端判定用户未登录,且已经获取了登录地址信息后,客户端即可以通过方法名称调用相应方法,以将登录地址信息和用户当前访问的地址栏的地址信息进行拼接,之后按照拼接后的地址信息进行跳转登录。Step S103: in the case that the user is not logged in, obtain login address information from the response message, so as to log in based on the login address information. Encapsulate the interface requested by the server in advance, specifically: define the methods corresponding to the server interface respectively, encapsulate the address information of the server interface into the method according to the request type of the server interface; pass the encapsulation result to the public Request class, the method name of the output method. Subsequently, if the client determines that the user is not logged in and has obtained the login address information, the client can call the corresponding method through the method name to splicing the login address information and the address information of the address bar currently accessed by the user, and then follow the splicing method. The following address information is used for jump login.
图2是根据本发明实施例的登录方法的主要原理示意图。如图2所示,为了实现本发明目的,客户端(实施例中为前端)进行了多层处理,包括页面视图(view)层、公共处理层、应用程序接口层。FIG. 2 is a schematic diagram of the main principle of a login method according to an embodiment of the present invention. As shown in FIG. 2 , in order to achieve the purpose of the present invention, the client (the front end in the embodiment) performs multi-layer processing, including a page view layer, a common processing layer, and an application program interface layer.
页面视图层,包含所有的请求消息,该层用于发送页面的请求消息,以及进行页面渲染。The page view layer contains all request messages. This layer is used to send page request messages and perform page rendering.
公共处理层,包含了自定义的request请求,实施例中为requestJS,该层用于使用请求拦截器拦截请求消息,汇总并统一处理页面所有的请求消息后,输出至应用程序接口层;使用响应拦截器拦截来自应用程序接口层的响应消息,汇总并统一处理所有的响应消息。实施例中采用二次封装的方式,实现对所有消息的统一处理。The public processing layer includes a custom request request, which is requestJS in the embodiment. This layer is used to intercept the request message by using a request interceptor, summarize and uniformly process all the request messages of the page, and output it to the application program interface layer; use the response The interceptor intercepts the response messages from the API layer, and aggregates and processes all the response messages uniformly. In the embodiment, the method of secondary encapsulation is adopted to realize unified processing of all messages.
应用程序接口层,用于封装所有的服务端接口,并给页面视图层暴露一个方法名。这样做的好处是可以对服务端所有的接口进行统一管理,如果服务端接口的url变动,则只需更改该层对应的文件属性即可,不用大面积的更改页面的请求消息,减少客户端重复请求及重复代码。应用程序接口层还用于在接收到请求消息后,通过相应接口将请求消息发送至当前与客户端建立有http连接的服务端;该接口在接收到来自服务端的对于该请求消息的响应消息后,将其发送至响应拦截器。The application interface layer is used to encapsulate all server-side interfaces and expose a method name to the page view layer. The advantage of this is that all interfaces on the server can be managed in a unified manner. If the url of the server interface changes, you only need to change the file attributes corresponding to this layer, instead of changing the request message of the page in a large area, reducing the number of clients. Duplicate requests and duplicate codes. The application program interface layer is also used to send the request message to the server that currently has an http connection with the client through the corresponding interface after receiving the request message; after the interface receives the response message from the server to the request message , which is sent to the response interceptor.
图3是根据本发明实施例的登录方法的主要流程示意图。如图3所示,本发明实施例的登录方法,主要包括如下步骤:FIG. 3 is a schematic flowchart of a main flow of a login method according to an embodiment of the present invention. As shown in FIG. 3 , the login method according to the embodiment of the present invention mainly includes the following steps:
步骤S301:公共处理层将来自于目标页面的所有对于服务端数据的请求消息封装成公共请求类。实施例中以Vue工程的单页面为例,客户端和服务端的所有信息交互均是axios请求消息,将axios请求消息封装为公共请求类(requestJS)的具体实现为:(1)创建一个axios实例对象,该实例对象名称为axiosService,之后输出(export)该实例对象;(2)利用interceptors.request.use方法(即请求拦截器)实现对所有axios请求消息的拦截,并对拦截到的axios请求消息进行处理;此处的处理可以是增加公共的头部信息,比如token(令牌)、时间戳等;(3)利用interceptors.response.use方法(即响应拦截器)拦截服务端返回的与axios请求消息相对应的响应消息,对响应消息进行统一处理。Step S301: The common processing layer encapsulates all request messages for server-side data from the target page into a common request class. In the embodiment, taking the single page of the Vue project as an example, all the information exchanges between the client and the server are axios request messages. The specific implementation of encapsulating the axios request message into a common request class (requestJS) is as follows: (1) Create an axios instance object, the name of the instance object is axiosService, and then export (export) the instance object; (2) use the interceptors.request.use method (ie request interceptor) to intercept all axios request messages, and intercept the intercepted axios requests The message is processed; the processing here can be to add public header information, such as token (token), timestamp, etc.; (3) use the interceptors.response.use method (ie, the response interceptor) to intercept the and return from the server. The response message corresponding to the axios request message is processed uniformly.
实施例中,对响应消息的统一处理主要包括:In the embodiment, the unified processing of the response message mainly includes:
(1)将响应消息的头部信息(headers)中applicationprofile属性数据对应的值存在客户端缓存中。(1) Store the value corresponding to the applicationprofile attribute data in the header information (headers) of the response message in the client cache.
(2)对响应消息的headers中content-type(内容类型)的值为application/properties的数据进行特殊处理,即直接返回给页面调用程序,这里返回一个promise对象。(2) Special processing is performed on the data whose content-type (content type) value in the headers of the response message is application/properties, that is, directly returned to the page calling program, where a promise object is returned.
(3)对其他数据:判断状态码(code)是否等于200,如果等于200,则将数据中的data值返回给页面调用程序;如果不等于200,则将数据中的message返回给页面调用程序,这里返回一个promise对象。(3) For other data: judge whether the status code (code) is equal to 200, if it is equal to 200, return the data value in the data to the page calling program; if it is not equal to 200, return the message in the data to the page calling program , which returns a promise object.
(4)对错误数据的处理:如果code等于401,则尝试获取header中location字段里的跳转路径(该路径为登录地址信息,该登录地址信息可以是登录页面或者登录窗口的url),以进行跳转;如果code等于404,则跳转到错误(error)页面。(4) Handling of wrong data: If the code is equal to 401, try to obtain the jump path in the location field in the header (the path is the login address information, and the login address information can be the url of the login page or login window). Make a jump; if the code is equal to 404, jump to the error page.
步骤S302:应用程序接口层分别定义与至少一个服务端接口相对应的方法,根据服务端接口的请求类型,将服务端接口的地址信息封装到方法中。这里只是定义一个接口输入和输出的标准。实施例中,对于接口输入的标准可以只关心调用的方法名称,无需关心请求的url具体是什么,如果服务端接口的url一旦变更,只需要更改方法内部的url即可,不必去更改每个页面的axios请求消息,大大减少了代码重复量。对于接口输入的标准可以是统一输出一个promise对象。Step S302: The application program interface layer respectively defines a method corresponding to at least one server interface, and encapsulates the address information of the server interface into the method according to the request type of the server interface. Here is just to define a standard for the input and output of an interface. In the embodiment, for the interface input standard, you can only care about the name of the method to be called, and do not need to care about the specific url of the request. If the url of the server interface is changed, you only need to change the url inside the method, and you do not need to change each url. The axios request message of the page greatly reduces the amount of code duplication. The standard for interface input can be to output a promise object uniformly.
下面对如何定义与服务端接口相对应的方法进行举例说明:The following is an example of how to define the method corresponding to the server interface:
比如,服务端接口为:v1/application/appIdFor example, the server interface is: v1/application/appId
客户端封装的接口为:The interface encapsulated by the client is:
export function getApp(appId){export function getApp(appId){
return request({return request({
url:baseUrl+'v1/application/'+appId,url:baseUrl+'v1/application/'+appId,
method:'get'method:'get'
})})
}}
再比如,服务端接口为:v1/applications/searchFor another example, the server interface is: v1/applications/search
客户端封装的接口为:The interface encapsulated by the client is:
export function searchApps(params){export function searchApps(params){
let url=baseUrl+'v1/applications/search?'let url=baseUrl+'v1/applications/search? '
for(let key in params){for(let key in params){
url+=key+"="+params[key]+"&"url+=key+"="+params[key]+"&"
}}
url=url.substring(0,url.length-1);url=url.substring(0,url.length-1);
return request({return request({
url:url,url: url,
method:'get'method:'get'
})})
}}
下面对如何根据服务端接口的请求类型,将服务端接口的地址信息封装到方法中进行举例说明:The following is an example of how to encapsulate the address information of the server interface into the method according to the request type of the server interface:
比如,对于get类型的请求,拼接对应的url,并在url后面拼接传入的参数。假设传入的参数为对象{a:1,b:2},封装时会将传入的参数与服务端的url结合起来处理成如下格式:http://xxx.jd.com/v1/xx/ge t?a=1&b=2。For example, for a get type request, the corresponding url is spliced, and the incoming parameters are spliced after the url. Assuming that the incoming parameters are objects {a:1, b:2}, the incoming parameters will be combined with the url of the server and processed into the following format during encapsulation: http://xxx.jd.com/v1/xx/ get? a=1&b=2.
再比如,对于post、delete、put类型的请求,传入的参数是放在数据(data)中的,故只需拼接对应的url即可,不对传入的参数做特殊处理。例如delete:http://xxx.jd.com/v1/xx/delete/:id,id就是传入的参数。For another example, for post, delete, and put type requests, the incoming parameters are placed in the data (data), so it is only necessary to splicing the corresponding url, and no special processing is performed for the incoming parameters. For example, delete: http://xxx.jd.com/v1/xx/delete/:id, where id is the incoming parameter.
步骤S303:应用程序接口层将封装结果传递到公共请求类,并输出方法的方法名称。应用程序接口层对于Vue页面只暴露一个方法名称,比如getApp、searchApps,Vue页面调用的时候,只需要按照要求传入参数,即可输出promise对象。实施例中,应用程序接口层将处理好的url、参数、其他需要处理的头部信息等传递给requestJS,并输出(export)这些方法名称,以将这些方法名称提供给页面视图层,使得页面视图层能够直接调用这些方法。Step S303: The application program interface layer transfers the encapsulation result to the public request class, and outputs the method name of the method. The application interface layer only exposes one method name for the Vue page, such as getApp and searchApps. When the Vue page is called, you only need to pass in the parameters as required to output the promise object. In the embodiment, the application program interface layer passes the processed url, parameters, and other header information that needs to be processed to requestJS, and outputs (export) these method names, so as to provide these method names to the page view layer, so that the page The view layer can call these methods directly.
步骤S304:页面视图层调用应用程序接口层的方法名称,以通过公共处理层拦截来自于目标页面的所有请求消息,以及服务端返回的与请求消息相对应的响应消息。服务端在接收到客户端发送的请求消息后,会返回对应的响应消息。公共处理层通过请求拦截器拦截来自于目标页面的所有请求消息,通过响应拦截器拦截服务端返回的与请求消息相对应的响应消息。实施例中,公共处理层在拦截到请求消息后,基于预先建立的http连接获取到与请求消息相匹配的响应消息。Step S304: The page view layer invokes the method name of the application program interface layer to intercept all request messages from the target page through the common processing layer, and the response messages corresponding to the request messages returned by the server. After receiving the request message sent by the client, the server will return the corresponding response message. The public processing layer intercepts all request messages from the target page through the request interceptor, and intercepts the response message corresponding to the request message returned by the server through the response interceptor. In the embodiment, after intercepting the request message, the public processing layer obtains a response message matching the request message based on the pre-established http connection.
步骤S305:公共处理层根据预定义的登录判断规则以及响应消息中的状态码,判断用户是否登录该目标页面,如果用户已登录该目标页面,则执行步骤S306;如果用户未登录该目标页面,则执行步骤S307。由于页面是通过Vue渲染的,而非是服务端渲染,在判断用户是否登录该目标页面时,现有技术中会采用cookie的方式,但是此方式容易造成恶意的cookie伪造攻击。本实施例中通过客户端与服务端合作的方式,即通过统一登录判断规则的方式来判断用户是否登录该目标页面,该规则中指定了表示用户未登录目标页面时对应的状态码。如果用户未登录该目标页面,服务端会返回该特定的状态码以及相应登录页面或登录窗口的url,客户端即可无需关心用户去哪个页面登录的问题。比如,客户端与服务端预先规定,当状态码为401时,表示用户未登录,这时,响应消息的头部信息中必然包含location字段,该字段用于存储登录页面或登录窗口的url(由服务端定义并存储,以便随时更换不同的环境及系统);状态码为其他值时,相应表示其他含义。Step S305: The public processing layer judges whether the user has logged in to the target page according to the predefined login judgment rule and the status code in the response message. If the user has logged in to the target page, step S306 is executed; Then step S307 is executed. Since the page is rendered by Vue, rather than the server-side rendering, when judging whether the user logs in to the target page, a cookie method is used in the prior art, but this method is prone to malicious cookie forgery attacks. In this embodiment, whether the user logs in to the target page is judged by means of the cooperation between the client and the server, that is, through a unified login judgment rule. The rule specifies a corresponding status code indicating that the user does not log in to the target page. If the user does not log in to the target page, the server will return the specific status code and the url of the corresponding login page or login window, and the client does not need to care which page the user goes to log in. For example, the client and server pre-specify that when the status code is 401, it means that the user is not logged in. At this time, the header information of the response message must contain the location field, which is used to store the url of the login page or login window ( It is defined and stored by the server so that different environments and systems can be changed at any time); when the status code is other values, it means other meanings accordingly.
步骤S306:页面视图层对该目标页面进行页面渲染,以显示页面内容。Step S306: The page view layer performs page rendering on the target page to display page content.
步骤S307:公共处理层从响应消息中获取登录地址信息,将登录地址信息和目标页面的地址信息进行拼接,以按照拼接后的地址信息跳转到登录页面或登录窗口。如果状态码为401,表示用户未登录该目标页面,需要客户端跳转到登录页面或登录窗口。由于服务端有测试、开发、线上三套系统,各个系统的登录页面或登录窗口的网址不同,所以客户端需要从服务端给的header获取,这样能极大的提高客户端的灵活性。实施例中,公共处理层从响应消息的header中包含的location字段中获取登录页面或登录窗口的url。目标页面的地址信息即用户当前访问的页面地址栏的url。实施例中,将两个地址信息拼接的过程可以为:const returnUrl=errorresponse.headers.location+"?ReturnUrl="+nowUrl;其中,location字段的信息即登录页面的url,比如为:http://xxx.jd.com;nowUrl是通过JS获取的用户当前访问的页面地址栏的url,比如为:http://abc.jd.com;则拼接完成后得到的url为:http://xxx.jd.com?ReturnUrl=http://abc.jd.com。之后,按照该拼接后的地址,利用客户端的location.href方法,即可完成由用户当前访问的目标页面到登录页面或登录窗口的跳转。Step S307: The public processing layer obtains the login address information from the response message, and splices the login address information and the address information of the target page to jump to the login page or login window according to the spliced address information. If the status code is 401, it means that the user has not logged in to the target page, and the client needs to jump to the login page or login window. Since the server has three systems of testing, development, and online, the login page or the URL of the login window of each system is different, so the client needs to obtain it from the header given by the server, which can greatly improve the flexibility of the client. In the embodiment, the public processing layer obtains the url of the login page or the login window from the location field included in the header of the response message. The address information of the target page is the url of the address bar of the page currently accessed by the user. In an embodiment, the process of splicing two address information may be: const returnUrl=errorresponse.headers.location+"?ReturnUrl="+nowUrl; wherein, the information in the location field is the url of the login page, such as: http:// xxx.jd.com; nowUrl is the url of the address bar of the page currently accessed by the user obtained through JS, for example: http://abc.jd.com; then the url obtained after splicing is: http://xxx. jd.com? ReturnUrl=http://abc.jd.com. After that, according to the spliced address, using the location.href method of the client, the jump from the target page currently accessed by the user to the login page or login window can be completed.
通过本发明实施例的登录方法可以看出,客户端拦截请求消息和对应的响应消息后,基于设定的登录判断规则和响应消息判定用户未登录时,从响应消息中获取登录地址信息,进而完成登录,实现了一种灵活的登录方式,客户端只需进行登录拦截,无需关心使用哪个地址登录;通过统一的登录判断规则,结合状态码进行登录判断,无需判断cookie是否存在,防止了cookie伪造等问题,进一步提高了客户端的灵活性;通过二次封装的方式,将请求消息统一封装成公共请求类,将服务端接口统一封装成客户端API,实现了对请求消息和响应消息的统一处理,减少了重复代码工作量,轻松实现登录拦截。It can be seen from the login method of the embodiment of the present invention that, after intercepting the request message and the corresponding response message, the client obtains the login address information from the response message when it determines that the user is not logged in based on the set login judgment rule and the response message, and then obtains the login address information from the response message. After completing the login, a flexible login method is realized. The client only needs to intercept the login, and does not need to care which address is used to log in. Through the unified login judgment rules, combined with the status code, the login judgment is performed, and there is no need to judge whether the cookie exists, which prevents the cookie. Forgery and other problems further improve the flexibility of the client; through the method of secondary encapsulation, the request message is uniformly encapsulated into a common request class, and the server interface is uniformly encapsulated into a client API, which realizes the unification of request messages and response messages. processing, reducing the workload of repetitive code, and easily implement login interception.
图4是根据本发明实施例的登录装置的主要模块的示意图。如图4所示,本发明实施例的登录装置400,主要包括:FIG. 4 is a schematic diagram of main modules of a login device according to an embodiment of the present invention. As shown in FIG. 4 , the
拦截模块401,用于拦截请求消息以及与所述请求消息相对应的响应消息。预先将请求消息封装为公共请求类,具体为:在该公共请求类中创建实例对象;使用请求拦截器拦截客户端发送的至少一个请求消息,对请求消息进行统一处理;使用响应拦截器拦截服务端返回的与请求消息相对应的响应消息,对响应消息进行统一处理。后续客户端即可通过调用请求拦截器拦截请求消息,通过响应拦截器拦截响应消息。The
判断模块402,用于根据预定义的登录判断规则以及所述响应消息中的状态码,判断用户是否登录。客户端和服务端统一登录判断规则,该规则中设置有状态码和各状态码对应的含义,比如定义状态码401,代表用户未登录。服务端在用户未登录的情况下,在响应消息的头部信息中增加登录地址信息;客户端在拦截到响应消息后,即可根据登录判断规则和响应消息中的状态码,判定用户是否登录。The judging
登录模块403,用于在所述用户未登录的情况下,从所述响应消息中获取登录地址信息,以基于所述登录地址信息进行登录。预先将服务端请求的接口进行封装,具体为:分别定义与服务端接口相对应的方法,根据服务端接口的请求类型,将服务端接口的地址信息封装到方法中;将封装结果传递到公共请求类,输出方法的方法名称。后续如果客户端判定用户未登录,且已经获取了登录地址信息后,客户端即可以通过方法名称调用相应方法,以将登录地址信息和用户当前访问的地址栏的地址信息进行拼接,之后按照拼接后的地址信息进行跳转登录。The
另外,本发明实施例的登录装置400还可以包括:封装模块(图4中未示出),该模块用于将所述请求消息封装为公共请求类;分别定义与服务端接口相对应的方法,根据所述服务端接口的请求类型,将所述服务端接口的地址信息封装到所述方法中;以及将封装结果传递到所述公共请求类,并输出所述方法的方法名称。In addition, the
从以上描述可以看出,客户端拦截请求消息和对应的响应消息后,基于设定的登录判断规则和响应消息判定用户未登录时,从响应消息中获取登录地址信息,进而完成登录,实现了一种灵活的登录方式,客户端只需进行登录拦截,无需关心使用哪个地址登录;通过统一的登录判断规则,结合状态码进行登录判断,无需判断cookie是否存在,防止了cookie伪造等问题,进一步提高了客户端的灵活性;通过二次封装的方式,将请求消息统一封装成公共请求类,将服务端接口统一封装成客户端API,实现了对请求消息和响应消息的统一处理,减少了重复代码工作量,轻松实现登录拦截。As can be seen from the above description, after the client intercepts the request message and the corresponding response message, and determines that the user is not logged in based on the set login judgment rules and response message, it obtains the login address information from the response message, and then completes the login. A flexible login method, the client only needs to perform login interception, and does not need to care which address is used to log in; through unified login judgment rules, combined with the status code for login judgment, there is no need to judge whether a cookie exists, preventing cookie forgery and other problems, and further Improve the flexibility of the client; through the secondary encapsulation method, the request message is uniformly encapsulated into a common request class, and the server interface is uniformly encapsulated into a client API, which realizes the unified processing of request messages and response messages, and reduces duplication. Code workload, easy to achieve login interception.
图5示出了可以应用本发明实施例的登录方法或登录装置的示例性系统架构500。FIG. 5 shows an
如图5所示,系统架构500可以包括终端设备501、502、503,网络504和服务器505。网络504用以在终端设备501、502、503和服务器505之间提供通信链路的介质。网络504可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 5 , the
用户可以使用终端设备501、502、503通过网络504与服务器505交互,以接收或发送消息等。终端设备501、502、503上可以安装有各种通讯客户端应用,例如购物类应用、网页浏览器应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等。The user can use the
终端设备501、502、503可以是具有显示屏并且支持网页浏览的各种电子设备,包括但不限于智能手机、平板电脑、膝上型便携计算机和台式计算机等等。The
服务器505可以是提供各种服务的服务器,例如对用户利用终端设备501、502、503所发送的请求消息提供响应的后台管理服务器。后台管理服务器可以对接收到的请求信息进行分析等处理,并将处理结果(例如响应信息)反馈给终端设备。The
需要说明的是,本申请实施例所提供的登录方法一般由终端设备501、502、503上的前端执行,相应地,登录装置一般设置于终端设备501、502、503上的前端中。It should be noted that the login methods provided in the embodiments of the present application are generally executed by the front ends on the
应该理解,图5中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。It should be understood that the numbers of terminal devices, networks and servers in FIG. 5 are only illustrative. There can be any number of terminal devices, networks and servers according to implementation needs.
根据本发明的实施例,本发明还提供了一种电子设备和一种计算机可读介质。According to an embodiment of the present invention, the present invention further provides an electronic device and a computer-readable medium.
本发明的电子设备包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现本发明实施例的一种登录方法。The electronic device of the present invention comprises: one or more processors; storage means for storing one or more programs, when the one or more programs are executed by the one or more processors, so that the one or more programs A plurality of processors implement a login method according to an embodiment of the present invention.
本发明的计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现本发明实施例的一种登录方法。The computer-readable medium of the present invention stores a computer program thereon, and when the program is executed by a processor, a login method according to an embodiment of the present invention is implemented.
下面参考图6,其示出了适用于来实现本发明实施例的电子设备的计算机系统600的结构示意图。图6示出的电子设备仅仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。Referring to FIG. 6 below, it shows a schematic structural diagram of a
如图6所示,计算机系统600包括中央处理单元(CPU)601,其可以根据存储在只读存储器(ROM)602中的程序或者从存储部分608加载到随机访问存储器(RAM)603中的程序而执行各种适当的动作和处理。在RAM 603中,还存储有计算机系统600操作所需的各种程序和数据。CPU 601、ROM 602以及RAM 603通过总线604彼此相连。输入/输出(I/O)接口605也连接至总线604。As shown in FIG. 6, a
以下部件连接至I/O接口605:包括键盘、鼠标等的输入部分606;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分607;包括硬盘等的存储部分608;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分609。通信部分609经由诸如因特网的网络执行通信处理。驱动器610也根据需要连接至I/O接口605。可拆卸介质611,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器610上,以便于从其上读出的计算机程序根据需要被安装入存储部分608。The following components are connected to the I/O interface 605: an
特别地,根据本发明公开的实施例,上文主要步骤图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行主要步骤图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分609从网络上被下载和安装,和/或从可拆卸介质611被安装。在该计算机程序被中央处理单元(CPU)601执行时,执行本发明的系统中限定的上述功能。In particular, according to the disclosed embodiments of the present invention, the processes described in the main step diagrams above may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods illustrated in the main step diagrams. In such an embodiment, the computer program may be downloaded and installed from the network via the
需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code therein. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device . Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
附图中的流程图和框图,图示了按照本发明各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more logical functions for implementing the specified functions executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented in special purpose hardware-based systems that perform the specified functions or operations, or can be implemented using A combination of dedicated hardware and computer instructions is implemented.
描述于本发明实施例中所涉及到的模块可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的模块也可以设置在处理器中,例如,可以描述为:一种处理器包括拦截模块、判断模块和登录模块。其中,这些模块的名称在某种情况下并不构成对该模块本身的限定,例如,拦截模块还可以被描述为“拦截请求消息以及与所述请求消息相对应的响应消息的模块”。The modules involved in the embodiments of the present invention may be implemented in a software manner, and may also be implemented in a hardware manner. The described module can also be set in the processor, for example, it can be described as: a processor includes an interception module, a judgment module and a login module. Wherein, the names of these modules do not constitute a limitation of the module itself under certain circumstances. For example, an interception module can also be described as "a module that intercepts request messages and response messages corresponding to the request messages".
作为另一方面,本发明还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的设备中所包含的;也可以是单独存在,而未装配入该设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该设备执行时,使得该设备包括:拦截请求消息以及与所述请求消息相对应的响应消息;根据预定义的登录判断规则,以及所述响应消息中的状态码,判断用户是否登录;其中,所述登录判断规则中设置有状态码和所述状态码代表的含义;在所述用户未登录的情况下,从所述响应消息中获取登录地址信息,以基于所述登录地址信息进行登录。As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or may exist alone without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by a device, the device includes: intercepting a request message and a response message corresponding to the request message; according to a predefined and the status code in the response message to determine whether the user is logged in; wherein, the login judgment rule is set with the status code and the meaning represented by the status code; in the case that the user is not logged in , and obtain login address information from the response message to log in based on the login address information.
从以上描述可以看出,客户端拦截请求消息和对应的响应消息后,基于设定的登录判断规则和响应消息判定用户未登录时,从响应消息中获取登录地址信息,进而完成登录,实现了一种灵活的登录方式,客户端只需进行登录拦截,无需关心使用哪个地址登录;通过统一的登录判断规则,结合状态码进行登录判断,无需判断cookie是否存在,防止了cookie伪造等问题,进一步提高了客户端的灵活性。As can be seen from the above description, after the client intercepts the request message and the corresponding response message, and determines that the user is not logged in based on the set login judgment rules and response message, it obtains the login address information from the response message, and then completes the login. A flexible login method, the client only needs to perform login interception, and does not need to care which address is used to log in; through unified login judgment rules, combined with the status code for login judgment, there is no need to judge whether a cookie exists, preventing cookie forgery and other problems, and further Improved client flexibility.
上述产品可执行本发明实施例所提供的方法,具备执行方法相应的功能模块和有益效果。未在本实施例中详尽描述的技术细节,可参见本发明实施例所提供的方法。The above product can execute the method provided by the embodiment of the present invention, and has corresponding functional modules and beneficial effects for executing the method. For technical details not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above-mentioned specific embodiments do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims (12)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910452009.9A CN112015383B (en) | 2019-05-28 | 2019-05-28 | A login method and device |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910452009.9A CN112015383B (en) | 2019-05-28 | 2019-05-28 | A login method and device |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN112015383A true CN112015383A (en) | 2020-12-01 |
| CN112015383B CN112015383B (en) | 2025-01-14 |
Family
ID=73501602
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910452009.9A Active CN112015383B (en) | 2019-05-28 | 2019-05-28 | A login method and device |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN112015383B (en) |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112905160A (en) * | 2021-02-08 | 2021-06-04 | 中国工商银行股份有限公司 | Axios-based package registration global interception method and device |
| CN114172896A (en) * | 2021-12-08 | 2022-03-11 | 深圳前海环融联易信息科技服务有限公司 | Processing method for front end receiving back end file stream |
| CN116112558A (en) * | 2022-11-21 | 2023-05-12 | 上海浦东发展银行股份有限公司 | Interface interception method and system based on axios |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104394133A (en) * | 2014-11-14 | 2015-03-04 | 百度在线网络技术(北京)有限公司 | Login method and login system |
| CN104468592A (en) * | 2014-12-12 | 2015-03-25 | 北京百度网讯科技有限公司 | Login method and system |
| CN105099678A (en) * | 2014-04-29 | 2015-11-25 | 北京奇虎科技有限公司 | Cloud disk login method based on external equipment and device and system thereof |
| JP2017134695A (en) * | 2016-01-29 | 2017-08-03 | 独立行政法人国立高等専門学校機構 | Response confirmation system, program, and server computer |
| CN107395614A (en) * | 2017-08-09 | 2017-11-24 | 深圳国泰安教育技术股份有限公司 | Single-point logging method and system |
-
2019
- 2019-05-28 CN CN201910452009.9A patent/CN112015383B/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105099678A (en) * | 2014-04-29 | 2015-11-25 | 北京奇虎科技有限公司 | Cloud disk login method based on external equipment and device and system thereof |
| CN104394133A (en) * | 2014-11-14 | 2015-03-04 | 百度在线网络技术(北京)有限公司 | Login method and login system |
| CN104468592A (en) * | 2014-12-12 | 2015-03-25 | 北京百度网讯科技有限公司 | Login method and system |
| JP2017134695A (en) * | 2016-01-29 | 2017-08-03 | 独立行政法人国立高等専門学校機構 | Response confirmation system, program, and server computer |
| CN107395614A (en) * | 2017-08-09 | 2017-11-24 | 深圳国泰安教育技术股份有限公司 | Single-point logging method and system |
Non-Patent Citations (1)
| Title |
|---|
| 阁下长得好生俊俏: "Vue+axios实现登陆拦截,axios封装(报错, 鉴权, 跳转, 拦截, 提示)", pages 2, Retrieved from the Internet <URL:https://blog.csdn.net/H1069495874/article/details/80057107> * |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112905160A (en) * | 2021-02-08 | 2021-06-04 | 中国工商银行股份有限公司 | Axios-based package registration global interception method and device |
| CN114172896A (en) * | 2021-12-08 | 2022-03-11 | 深圳前海环融联易信息科技服务有限公司 | Processing method for front end receiving back end file stream |
| CN116112558A (en) * | 2022-11-21 | 2023-05-12 | 上海浦东发展银行股份有限公司 | Interface interception method and system based on axios |
Also Published As
| Publication number | Publication date |
|---|---|
| CN112015383B (en) | 2025-01-14 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11546331B2 (en) | Credential and authentication management in scalable data networks | |
| US8843646B2 (en) | Multi-desktop interaction using nested remote desktop sessions | |
| US11811884B1 (en) | Topic subscription provisioning for communication protocol | |
| US10592399B2 (en) | Testing web applications using clusters | |
| CN108574604A (en) | test method and device | |
| CN110858202A (en) | Method and device for generating where clause in database query statement | |
| WO2020232698A1 (en) | Secure web application delivery platform | |
| CN113742235A (en) | A method and device for checking code | |
| JP2022546073A (en) | Connecting web publisher inventory to programmatic exchanges without third party cookies | |
| CN107635001A (en) | Web scripts abnormality eliminating method and device | |
| CN112131095A (en) | Pressure testing method and device | |
| CN112015383B (en) | A login method and device | |
| CN113595927A (en) | Method and device for processing mirror flow in bypass mode | |
| CN112052152A (en) | A method and device for simulating testing | |
| US9398041B2 (en) | Identifying stored vulnerabilities in a web service | |
| CN112149392A (en) | A rich text editing method and device | |
| CN112929453A (en) | Method and device for sharing session data | |
| AU2018390863B2 (en) | Computer system and method for extracting dynamic content from websites | |
| CN116561013B (en) | Test methods, devices, electronic equipment and media based on the target service framework | |
| US20210281629A1 (en) | Processing of web-based applications | |
| CN118972431A (en) | AI model request processing method, computer equipment, medium and product | |
| CN109981546A (en) | The method and apparatus for obtaining the far call relationship between application module | |
| CN117194068A (en) | Cross-process data transmission method, system, equipment and storage medium | |
| CN115840601A (en) | Task speed limiting method and device | |
| CN112306791B (en) | Performance monitoring method and device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |
