使用ABAP代码生成二维码(QR Code)
Previously we have discussed how to generate QRcode with SAP standard functionality:
(1) Generate QRcode with ABAP Webdynpro (2) Generate QRcode with ABAP Code plus Adobe form template
Both solutions will generate QRCode within a PDF file.
If your requirement is to generate the QRCode in a picture file, you can use the solution described in this blog.
There are lots of websites which provide free QRCode generation service. Just google it:
I prefer to use this one http://www.qrstuff.com: just choose “Plain Text” and we can input some characters in Text field. There is a AJAX call which will generate QRCode immediately after some characters are typed.
Now question is how we automate the character input via ABAP.
I use Chrome to explore what has happened when we input some char in webpage. Click F12 to launch Chrome developer tool, input some char and observe the information displayed in the “Network” tab:
The request URL is found: http://www.qrstuff.com/generate.generate The request method is GET. Also it is necessary to identify http form fields and they are also listed in Chrome:
We need to copy all of those form fields into our ABAP code except preview=1, since we don’t need the preview functionality, we just need the generated png file.
here below is the simple report to generate QRCode from hard coded string “testforQRCode”. ( The bold text are just copied from Chrome developer tool ) The source code of zcl_http_tool could be found from attachment.
DATA:ls_form type zcl_http_tool=>ty_name_pair,
lt_form type zcl_http_tool=>tt_name_pair,
lv_code type xstring.
ls_form = value #( name = 'type' value = 'TEXT' ).
APPEND ls_form TO lt_form.
ls_form = value #( name = 'foreground_color' value = '000000' ).
APPEND ls_form TO lt_form.
ls_form = value #( name = 'ecc_level' value = 'L' ).
APPEND ls_form TO lt_form.
ls_form = value #( name = 'width_pixels' value = '200' ).
APPEND ls_form TO lt_form.
ls_form = value #( name = 'dpi' value = '72' ).
APPEND ls_form TO lt_form.
ls_form = value #( name = 'file_type' value = 'png' ).
APPEND ls_form TO lt_form.
ls_form = value #( name = 'text' value = 'testforQRCode' ).
APPEND ls_form TO lt_form.
zcl_http_tool=>send_request( EXPORTING iv_url = 'http://www.qrstuff.com/generate.generate'
iv_req_type = if_http_request=>co_request_method_get
it_form = lt_form
IMPORTING ev_response = lv_code ).
And this is QRCode scanned from my mobile phone:
- 跨平台移动开发UI语言 -XAML
- S-shortcodes:WordPress短代码形式美化框插件下载
- 服务器同时存在1.1和2.0程序注意事项
- Flash/Flex学习笔记(44):万有引力与粒子系统
- 代码重写WordPress网页标题为“原网页标题|网站名”的形式
- 未来10年21个核心工作岗位
- Asp.net 2.0 WebPart使用经验点滴
- 使用LinqToExcel读取Excel
- 时代的需要:越来越多的Java工程师开始转向hadoop?
- 如何结合IbatisNet的LIST遍历实现模糊查询
- Flash/Flex学习笔记(41):碰撞检测
- [.NET网格计算框架] Alchemi
- 修改WordPress登陆文件名wp-login.php,防密码被暴力破解
- NDoc - .NET 代码文档生成器
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android实现自定义验证码输入框效果(实例代码)
- flutter 实现多布局列表的示例代码
- flutter TextField换行自适应的实现
- 如何造个android Flow流式响应的轮子
- Flutter混合开发详解
- Android 单双击实现的方法步骤
- Android多渠道打包时获取当前渠道的方法
- Flutter Dio二次封装的实现
- android开发通过Scroller实现过渡滑动效果操作示例
- Android9.0 静默安装源码的实现
- Flutter路由框架Fluro使用简介
- Android倒计时神器(CountDownTimer)
- Kotlin如何安全访问lateinit变量的实现
- Android实现加载对话框
- Android RecyclerView实现悬浮吸顶、分隔线、到底提示效果