天天看點

用ABAP 生成二維碼 QR Code

二維碼線上生成網站:

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' ).

ls_form = value #( name = 'size' value = '6' ).

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用途,沒有加對應的出錯處理)

繼續閱讀