除了使用我的这篇blogStep by step to create QRCode in ABAP Webdynpro提到的使用ABAP webdynpro生成二维码之外,也可以通过使用二维码在线生成网站提供的service来生成二维码。
二维码在线生成网站:
http://www.makepic.com/qrcode.php
在网页上输入要生成的二维码数据源,校验级别和图片大小,点生成即可看到生成的二维码图片:
下面是用ABAP code 利用上述service生成二维码的代码:
DATA:ls_form type zcl_http_tool=>ty_name_pair,
lt_header type zcl_http_tool=>tt_name_pair,
lt_form type zcl_http_tool=>tt_name_pair,
lv_code type xstring.
ls_form = value #( name = ‘data‘ value = ‘testforQRCode‘ ).
APPEND ls_form TO lt_form.
ls_form = value #( name = ‘level‘ value = ‘M‘ ).
APPEND ls_form TO lt_form.
ls_form = value #( name = ‘size‘ value = ‘6‘ ).
APPEND ls_form TO lt_form.
zcl_http_tool=>send_request( iv_url = ‘http://www.makepic.com/qrcode.php‘
iv_req_type = if_http_request=>co_request_method_post
it_form = lt_form ).
ls_form = value #( name = ‘Referer‘ value = ‘http://www.makepic.com/qrcode.php‘ ).
APPEND ls_form TO lt_header.
zcl_http_tool=>send_request( EXPORTING iv_url = ‘http://www.makepic.com/mkqr.php?data=testforQRCode&level=M&size=6‘
iv_req_type = if_http_request=>co_request_method_get
it_header = lt_header
IMPORTING ev_response = lv_code ).
testforQRCode对应生成的二维码:
用手机上的二维码扫描应用能够成功扫描出来:
zcl_http_tool的代码在我的github上(因为用于demo用途,没有加对应的出错处理)
原文地址:https://www.cnblogs.com/baimeishaoxia/p/11980126.html
时间: 2024-09-30 08:50:53