WO2016074568A1 - 生成条码的方法、装置及服务器 - Google Patents
生成条码的方法、装置及服务器 Download PDFInfo
- Publication number
- WO2016074568A1 WO2016074568A1 PCT/CN2015/093314 CN2015093314W WO2016074568A1 WO 2016074568 A1 WO2016074568 A1 WO 2016074568A1 CN 2015093314 W CN2015093314 W CN 2015093314W WO 2016074568 A1 WO2016074568 A1 WO 2016074568A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- string
- barcode
- server
- expression string
- webpage
- 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.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06K—GRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
- G06K19/00—Record carriers for use with machines and with at least a part designed to carry digital markings
- G06K19/06—Record carriers for use with machines and with at least a part designed to carry digital markings characterised by the kind of the digital marking, e.g. shape, nature, code
Definitions
- the present application relates to the field of communications technologies, and in particular, to a method for generating a barcode, a device for generating a barcode, and a server.
- a bar code that is, a bar code
- a bar code is a graphic identifier that expresses a set of information by arranging a plurality of black bars and spaces of unequal widths according to a certain encoding rule.
- Barcode technology has been widely used in the Internet and e-commerce fields. Since there are various terminals (such as a PC terminal, a mobile terminal, a handheld device such as a PAD, and a server device), and different platforms have different platforms, the usual method for generating a barcode in the prior art is It is implemented by the developer using different class libraries.
- the present application provides a method for generating a barcode, a device for generating a barcode, and a server, which can solve the problem of generating a barcode across terminals and at low cost.
- an apparatus for generating a barcode comprising:
- An expression string generating module configured to acquire a string to be processed to generate an expression string, where the expression string is used to represent a data value of a mapping relationship between the character string to be processed and the corresponding code system;
- a webpage-based pattern generation module is configured to draw the expression string into a barcode in a webpage.
- Another aspect of the present application provides a method of generating a barcode, the method comprising the steps of:
- the expression string is used to represent a data value of a mapping relationship between the to-be-processed character string and the corresponding code system;
- Another aspect of the present application is also a method of generating a barcode, the method comprising the steps of:
- the expression string is used to represent a data value of a mapping relationship between the to-be-processed character string and the corresponding code system;
- the language technology adopted by the server end is adapted to the running environment of the javascript
- the graphics library is a graphics library adapted to the Node environment. ;
- the application also provides an apparatus for generating a barcode by using a barcode generating device, the device comprising:
- An expression string generating module configured to acquire a string to be processed to generate an expression string, where the expression string is used to represent a data value of a mapping relationship between the character string to be processed and the corresponding code system;
- a webpage service module configured to invoke the expression string generation module, obtain the expression string, and transmit the expression string and corresponding page location information to the webpage technology-based pattern generation module;
- a webpage-based pattern generation module is configured to draw the expression string into a barcode at the page position.
- the application also provides a server for generating a barcode, the server comprising:
- An expression string generating module configured to acquire a string to be processed to generate an expression string, where the expression string is used to represent a data value of a mapping relationship between the character string to be processed and the corresponding code system;
- a server service module configured to invoke the expression string generation module, obtain the expression string, and transmit the expression string to a server-side image generation module, and send the barcode image to the client browser;
- a server-side image generation module configured to draw the expression string on a server side by using a graphics library
- the barcode technology is adapted to the running environment of the javascript
- the graphics library is a graphics library adapted to the Node environment.
- the application completely changes the bar code of the C/S technology in the prior art, and implements the bar code generation technology through the B/S mode.
- the device for generating the bar code provided by the application may be
- the terminal provides the same API (application programming interface, the user can call the framework API to implement more complex and rich applications), the user can implement the barcode generation by calling the device under different terminals, so that the user is different Based on this application, the code can be shared under different platforms, reducing the writing of duplicate code, and finally improving the maintainability of the product code, thereby minimizing maintenance and usage costs.
- FIG. 1 is a hardware framework diagram of a barcode generation module in the present application.
- FIG. 2 is a logic block diagram of a barcode generating apparatus in an embodiment of the present application.
- FIG. 3 is a flowchart of a method for implementing barcode generation in a webpage by a client by calling the apparatus of FIG. 1 according to an embodiment of the present application;
- FIG. 4 is a logic block diagram of an apparatus for implementing barcode generation in a webpage by calling the apparatus of FIG. 1 in an embodiment of the present application;
- FIG. 5 is a flowchart of a method for implementing barcode generation on a server side by using a device in FIG. 1 by a server in the embodiment of the present application;
- FIG. 6 is a logic block diagram of a server for implementing barcode generation in an embodiment of the present application.
- FIG. 7 is an effect diagram of generating an expression string of a character string to be processed in an application example of the present application
- FIG. 8 is a rendering diagram of generating a barcode in an application example of the present application.
- the present application provides a technical solution for generating barcodes for a variety of terminals, regardless of the platform used by the terminal and what operating system (Window, Mac, Unix, Linux, iOS, Android, etc.), or even various versions of various terminal devices.
- the browser can run.
- the bar code referred to in the present application is a general term for a graphic identifier for expressing a set of information, and includes a plurality of graphic identifiers such as a one-dimensional code and a two-dimensional code.
- a one-dimensional code generally refers to a plurality of black bars and spaces having different widths arranged according to a certain coding rule
- the two-dimensional code can be regarded as a special bar code, which can be regarded as It is an upgrade of a bar code, which is a black and white graphic, such as a QR code, distributed in a plane (two-dimensional direction) with a certain geometric pattern.
- the terminal in this application includes a PC end, a mobile terminal, other handheld devices (such as a PAD), a server, and the like.
- the application completely changes the bar code of the C/S technology in the prior art, and implements the bar code generation technology through the B/S mode.
- the device for generating the bar code provided by the application may be The terminal provides the same API (application programming interface, the user can call the framework API to implement more complex and rich applications), and the user can implement the barcode generation by calling the device under different terminals.
- the device of the present application can be implemented by various devices such as a PC and a smart device.
- the embodiment may be implemented by software, or may be implemented by hardware or a combination of hardware and software.
- the processor of the device in which it is located reads the corresponding computer program instructions in the non-volatile memory into the memory.
- FIG. 1 a hardware structure diagram of the device in the present application, except the processor and the network shown in FIG. 1 .
- the server in which the device is located in the embodiment may also include other hardware, which is not shown in detail in FIG.
- the logical block diagram of the device is shown in FIG. 2.
- the device 100 for generating a barcode includes at least two modules: an expression string generation module 101 and a webpage technology-based pattern generation module 102.
- the client can generate barcodes in the webpage by calling these two modules.
- the function of the expression string generation module 101 is to acquire the data value of each part according to the mapping relationship of the code system corresponding to the character string after acquiring the character string to be processed, and generate an expression string.
- the code system involved in barcode technology includes CODE39, CODE128, PDF417 and other code systems. The manner of obtaining the character string to be processed in the present application and the selection method of the code system corresponding to the character string may be determined according to the needs of the user, and will not be described herein.
- the function of the webpage-based pattern generation module 102 is to draw the expression string generated by the expression string generation module into a barcode in a webpage using webpage technology.
- the webpage technology adopted by the webpage technology-based pattern generation module 102 of the present application may be a technique of drawing through Canvas, and It can be a technique of drawing through SVG or Flash. Therefore, as shown in FIG. 2, the webpage-based pattern generation module may include at least one of the functions of one of the Canvas drawing sub-module 1021, the SVG, or the Flash drawing sub-module 1022.
- other webpage technologies that can be used for drawing can also be applied, so if you need to increase the scalability of the function of the webpage-based pattern generation module, other drawing function modules can be added accordingly.
- the apparatus may further include the server-side image generation module 103 of FIG. 1, if the language technology adopted by the server is compatible with the language of the javascript runtime environment, The module can be used to draw the expression string on the server side into a barcode image for use by the client webpage.
- the language used by the server to adapt to the javascript runtime environment may adopt the currently more common Nodejs technology, and the function of the image generation module may be implemented by adapting to the graphics library of the Node environment.
- the Node-canvas graphics library is implemented.
- the generation of the barcode device in FIG. 2 implements a set of schemes suitable for multiple
- the purpose of the terminal is to provide an API for the client using various versions of the browser, or to provide an API for the server, and only need the server to adopt a language suitable for the javascript runtime environment.
- the business logic of the webpage triggers the operation of calling the barcode generating apparatus of FIG. 1.
- the business logic of the webpage may
- the string to be processed is obtained from the webpage (other ways of obtaining the string can be made according to the user's needs) and transmitted to the device in FIG. 1 (step 201), and the device is further in the webpage.
- step 202 Executing an operation of generating an expression string (step 202); the business logic of the webpage transmits the generated expression string and the page location information where the barcode is displayed to the device (step 203), and invokes the drawing function of the device to draw, so The device draws the barcode of the obtained expression string in the corresponding page position in the webpage by webpage technology (step 204).
- the process of drawing the barcode is done by the technique of Canvas drawing. If the browser version used by the client is the previous generation browser (IE6, IE7, IE8, etc.), the barcode is drawn by SVG or Flash drawing technology.
- the apparatus for implementing the steps in FIG. 2 is also provided below.
- the apparatus may be implemented by software, or may be implemented by hardware or a combination of hardware and software.
- the processor of the device in which it is located reads the corresponding computer program instructions in the non-volatile memory into the memory.
- the hardware level it can include processors, network interfaces, memory, and non-volatile memory.
- FIG. 4 is a logic block diagram of an apparatus for implementing the steps of FIG. 3, notably, in accordance with common general knowledge of those skilled in the art, although the steps in FIG. 3 are performed by web pages downloaded in a client browser.
- each module in Figure 4 is located on the server side before executing the corresponding function, and is loaded into the web page at runtime to be executed in the client browser, that is, generated.
- the process of bar code is completed on the client side, and thus it can be seen that the present application is different from the bar code generation method of the prior art class library technology.
- the apparatus for implementing barcode generation includes a webpage service module 301 to implement an API calling function, and the webpage service module 301 performs the function of the business logic of the webpage above. That is, the character to be processed is transmitted to the expression string generating module 101 through the webpage service module 301, and the expression string generating module 101 is called to generate an expression string, and then the expression string and the page location information are notified to the webpage technology-based pattern generation module 102, and the call is made.
- the webpage-based pattern generation module 102 draws a barcode at a corresponding page location.
- FIG. 3 and FIG. 4 are explanatory diagrams of the technical solution for generating a barcode on the client in the present application.
- the technical solution for generating a barcode on the server side is explained in detail below through FIG. 5 and FIG. 6.
- the API of the apparatus of FIG. 1 of the present application can also be invoked to implement barcode generation.
- the server side can adopt the currently used language technology Nodejs. As shown in FIG. 5, when the server-side business logic needs to invoke the device in FIG.
- the device acquires the character string to be processed, and generates an expression string (step 501); the server-side business logic obtains the expression string and then transmits Giving the device and calling its drawing function, the device draws the expression string into image data on the server side using the graphics library (step 502), where the graphics library is described above, referring to the graphics library adapted to the Node environment; The picture is sent by the server-side business logic to the client browser for rendering (step 503).
- the process of sending the picture to the client browser by the service logic of the server in step 504 can be implemented in various ways, one of which is in accordance with the method commonly used in the prior art, that is, the bar code picture is first
- the server side stores the image file, and then the path of the image file is transmitted to the client through the url, and the client downloads the image file from the corresponding path to the corresponding position in the webpage for presentation.
- this application also breaks through another transmission method.
- the server encodes the image data into a base64 format, and then sets the base64 image data in the response header of the sent message.
- the image format is transmitted to the client presentation.
- the format of the response header message may be:
- Data:image/png;base64,xxxxxxxxxxxxxxx. x represents the encoded base64 encoding. It can be seen that the server does not need to store the picture file, and the client can directly display the barcode picture without downloading, so the efficiency is higher and the user experience is better.
- the server corresponding to each step of FIG. 5 may be implemented by software, or may be implemented by hardware or a combination of hardware and software.
- the processor of the device in which it is located reads the corresponding computer program instructions in the non-volatile memory into the memory.
- the hardware level it can include processors, network interfaces, memory, and non-volatile memory.
- FIG. 6 is a logic block diagram of a server implementing the steps of Figure 5.
- the function of the server's business logic is implemented by the server business logic module.
- the server service module invokes the expression string generation module to generate the expression string, and then transmits the expression string to the server image generation module, and the server-side image generation module draws the expression string on the server side into a barcode image by using the graphics library adapted to the Node environment ( In the embodiment, it can be implemented by the Node-canvas technology; and the server business logic module transmits the generated barcode image to the browser of the client through the webpage for presentation (please refer to the various manners described in FIG. 5, and details are not described again) .
- the following is only an example of using the API of the device in FIG. 1 through the client webpage as an example, and a detailed application example is described.
- the browser version of the client is a modern browser.
- the encoding of the string to be processed into an expression string is CODE128.
- the CODE128 encoding is widely used in the production process, logistics control system, and payment, etc.
- the following code128 example is used. According to Baidu Encyclopedia, you can also know the detailed meaning of the code. Baidu Encyclopedia link: http://baike.baidu.com/view/1332755.htm.
- Code128 is intended to mean that it can represent 128 characters from ASCII 0 to ASCII 127.
- ASCII is a computer coding system based on the Latin alphabet. It is mainly used to display modern English and other Western European languages.
- Code128A standard numbers and uppercase letters, control characters, special characters;
- Code128B standard numbers and uppercase letters, lowercase letters, special characters
- type B For the string "hello alibaba!” to be processed, type B should be selected.
- the code128 encoding mapping table can be found according to the Internet address http://xudafeng.github.io/code128/ .
- the encoding value of h is: bssbbssssbs
- the encoding value of e is: bsbbssbssss
- the encoding value of l is: bbssbsbssss
- the encoding value of o is: bsssbbbbsbs
- the encoding value of the space is: bbsbbssbbss
- the encoding value of a is: bssbsbbssss
- the encoding value of l is: bbssbsbssss
- the encoding value of i is: bssssbbsbss
- the encoding value of b is: bssbssssbbs
- the encoding value is: bbssbbsbbss
- the Code128 check digit is calculated as:
- the API provided in FIG. 1 is continuously called to visualize the expression string data. Since the client uses a modern browser, the canvas is downloaded in the client browser. Barcode drawn in the webpage:
- Fig. 7 is an effect diagram of the generated bar code map.
Landscapes
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Information Transfer Between Computers (AREA)
- User Interface Of Digital Computer (AREA)
Abstract
本申请公开了生成条码的方法、装置及服务器,其中生成条码的装置包括表达串生成模块,用于获取待处理的字符串生成表达串,所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;基于网页技术的图案生成模块,用于将所述表达串在网页中绘制成条码。本申请能够减少重复代码的编写,最终能够提升产品代码的可维护性,从而最大程度上降低维护和使用成本。
Description
本申请涉及通信技术领域,尤其涉及生成条码的方法、生成条码的装置、以及服务器。
条码即条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符。条码技术目前已广泛应用在互联网,电商领域。由于目前存在多种终端(例如PC端,移动终端,PAD等手持设备端以及服务器端设备等),而不同的终端各自的平台不尽相同,因此,现有技术中生成条形码的通常的做法是由研发人员使用不同的类库来实现。
但是,对于各个平台使用不同的类库,导致的结果是一方面开发人员要熟悉了解不同平台下的类库使用,各个终端的横向扩展非常困难,另一方面不同平台下会有一些相同的功能,而在现有的技术方案下这部分相同的功能需要在不同终端下基于不同的框架或类库重复实现,成本很高。
发明内容
本申请提供生成条码的方法、生成条码的装置、以及服务器,能够跨终端且低成本的解决生成条码的问题。
根据本申请实施例的第一方面,一种用于生成条码的装置,该装置包括:
表达串生成模块,用于获取待处理的字符串生成表达串,所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;
基于网页技术的图案生成模块,用于将所述表达串在网页中绘制成条码。
本申请另一方面提供一种生成条码的方法,该方法包括步骤:
获取待处理的字符串,在网页中生成表达串;所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;
获取所述表达串以及网页中相应的页面位置信息,并在该页面位置通过网页技术绘制条码。
本申请另一方面还一种生成条码的方法,该方法包括步骤:
获取待处理的字符串,生成表达串;所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;
获取所述表达串,将所述表达串在服务器端利用图形库绘制成条码图片;所述服务器端所采用的语言技术与javascript的运行环境相适应;所述图形库为适应Node环境的图形库;
将所述条码图片发送至客户端浏览器。
本申请还提供了一种利用条码生成装置生成条码的装置,该装置包括:
表达串生成模块,用于获取待处理的字符串生成表达串,所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;
网页业务模块,用于调用所述表达串生成模块,获得所述表达串,并将所述表达串以及相应的页面位置信息传给所述基于网页技术的图案生成模块;
基于网页技术的图案生成模块,用于将所述表达串在所述页面位置绘制成条码。
本申请还提供一种生成条码的服务器,该服务器包括:
表达串生成模块,用于获取待处理的字符串生成表达串,所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;
服务器业务模块,用于调用所述表达串生成模块,获得所述表达串,并将所述表达串传给服务器端图片生成模块,以及将条码图片发送给客户端浏览器;
服务器端图片生成模块,用于将所述表达串在服务器端利用图形库绘制
成条码图片;所述服务器端所采用的语言技术与javascript的运行环境相适应,所述图形库为适应Node环境的图形库。
本申请完全改变了现有技术中通过C/S技术的类库来实现条码的思路,突破性的通过B/S模式来实现条码生成技术,本申请提供的用于生成条码的装置可以为各种终端提供相同的API(应用程序编程接口,用户可以调用框架的API实现更复杂和丰富的应用),用户在不同的终端下都可以通过调用该装置实现条码的生成,从而使得用户在不同的终端下都可以基于本申请就能够达到在不同的平台下共享代码,减少重复代码的编写,最终能够提升产品代码的可维护性,从而最大程度上降低维护和使用成本。
图1为本申请中条码生成模块的硬件框架图。
图2为本申请实施例中条码生成装置的逻辑框图;
图3为本申请实施例中客户端通过调用图1的装置在网页中实现条码生成的方法的流程图;
图4为本申请实施例中调用图1的装置在网页中实现条码生成的装置的逻辑框图;
图5为本申请实施例中服务器端通过调用图1中的装置在服务器端实现条码生成的方法的流程图;
图6为本申请实施例中实现条码生成的服务器的逻辑框图;
图7为本申请应用实例中将待处理的字符串生成表达串的效果图;
图8为本申请应用实例中生成条码的效果图。
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的
要素。以下示例性实施例中所描述的实施方式并不代表与本申请相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本申请的一些方面相一致的装置和方法的例子。
在本申请使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本申请。在本申请和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。
本申请提供了适应于多种终端生成条码的技术方案,无论终端使用的是什么平台以及什么操作系统(Window,Mac,Unix,Linux,iOS,Android等),甚至各种版本各种终端设备的浏览器都可以运行。在本申请中所涉及的条码是用以表达一组信息的图形标识符的统称,包括一维码、二维码等多种图形标识符。以一维码和二维码为例,一维码泛指将宽度不等的多个黑条和空白按照一定的编码规则排列,二维码可以看成是一种特殊的条码,可看作是条形码的升级,是用特定的几何图形按一定规律在平面(二维方向)上分布的黑白相间的图形,例如QR码等。本申请中的终端包括PC端、移动终端、其他手持设备(如PAD)端、服务端等。
随着WEB和浏览器的发展,Javascript,HTML5技术在越来越多的平台得以应用,不仅应用于客户端PC浏览器,还应用到了移动、平板客户端触屏浏览器甚至服务器端。本申请完全改变了现有技术中通过C/S技术的类库来实现条码的思路,突破性的通过B/S模式来实现条码生成技术,本申请提供的用于生成条码的装置可以为各种终端提供相同的API(应用程序编程接口,用户可以调用框架的API实现更复杂和丰富的应用),用户在不同的终端下都可以通过调用该装置实现条码的生成。
本申请的该装置可以通过PC、智能设备等多种设备实现。实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。从硬件层面而言,如图1所示,为本申请中该装置的一种硬件结构图,除了图1所示的处理器、网
络接口、内存以及非易失性存储器之外,实施例中装置所在的服务器通常还可以包括其他硬件,对此图1不再详细示出。
该装置的逻辑框图如图2所示,该生成条码的装置100至少包括两个模块:表达串生成模块101和基于网页技术的图案生成模块102。客户端通过调用这两个模块可以实现在网页中生成条码。
表达串生成模块101的功能是在获取到待处理的字符串后,根据该字符串所对应的码制的映射关系获取各部分的数据值,生成表达串。条码技术涉及的码制包括CODE39,CODE128,PDF417等多种码制。在本申请中待处理的字符串的获取方式以及字符串所对应的码制的选择方式可以根据使用者的需要来决定,在此不赘述。
基于网页技术的图案生成模块102的功能是将表达串生成模块所生成的表达串利用网页技术在网页中绘制成条码。为了使得该装置能够被各种版本各种客户端终端设备的浏览器执行,作为一个实施例,本申请的基于网页技术的图案生成模块102所采用的网页技术可以是通过Canvas绘图的技术,还可以是通过SVG或Flash绘图的技术。因此如图2所示,基于网页技术的图案生成模块可以至少包括Canvas绘图子模块1021、SVG或Flash绘图子模块1022中的一个模块所具有的功能。当然其他可以用于绘图的网页技术也可以适用,因此如果需要增加基于网页技术的图案生成模块的功能的可扩展性可以相应增加其他绘图功能模块。
为了使得本申请的装置也能够为服务器端提供API以便生成条码,该装置还可以包括图1中的服务器端图片生成模块103,如果服务器端所采用的语言技术与javascript运行环境相适应的语言,则可以通过该模块在服务器端将表达串绘制成条码图片,供客户端网页使用。在一个实施例中,服务器端使用的与javascript运行环境相适应的语言可以采用目前比较通用的Nodejs技术,图片生成模块的功能可以通过适应Node环境的图形库来实现,作为一个实施例,可以通过Node-canvas图形库来实现。
从以上叙述可以看出,图2中的生成条码装置实现了一套方案适用于多
种终端的目的,既可以为使用各种版本浏览器的客户端提供API,也可以为服务器端提供API,只需要服务器端采用了与javascript运行环境相适应的语言。
以下参照图3对客户端通过调用图1的装置在网页中实现条码生成的方案进行解释和阐述。
当客户端通过浏览器访问特定的网页时,该网页的业务逻辑将触发调用图1的条码生成装置的操作,作为一个实施例,当网页的业务逻辑收到指令调用该装置时,业务逻辑可以从网页中获取到待处理的字符串(除此之外的其他获取字符串的途径可以根据使用者需求来制定),并传递给图1中的装置(步骤201),该装置进而在网页中执行生成表达串的操作(步骤202);网页的业务逻辑将生成的表达串以及该条码显示时所在的页面位置信息传递给该装置(步骤203),并调用该装置的绘图功能进行绘图,于是该装置将获取到的表达串在网页中相应的页面位置通过网页技术绘制条码(步骤204)。
如果客户端所使用的浏览器版本为现代浏览器(包括IE9及以上版本,Chrome,Firefox,Safari等浏览器),则通过Canvas绘图的技术完成绘制条码的步骤。如果客户端所使用的浏览器版本为上一代浏览器(IE6,IE7,IE8等),则通过SVG或Flash绘图的技术来绘制条码。
与图3中的条码生成方法相对应,以下还提供出实现图2中的各步骤的装置,实施例中该装置可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。从硬件层面而言,可以包括处理器、网络接口、内存以及非易失性存储器等。
图4为实现图3中的各步骤的装置的逻辑框图,值得注意的是,根据本领域技术人员的公知常识,虽然图3中各步骤是通过在客户端浏览器中被下载的网页中执行的,但是图4中的各模块在执行相应的功能之前是位于服务器端,而在运行时被加载到网页中在客户端浏览器中被执行,也就是说生成
条码的过程是在客户端完成,由此可以看出本申请不同于现有技术的类库技术的条码生成方式。
从图4中可以看出,实现条码生成的装置包括一个网页业务模块301来实现API的调用功能,网页业务模块301完成上文中网页的业务逻辑的功能。即通过网页业务模块301将待处理的字符传给表达串生成模块101,并调用表达串生成模块101生成表达串,随后将表达串和页面位置信息通知基于网页技术的图案生成模块102,并调用基于网页技术的图案生成模块102在相应的页面位置绘制条码。
图3和图4是本申请中在客户端生成条码的技术方案解释说明,以下通过图5和图6对服务器端生成条码的技术方案进行详细解释。
如果服务器端所采用的语言技术与javascript运行环境相适应的语言则同样可以调用本申请图1的装置的API来实现条码生成。作为一个实施例,服务器端可以采用目前常用的的语言技术Nodejs。流程图如图5所示,当服务器端的业务逻辑需要调用图2中的装置时,该装置获取待处理的字符串,生成表达串(步骤501);服务器端的业务逻辑获取到表达串后会传递给该装置并调用其绘图功能,该装置在服务器端将表达串利用图形库绘制成图片数据(步骤502),这里的图形库在前文有描述,是指与Node环境相适应的图形库;然后由服务器端的业务逻辑将图片发送至客户端浏览器进行呈现(步骤503)。
值得特别指出的是,步骤504中服务器的业务逻辑将图片发送至客户端浏览器的过程可以通过多种方式实现,其中一种方式是按照现有技术中常用的方式,即先将条码图片在服务器端存储成图片文件,然后将图片文件的路径通过url传给客户端,客户端从相应的路径将图片文件下载在网页中的相应位置进行呈现。除此之外,本申请还突破性的研究出另一种传输方式,当生成条码图片后,服务器端将图片数据编码成base64格式,然后将base64图片数据在所发送的消息的响应头中设置成图片格式传输至客户端呈现,在实施例中响应头消息的格式可以是:
data:image/png;base64,xxxxxxxxxxxxxxx。x表示编码后的base64编码。可以看出,该种方式服务器无需存储图片文件,而客户端可以无需下载直接呈现条码图片,因此效率更高,用户体验更好。
与图5种的各步骤相对应的服务器可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。从硬件层面而言,可以包括处理器、网络接口、内存以及非易失性存储器等。
图6为实现图5中各步骤的服务器的逻辑框图。从图中可以看出,服务器的业务逻辑的功能由服务器业务逻辑模块实现。服务器业务模块调用表达串生成模块,使其生成表达串后,将该表达串传给服务器图片生成模块,服务器端图片生成模块将表达串在服务器端利用适应Node环境的图形库绘制成条码图片(在实施例中可以通过Node-canvas技术实现);而服务器业务逻辑模块将所生成的条码图片通过网页传给客户端的浏览器进行呈现(请参照图5所描述的多种方式,不再赘述)。
为了能够使使用者充分感受本申请的技术方案生成条码的完整过程,以下仅以通过客户端网页调用图1中的装置的API为例,叙述详细的应用实例。在该应用实例中客户端的浏览器版本为现代浏览器。
在本应用实例中,将待处理的字符串转换为表达串的编码采用CODE128为例,CODE128编码广泛应用在生产流程、物流控制系统,以及支付等方面的条码码制,以下用code128举例子,根据百度百科也可以获知该编码的详细含义。百度百科链接:http://baike.baidu.com/view/1332755.htm。Code128本意是指其可表示从ASCII 0到ASCII 127共128个字符。ASCII是基于拉丁字母的一套电脑编码系统。它主要用于显示现代英语和其他西欧语言。
在该应用实例中待处理的字符为“hello alibaba!”,我们讨论如何对字符“hello alibaba!”进行条码编码。
Code128编码方式有三种:
A、Code128A:标准数字和大写字母,控制符,特殊字符;
B、Code128B:标准数字和大写字母,小写字母,特殊字符;
C、Code128C:00到99的数字对共100个,只能表示偶数位长度的数字;
针对待处理的字符串“hello alibaba!”,应选择类型B,可以根据互联网的网址http://xudafeng.github.io/code128/了解code128编码映射表。
调用图1中的装置的API,根据Code28编码映射表在网页中生成表达串的过程具体如下:
1.根据映射表获取B类型开始位
如图6所示得到编码值“bbsbssbssss”
2.依次获取“hello alibaba!”数据位
h的编码值为:bssbbssssbs
e的编码值为:bsbbssbssss
l的编码值为:bbssbsbssss
o的编码值为:bsssbbbbsbs
空格的编码值为:bbsbbssbbss
a的编码值为:bssbsbbssss
l的编码值为:bbssbsbssss
i的编码值为:bssssbbsbss
b的编码值为:bssbssssbbs
!的编码值为:bbssbbsbbss
注意:与获取开始位类似,可以参照上面提供的编码表。
3.获取检验位
Code128检验位计算方式为:
开始位的ID值+每位数据的位置×每位的ID值)%103结果为:bssbbsbbbss
4.补充结束位,获取完整数据
A,B,C三种类型的结束位都为:bbsssbbbsbsbb
最终生成的表达串(开始位+数据位+检验位+结束位):
bbsbssbssssbssbbssssbsbsbbssbssssbbssbsbssssbbssbsbssssbsssbbbbsbsbbsbbssbbssbssbsbbssssbbssbsbssssbssssbbsbssbssbssssbbsbssbsbbssssbssbssssbbsbssbsbbssssbbssbbsbbssbssbbsbbbssbbsssbbbsbsbb
通过网页业务逻辑将生成的表达串传给图1中的装置后,继续调用图1提供的API将表达串数据可视化,由于客户端使用的是现代浏览器,因此利用canvas在客户端浏览器下载的网页中绘制条码:
设置单位宽度width,例如为1像素或其他值
设置高度height,可以设置为任意合适值;
1.以坐标(0,0)作为起点,根据表达串
“bbsbssbssssb.....bbsssbbbsbsbb”进行遍历;
2.使用context.fillRect(x,0,width,height)进行绘制,此时x值与数据位置成正比;
3.绘制完成后在客户端的浏览器的网页中呈现出条码,可使用toDataURL导出图片格式后呈现,也可以不导出直接呈现条码图案。图7为生成的条码图的效果图。
本领域技术人员在考虑说明书及实践这里公开的发明后,将容易想到本申请的其它实施方案。本申请旨在涵盖本申请的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本申请的一般性原理并包括本申请未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本申请的真正范围和精神由下面的权利要求指出。
应当理解的是,本申请并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本申请的范围仅由所附的权利要求来限制。
Claims (17)
- 一种用于生成条码的装置,其特征在于,该装置包括:表达串生成模块,用于获取待处理的字符串生成表达串,所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;基于网页技术的图案生成模块,用于将所述表达串在网页中绘制成条码。
- 根据权利要求1所述的装置,其特征在于,所述网页技术为通过canvas绘图的技术。
- 根据权利要求1所述的装置,其特征在于,所述网页技术为通过SVG或Flash绘图的技术。
- 根据权利要求1所述的装置,其特征在于,所述条码包括一维码或二维码。
- 根据权利要求2或3所述的装置,其特征在于,该装置还包括:服务器端图片生成模块,用于将所述表达串在服务器端利用图形库绘制成条码图片;所述服务器端所采用的语言技术与javascript的运行环境相适应,所述图形库为适应Node环境的图形库。
- 根据权利要求5所述的装置,其特征在于,所述服务器端采用的语言技术为Nodejs,所述适应Node环境的图形库包括Node-canvas图形库。
- 一种生成条码的方法,其特征在于,该方法包括步骤:获取待处理的字符串,在网页中生成表达串;所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;获取所述表达串以及网页中相应的页面位置信息,并在该页面位置通过网页技术绘制条码。
- 根据权利要求7所述的方法,其特征在于,所述网页技术为通过canvas绘图的技术。
- 根据权利要求7所述的方法,其特征在于,所述网页技术为通过SVG或Flash绘图的技术。
- 根据权利要求7所述的方法,其特征在于,所述条码包括一维码或二维码。
- 一种生成条码的方法,其特征在于,该方法包括步骤:获取待处理的字符串,生成表达串;所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;获取所述表达串,将所述表达串在服务器端利用图形库绘制成条码图片;所述服务器端所采用的语言技术与javascript的运行环境相适应;所述图形库为适应Node环境的图形库;将所述条码图片发送至客户端浏览器。
- 根据权利要求11所述的方法,其特征在于,所述服务器端采用的语言技术为Nodejs,所述适应Node环境的图形库包括Node-canvas图形库。
- 根据权利要求11所述的方法,其特征在于,将所述条码图片发送至客户端浏览器的过程包括:将所述条码图片编码成base64编码,将载有所述base64编码的消息发送至客户端浏览器。
- 一种利用权利要求1至4中任一个所述的装置生成条码的装置,其特征在于,该装置包括:表达串生成模块,用于获取待处理的字符串生成表达串,所述表达串用于表示待处理的字符串与所对应的码制的映射关系的数据值;网页业务模块,用于调用所述表达串生成模块,获得所述表达串,并将所述表达串以及相应的页面位置信息传给所述基于网页技术的图案生成模块;基于网页技术的图案生成模块,用于将所述表达串在所述页面位置绘制成条码。
- 一种生成条码的服务器,其特征在于,该服务器包括:表达串生成模块,用于获取待处理的字符串生成表达串,所述表达串用 于表示待处理的字符串与所对应的码制的映射关系的数据值;服务器业务模块,用于调用所述表达串生成模块,获得所述表达串,并将所述表达串传给服务器端图片生成模块,以及将条码图片发送给客户端浏览器;服务器端图片生成模块,用于将所述表达串在服务器端利用图形库绘制成条码图片;所述服务器端所采用的语言技术与javascript的运行环境相适应,所述图形库为适应Node环境的图形库。
- 根据权利要求15所述的服务器,其特征在于,所述服务器端采用的语言技术为Nodejs,所述图片生成模块采用Node-canvas技术。
- 根据权利要求15所述的服务器,其特征在于,所述服务器业务模块发送条码图片的过程为:将所述条码图片编码成base64编码,将载有所述base64编码的消息发送至客户端浏览器。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201410642577.2A CN105574569B (zh) | 2014-11-11 | 2014-11-11 | 生成条码的方法、装置及服务器 |
| CN201410642577.2 | 2014-11-11 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2016074568A1 true WO2016074568A1 (zh) | 2016-05-19 |
Family
ID=55884675
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2015/093314 Ceased WO2016074568A1 (zh) | 2014-11-11 | 2015-10-30 | 生成条码的方法、装置及服务器 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN105574569B (zh) |
| WO (1) | WO2016074568A1 (zh) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112328317A (zh) * | 2020-08-31 | 2021-02-05 | 中盈优创资讯科技有限公司 | 一种基于node-canvas的服务端生成图表方法 |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102708503A (zh) * | 2012-04-20 | 2012-10-03 | 武汉大学 | 一种利用二维码做手机广告的方法 |
| CN103870861A (zh) * | 2012-12-11 | 2014-06-18 | 腾讯科技(深圳)有限公司 | 一种生成二维码的方法和装置 |
| CN103902711A (zh) * | 2014-04-01 | 2014-07-02 | 深圳市茁壮网络股份有限公司 | 一种将二维码图片嵌入网页的方法和系统 |
-
2014
- 2014-11-11 CN CN201410642577.2A patent/CN105574569B/zh active Active
-
2015
- 2015-10-30 WO PCT/CN2015/093314 patent/WO2016074568A1/zh not_active Ceased
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102708503A (zh) * | 2012-04-20 | 2012-10-03 | 武汉大学 | 一种利用二维码做手机广告的方法 |
| CN103870861A (zh) * | 2012-12-11 | 2014-06-18 | 腾讯科技(深圳)有限公司 | 一种生成二维码的方法和装置 |
| CN103902711A (zh) * | 2014-04-01 | 2014-07-02 | 深圳市茁壮网络股份有限公司 | 一种将二维码图片嵌入网页的方法和系统 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN105574569B (zh) | 2020-01-03 |
| CN105574569A (zh) | 2016-05-11 |
| HK1224405A1 (zh) | 2017-08-18 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN105739963B (zh) | 生成网页的方法和装置 | |
| US11677809B2 (en) | Methods for transforming a server side template into a client side template and devices thereof | |
| CN110908712A (zh) | 移动端跨平台的数据处理方法和设备 | |
| US9646103B2 (en) | Client-side template engine and method for constructing a nested DOM module for a website | |
| US11003835B2 (en) | System and method to convert a webpage built on a legacy framework to a webpage compatible with a target framework | |
| CN108416021B (zh) | 一种浏览器网页内容处理方法、装置、电子设备及可读介质 | |
| US20160012144A1 (en) | Javascript-based, client-side template driver system | |
| CN111880892A (zh) | 一种基于svg技术的实时监测工业数据的方法 | |
| CN109918175A (zh) | 图片生成方法、装置、存储介质及电子设备 | |
| CN105005568A (zh) | 基于模板的web页面前端处理装置及方法 | |
| WO2016005885A2 (en) | Asynchronous initialization of document object model (dom) modules | |
| CN113900647A (zh) | 一种网页截图的方法和装置以及设备 | |
| CN113050921A (zh) | 一种网页转换方法、装置、存储介质和计算机设备 | |
| JP2016540333A (ja) | 端末標記方法、端末標記装置、プログラム及び記録媒体 | |
| US20140365900A1 (en) | Replication of mobile rendering using computer-readable images | |
| CN104298506A (zh) | 一种网页分页插件的实现方法 | |
| US20160012023A1 (en) | Self-Referencing of Running Script Elements in Asynchronously Loaded DOM Modules | |
| CN102799764A (zh) | 一种基于Web的工程计算系统及方法 | |
| CN107273127A (zh) | 一种在web应用中实现页面插件化的方法及装置 | |
| CN114254585B (zh) | 字体生成方法、装置、电子设备及存储介质 | |
| CN105574569B (zh) | 生成条码的方法、装置及服务器 | |
| CN116827637B (zh) | 基于画布的数据加密传输方法、系统、设备及介质 | |
| CN109413115B (zh) | 协议文本解析方法及系统 | |
| CN112306619A (zh) | 一种截图方法和装置 | |
| CN113791779B (zh) | 数据处理方法、装置及系统 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 15859013 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 15859013 Country of ref document: EP Kind code of ref document: A1 |