SAP加密解密功能设计
【场景】与外围系统对接时,出于信息安全等因素,经常需要对传输的信息做加密解密控制。
1. 公用类zcl_aes_utility
*----------------------------------------------------------------------*
* CLASS ZCL_AES_UTILITY DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_aes_utility DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
*"* public components of class ZCL_AES_UTILITY
*"* do not include other source files here!!!
CONSTANTS mc_block_length_in_bit TYPE int4 VALUE 128 ##NO_TEXT.
CONSTANTS mc_block_length_in_byte TYPE int4 VALUE 16 ##NO_TEXT.
CONSTANTS mc_key_length_in_bit_128 TYPE int4 VALUE 128 ##NO_TEXT.
CONSTANTS mc_key_length_in_bit_192 TYPE int4 VALUE 192 ##NO_TEXT.
CONSTANTS mc_key_length_in_bit_256 TYPE int4 VALUE 256 ##NO_TEXT.
CONSTANTS mc_encryption_mode_ecb TYPE char10 VALUE 'ECB' ##NO_TEXT.
CONSTANTS mc_encryption_mode_cbc TYPE char10 VALUE 'CBC' ##NO_TEXT.
CONSTANTS mc_encryption_mode_pcbc TYPE char10 VALUE 'PCBC' ##NO_TEXT.
CONSTANTS mc_encryption_mode_cfb TYPE char10 VALUE 'CFB' ##NO_TEXT.
CONSTANTS mc_encryption_mode_ofb TYPE char10 VALUE 'OFB' ##NO_TEXT.
CONSTANTS mc_encryption_mode_ctr TYPE char10 VALUE 'CTR' ##NO_TEXT.
CONSTANTS mc_padding_standard_none TYPE char10 VALUE 'NONE' ##NO_TEXT.
CONSTANTS mc_padding_standard_pkcs_7 TYPE char10 VALUE 'PKCS7' ##NO_TEXT.
CLASS-DATA:
mt_raw16 TYPE TABLE OF zif_aes_mode=>ty_raw16 .
CLASS-METHODS is_valid_iv_xstring
IMPORTING
!i_initialization_vector TYPE xstring
RETURNING
VALUE(r_valid) TYPE boole_d .
CLASS-METHODS encrypt_xstring
IMPORTING
!i_key TYPE xstring
!i_data TYPE xstring
!i_initialization_vector TYPE xstring OPTIONAL
!i_padding_standard TYPE char10 OPTIONAL
!i_encryption_mode TYPE char10 OPTIONAL
EXPORTING
!e_data TYPE xstring .
CLASS-METHODS decrypt_xstring
IMPORTING
!i_key TYPE xstring
!i_data TYPE xstring
!i_initialization_vector TYPE xstring OPTIONAL
!i_padding_standard TYPE char10 OPTIONAL
!i_encryption_mode TYPE char10 OPTIONAL
EXPORTING
!e_data TYPE xstring .
CLASS-METHODS encrypt_raw16_table
IMPORTING
!i_key TYPE xstring
!i_initialization_vector TYPE xstring OPTIONAL
!i_encryption_mode TYPE char10 OPTIONAL
!i_padding_standard TYPE char10 OPTIONAL
!i_data_length_in_byte TYPE int4
EXPORTING
!et_data LIKE mt_raw16
CHANGING
!ct_data LIKE mt_raw16 .
CLASS-METHODS decrypt_raw16_table
IMPORTING
!i_key TYPE xstring
!i_initialization_vector TYPE xstring
!i_encryption_mode TYPE char10
!i_padding_standard TYPE char10
!it_data LIKE mt_raw16
EXPORTING
!e_data_length_in_byte TYPE int4
!et_data LIKE mt_raw16 .
CLASS-METHODS convert_xstring_to_raw16_table
IMPORTING
!i_data TYPE xstring
EXPORTING
!e_data_length_in_byte TYPE int4
!et_raw16_table LIKE mt_raw16 .
CLASS-METHODS convert_raw16_table_to_xstring
IMPORTING
!i_data_length_in_byte TYPE int4
!it_raw16_table LIKE mt_raw16
EXPORTING
!e_data TYPE xstring .
CLASS-METHODS validate_encryption_mode
IMPORTING
!i_initialization_vector TYPE xstring OPTIONAL
!i_encryption_mode TYPE char10 OPTIONAL .
CLASS-METHODS validate_padding_standard
IMPORTING
!i_padding_standard TYPE char10 OPTIONAL .
CLASS-METHODS validate_raw16_table_size
IMPORTING
!i_data_length_in_byte TYPE int4
!it_data LIKE mt_raw16 .
CLASS-METHODS add_padding_raw16_table
IMPORTING
!i_data_length_in_byte TYPE int4
!io_padding_utility TYPE REF TO zcl_byte_padding_utility
CHANGING
!ct_data LIKE mt_raw16 .
CLASS-METHODS remove_padding_raw16_table
IMPORTING
!io_padding_utility TYPE REF TO zcl_byte_padding_utility
EXPORTING
!e_data_length_in_byte TYPE int4
CHANGING
!ct_data LIKE mt_raw16 .
2. 类/接口ZCL_AES_MODE_ECB
*----------------------------------------------------------------------*
* INTERFACE ZIF_AES_MODE
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE zif_aes_mode
PUBLIC .
types: ty_raw16 type x length 16.
CLASS-DATA:
mt_raw16 TYPE TABLE OF ty_raw16 .
METHODS decrypt_raw16_table
IMPORTING
!io_rijndael TYPE REF TO zcl_rijndael_utility
!i_key TYPE xstring
!i_initialization_vector TYPE xstring
!it_data LIKE mt_raw16
EXPORTING
!et_data LIKE mt_raw16 .
METHODS encrypt_raw16_table
IMPORTING
!io_rijndael TYPE REF TO zcl_rijndael_utility
!i_key TYPE xstring
!i_initialization_vector TYPE xstring
!it_data LIKE mt_raw16
EXPORTING
!et_data LIKE mt_raw16 .
ENDINTERFACE.
2. 类/接口 ZIF_AES_MODE
*----------------------------------------------------------------------*
* INTERFACE ZIF_AES_MODE
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE zif_aes_mode
PUBLIC .
types: ty_raw16 type x length 16.
CLASS-DATA:
mt_raw16 TYPE TABLE OF ty_raw16 .
METHODS decrypt_raw16_table
IMPORTING
!io_rijndael TYPE REF TO zcl_rijndael_utility
!i_key TYPE xstring
!i_initialization_vector TYPE xstring
!it_data LIKE mt_raw16
EXPORTING
!et_data LIKE mt_raw16 .
METHODS encrypt_raw16_table
IMPORTING
!io_rijndael TYPE REF TO zcl_rijndael_utility
!i_key TYPE xstring
!i_initialization_vector TYPE xstring
!it_data LIKE mt_raw16
EXPORTING
!et_data LIKE mt_raw16 .
ENDINTERFACE.
*----------------------------------------------------------------------*
* CLASS ZCL_AES_MODE_CBC DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_aes_mode_cbc DEFINITION
PUBLIC
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES zif_aes_mode .
3. 加密方法ENCRYPT_XSTRING加密
METHOD encrypt_xstring.
DATA: lt_plain_raw16 LIKE mt_raw16,
lt_cipher_raw16 LIKE mt_raw16,
lv_plain_length_in_byte TYPE int4,
lv_cipher_length_in_byte TYPE int4.
CLEAR e_data.
convert_xstring_to_raw16_table(
EXPORTING
i_data = i_data
IMPORTING
e_data_length_in_byte = lv_plain_length_in_byte
et_raw16_table = lt_plain_raw16 ).
encrypt_raw16_table(
EXPORTING
i_data_length_in_byte = lv_plain_length_in_byte
i_encryption_mode = i_encryption_mode
i_initialization_vector = i_initialization_vector
i_padding_standard = i_padding_standard
i_key = i_key
IMPORTING
et_data = lt_cipher_raw16
CHANGING
ct_data = lt_plain_raw16 ).
lv_cipher_length_in_byte = lines( lt_cipher_raw16 ) * mc_block_length_in_byte.
convert_raw16_table_to_xstring(
EXPORTING
it_raw16_table = lt_cipher_raw16
i_data_length_in_byte = lv_cipher_length_in_byte
IMPORTING
e_data = e_data ).
ENDMETHOD. "encrypt_xstring
METHOD: CONVERT_XSTRING_TO_RAW16_TABLE
METHOD convert_xstring_to_raw16_table.
DATA: lv_input_length TYPE int4,
lv_number_of_blocks TYPE int4,
lv_block_cursor TYPE int4,
lv_offset TYPE int4.
FIELD-SYMBOLS: <raw16> TYPE zif_aes_mode=>ty_raw16.
CLEAR et_raw16_table.
lv_input_length = xstrlen( i_data ).
lv_number_of_blocks = ceil( '1.0' * lv_input_length / mc_block_length_in_byte ).
lv_block_cursor = 1.
lv_offset = 0.
WHILE lv_block_cursor <= lv_number_of_blocks.
APPEND INITIAL LINE TO et_raw16_table ASSIGNING <raw16>.
IF lv_block_cursor < lv_number_of_blocks.
<raw16> = i_data+lv_offset(mc_block_length_in_byte).
ELSE.
<raw16> = i_data+lv_offset.
ENDIF.
lv_block_cursor = lv_block_cursor + 1.
lv_offset = lv_offset + mc_block_length_in_byte.
ENDWHILE.
e_data_length_in_byte = lv_input_length.
ENDMETHOD. "convert_xstring_to_raw16_table
METHOD:ENCRYPT_RAW16_TABLE
METHOD encrypt_raw16_table.
DATA: rijndael TYPE REF TO zcl_rijndael_utility.
DATA: padding_utility TYPE REF TO zcl_byte_padding_utility.
DATA: aes_mode TYPE REF TO zif_aes_mode.
CLEAR et_data.
validate_encryption_mode(
i_encryption_mode = i_encryption_mode
i_initialization_vector = i_initialization_vector ).
validate_padding_standard( i_padding_standard ).
validate_raw16_table_size(
it_data = ct_data
i_data_length_in_byte = i_data_length_in_byte ).
rijndael = get_rijndael( i_key ).
padding_utility = get_padding_utility( i_padding_standard ).
aes_mode = get_aes_mode( i_encryption_mode ).
add_padding_raw16_table(
EXPORTING
i_data_length_in_byte = i_data_length_in_byte
io_padding_utility = padding_utility
CHANGING
ct_data = ct_data ).
aes_mode->encrypt_raw16_table(
EXPORTING
io_rijndael = rijndael
i_key = i_key
i_initialization_vector = i_initialization_vector
it_data = ct_data
IMPORTING
et_data = et_data ).
ENDMETHOD. "encrypt_raw16_table
METHOD:CONVERT_RAW16_TABLE_TO_XSTRING
METHOD convert_raw16_table_to_xstring.
DATA: lv_last_line_length TYPE int4.
FIELD-SYMBOLS: <raw16> TYPE zif_aes_mode=>ty_raw16.
CLEAR e_data.
IF i_data_length_in_byte <= 0.
RETURN.
ENDIF.
lv_last_line_length = ( i_data_length_in_byte - 1 ) MOD mc_block_length_in_byte + 1.
LOOP AT it_raw16_table ASSIGNING <raw16>.
AT LAST.
e_data = e_data && <raw16>(lv_last_line_length).
EXIT.
ENDAT.
e_data = e_data && <raw16>.
ENDLOOP.
ENDMETHOD. "convert_raw16_table_to_xstring
4. 解密方法DECRYPT_XSTRING
METHOD decrypt_xstring.
DATA: lt_plain_raw16 LIKE mt_raw16,
lt_cipher_raw16 LIKE mt_raw16,
lv_plain_length_in_byte TYPE int4.
CLEAR e_data.
convert_xstring_to_raw16_table(
EXPORTING
i_data = i_data
IMPORTING
et_raw16_table = lt_cipher_raw16 ).
decrypt_raw16_table(
EXPORTING
i_encryption_mode = i_encryption_mode
i_initialization_vector = i_initialization_vector
i_padding_standard = i_padding_standard
i_key = i_key
it_data = lt_cipher_raw16
IMPORTING
e_data_length_in_byte = lv_plain_length_in_byte
et_data = lt_plain_raw16 ).
convert_raw16_table_to_xstring(
EXPORTING
it_raw16_table = lt_plain_raw16
i_data_length_in_byte = lv_plain_length_in_byte
IMPORTING
e_data = e_data ).
ENDMETHOD. "decrypt_xstring
method:DECRYPT_RAW16_TABLE
METHOD decrypt_raw16_table.
DATA: rijndael TYPE REF TO zcl_rijndael_utility.
DATA: padding_utility TYPE REF TO zcl_byte_padding_utility.
DATA: aes_mode TYPE REF TO zif_aes_mode.
CLEAR et_data.
validate_encryption_mode(
i_encryption_mode = i_encryption_mode
i_initialization_vector = i_initialization_vector ).
validate_padding_standard( i_padding_standard ).
rijndael = get_rijndael( i_key ).
padding_utility = get_padding_utility( i_padding_standard ).
aes_mode = get_aes_mode( i_encryption_mode ).
aes_mode->decrypt_raw16_table(
EXPORTING
io_rijndael = rijndael
i_key = i_key
i_initialization_vector = i_initialization_vector
it_data = it_data
IMPORTING
et_data = et_data ).
remove_padding_raw16_table(
EXPORTING
io_padding_utility = padding_utility
IMPORTING
e_data_length_in_byte = e_data_length_in_byte
CHANGING
ct_data = et_data ).
ENDMETHOD. "DECRYPT_RAW16_TABLE
method: VALIDATE_ENCRYPTION_MODE
METHOD validate_encryption_mode.
IF i_encryption_mode = mc_encryption_mode_cbc
OR i_encryption_mode = mc_encryption_mode_pcbc
OR i_encryption_mode = mc_encryption_mode_cfb
OR i_encryption_mode = mc_encryption_mode_ofb
OR i_encryption_mode = mc_encryption_mode_ctr.
IF is_valid_iv_xstring( i_initialization_vector ) = abap_false.
RAISE EXCEPTION TYPE cx_me_illegal_argument
EXPORTING
name = 'I_INITIALIZATION_VECTOR'
value = 'Incorrect Initialization Vector length'.
ENDIF.
ELSEIF i_encryption_mode = mc_encryption_mode_ecb
OR i_encryption_mode IS INITIAL.
"Nothing, default is ECB mode
ELSE.
RAISE EXCEPTION TYPE cx_me_illegal_argument
EXPORTING
name = 'I_ENCRYPTION_MODE'
value = 'Incorrect Encryption Mode'.
ENDIF.
ENDMETHOD. "validate_encryption_mode
METHOD is_valid_iv_xstring.
DATA: iv_length_in_bit TYPE int4.
iv_length_in_bit = xstrlen( i_initialization_vector ) * zcl_rijndael_utility=>mc_factor_bit_byte.
IF iv_length_in_bit = mc_block_length_in_bit.
r_valid = abap_true.
ENDIF.
ENDMETHOD. "is_valid_iv_xstring
METHOD validate_padding_standard.
IF i_padding_standard IS NOT INITIAL AND
i_padding_standard <> zcl_byte_padding_utility=>mc_padding_standard_none AND
i_padding_standard <> zcl_byte_padding_utility=>mc_padding_standard_pkcs_5 AND
i_padding_standard <> zcl_byte_padding_utility=>mc_padding_standard_pkcs_7.
RAISE EXCEPTION TYPE cx_me_illegal_argument
EXPORTING
name = 'I_PADDING_STANDARD'
value = 'Unsupported padding standard'.
ENDIF.
ENDMETHOD. "validate_padding_standard
method:GET_RIJNDAEL
METHOD get_rijndael.
DATA: key_length_in_bit TYPE int4.
key_length_in_bit = xstrlen( i_key ) * zcl_rijndael_utility=>mc_factor_bit_byte.
IF key_length_in_bit = mc_key_length_in_bit_128.
IF mo_rijndael_128_128 IS NOT BOUND.
CREATE OBJECT mo_rijndael_128_128
EXPORTING
i_key_length_in_bit = mc_key_length_in_bit_128
i_block_length_in_bit = mc_block_length_in_bit.
ENDIF.
r_rajndael = mo_rijndael_128_128.
ELSEIF key_length_in_bit = mc_key_length_in_bit_192.
IF mo_rijndael_128_192 IS NOT BOUND.
CREATE OBJECT mo_rijndael_128_192
EXPORTING
i_key_length_in_bit = mc_key_length_in_bit_192
i_block_length_in_bit = mc_block_length_in_bit.
ENDIF.
r_rajndael = mo_rijndael_128_192.
ELSEIF key_length_in_bit = mc_key_length_in_bit_256.
IF mo_rijndael_128_256 IS NOT BOUND.
CREATE OBJECT mo_rijndael_128_256
EXPORTING
i_key_length_in_bit = mc_key_length_in_bit_256
i_block_length_in_bit = mc_block_length_in_bit.
ENDIF.
r_rajndael = mo_rijndael_128_256.
ELSE.
RAISE EXCEPTION TYPE cx_me_illegal_argument
EXPORTING
name = 'I_KEY'
value = 'Incorrect key length'.
ENDIF.
ENDMETHOD. "get_rijndael
method:GET_PADDING_UTILITY
METHOD get_padding_utility.
CASE i_padding_standard.
WHEN space OR zcl_byte_padding_utility=>mc_padding_standard_none.
IF mo_padding_utility_none IS NOT BOUND.
mo_padding_utility_none = zcl_byte_padding_utility=>get_byte_padding_utility( i_padding_standard ).
ENDIF.
r_padding_utility = mo_padding_utility_none.
WHEN zcl_byte_padding_utility=>mc_padding_standard_pkcs_5.
IF mo_padding_utility_pkcs_5 IS NOT BOUND.
mo_padding_utility_pkcs_5 = zcl_byte_padding_utility=>get_byte_padding_utility( i_padding_standard ).
ENDIF.
r_padding_utility = mo_padding_utility_pkcs_5.
WHEN zcl_byte_padding_utility=>mc_padding_standard_pkcs_7.
IF mo_padding_utility_pkcs_7 IS NOT BOUND.
mo_padding_utility_pkcs_7 = zcl_byte_padding_utility=>get_byte_padding_utility( i_padding_standard ).
ENDIF.
r_padding_utility = mo_padding_utility_pkcs_7.
ENDCASE.
ENDMETHOD. "get_padding_utility
method: GET_AES_MODE
I_ENCRYPTION_MODE TYPE CHAR10
value( R_AES_MODE ) TYPE REF TO ZIF_AES_MODE
METHOD get_aes_mode.
CASE i_encryption_mode.
WHEN space OR mc_encryption_mode_ecb.
IF mo_aes_mode_ecb IS NOT BOUND.
CREATE OBJECT mo_aes_mode_ecb TYPE zcl_aes_mode_ecb.
ENDIF.
r_aes_mode = mo_aes_mode_ecb.
WHEN mc_encryption_mode_cbc.
IF mo_aes_mode_cbc IS NOT BOUND.
CREATE OBJECT mo_aes_mode_cbc TYPE zcl_aes_mode_cbc.
ENDIF.
r_aes_mode = mo_aes_mode_cbc.
WHEN mc_encryption_mode_pcbc.
IF mo_aes_mode_pcbc IS NOT BOUND.
CREATE OBJECT mo_aes_mode_pcbc TYPE zcl_aes_mode_pcbc.
ENDIF.
r_aes_mode = mo_aes_mode_pcbc.
WHEN mc_encryption_mode_cfb.
IF mo_aes_mode_cfb IS NOT BOUND.
CREATE OBJECT mo_aes_mode_cfb TYPE zcl_aes_mode_cfb.
ENDIF.
r_aes_mode = mo_aes_mode_cfb.
WHEN mc_encryption_mode_ofb.
IF mo_aes_mode_ofb IS NOT BOUND.
CREATE OBJECT mo_aes_mode_ofb TYPE zcl_aes_mode_ofb.
ENDIF.
r_aes_mode = mo_aes_mode_ofb.
WHEN mc_encryption_mode_ctr.
IF mo_aes_mode_ctr IS NOT BOUND.
CREATE OBJECT mo_aes_mode_ctr TYPE zcl_aes_mode_ctr.
ENDIF.
r_aes_mode = mo_aes_mode_ctr.
ENDCASE.
ENDMETHOD. "get_aes_mode
method: REMOVE_PADDING_RAW16_TABLE
METHOD remove_padding_raw16_table.
DATA: lv_padding_length TYPE int4,
lv_last_line_number TYPE int4,
lv_line_before_padding TYPE xstring,
lv_line_after_padding TYPE xstring.
FIELD-SYMBOLS: <raw16> TYPE zif_aes_mode=>ty_raw16.
CLEAR e_data_length_in_byte.
lv_last_line_number = lines( ct_data ).
IF lv_last_line_number <= 0.
RETURN.
ENDIF.
READ TABLE ct_data INDEX lv_last_line_number ASSIGNING <raw16>.
lv_line_after_padding = <raw16>.
io_padding_utility->remove_padding(
EXPORTING
i_block_length_in_byte = mc_block_length_in_byte
i_data = lv_line_after_padding
IMPORTING
e_padding_length_in_byte = lv_padding_length
e_data = lv_line_before_padding ).
IF lv_line_before_padding IS INITIAL.
DELETE ct_data INDEX lv_last_line_number.
ELSE.
<raw16> = lv_line_before_padding.
ENDIF.
e_data_length_in_byte = lv_last_line_number * mc_block_length_in_byte - lv_padding_length.
ENDMETHOD. "remove_padding_raw16_table
5. 功能应用
AES加密秘钥配置
METHOD encrypt_data.
DATA:
lv_xstr_out TYPE xstring,
lv_xstr_key TYPE xstring,
lv_key TYPE string,
lv_xstr_in TYPE xstring,
lv_input TYPE string.
CLEAR: ev_encrypted.
IF iv_value IS INITIAL.
RETURN.
ENDIF.
lv_input = iv_value.
SELECT SINGLE sctky INTO lv_key FROM ztab_aes01
WHERE bssnr = 'FI1183'
AND isdel = abap_off.
IF sy-subrc <> 0.
IF sy-mandt <> '600'.
lv_key = 'mGaDFIZTfGSgNNdj'.
ELSE.
RETURN.
ENDIF.
ENDIF.
CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING'
EXPORTING
im_string = lv_input
IMPORTING
ex_xstring = lv_xstr_in.
CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING'
EXPORTING
im_string = lv_key
IMPORTING
ex_xstring = lv_xstr_key.
zcl_aes_utility=>encrypt_xstring(
EXPORTING
i_key = lv_xstr_key
i_data = lv_xstr_in
i_padding_standard = zcl_aes_utility=>mc_padding_standard_pkcs_7
i_encryption_mode = zcl_aes_utility=>mc_encryption_mode_ecb
IMPORTING
e_data = lv_xstr_out
).
CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
EXPORTING
input = lv_xstr_out
IMPORTING
output = ev_encrypted.
ENDMETHOD.
METHOD gen_wy_attach_url.
DATA:
lv_yxurl TYPE c LENGTH 1000,
lv_token TYPE c LENGTH 1000,
lv_encode TYPE savwctxt-fieldcont,
ls_ztfi1040_07 TYPE ztfi1040_07,
lv_token_str TYPE string,
lv_ts TYPE n LENGTH 14.
CLEAR: ev_url, es_return.
ls_ztfi1040_07-ywdnr = iv_ywdnr.
SELECT SINGLE ywdnr yxurl fi_type
INTO ( ls_ztfi1040_07-ywdnr, ls_ztfi1040_07-yxurl ,ls_ztfi1040_07-fi_type )
FROM ztfi1040_07
WHERE ywdnr = ls_ztfi1040_07-ywdnr.
IF sy-subrc <> 0 OR
ls_ztfi1040_07-yxurl IS INITIAL OR
ls_ztfi1040_07-yxurl = space.
* es_return-type = 'E'.
* es_return-message = '无附件信息'.
* RETURN.
SELECT SINGLE ywdnr yxurl fi_type
INTO ( ls_ztfi1040_07-ywdnr, ls_ztfi1040_07-yxurl,ls_ztfi1040_07-fi_type )
FROM ztfi1040_01
WHERE ywdnr = ls_ztfi1040_07-ywdnr.
IF sy-subrc <> 0 OR ls_ztfi1040_07-yxurl IS INITIAL OR
ls_ztfi1040_07-yxurl = space.
es_return-type = 'E'.
es_return-message = '无附件信息'.
RETURN.
ENDIF.
ENDIF.
lv_ts = sy-datum && sy-uzeit.
lv_token_str = lv_ts && |^_^| && ls_ztfi1040_07-yxurl.
me->encrypt_data(
EXPORTING
iv_value = lv_token_str
IMPORTING
ev_encrypted = lv_token_str
).
IF lv_token_str IS INITIAL.
es_return-type = 'E'.
es_return-message = '加密失败'.
RETURN.
ENDIF.
lv_encode = lv_token_str.
CALL FUNCTION 'WWW_URLENCODE'
EXPORTING
value = lv_encode
IMPORTING
value_encoded = lv_token.
lv_encode = ls_ztfi1040_07-yxurl.
CLEAR lv_yxurl.
CALL FUNCTION 'WWW_URLENCODE'
EXPORTING
value = lv_encode
IMPORTING
value_encoded = lv_yxurl.
CASE sy-mandt.
WHEN 600.
IF ls_ztfi1040_07-fi_type EQ 'WD1' OR ls_ztfi1040_07-fi_type EQ 'WD2' OR ls_ztfi1040_07-fi_type EQ 'WD3'.
ev_url = 'http://bf.xxxxservice.com/hscs/ap/land/rec/files/view'.
ELSE.
ENDIF.
WHEN OTHERS.
ev_url = 'http://10.0.xxx/hscs/ap/land/time/files/view'.
ENDCASE.
ev_url = ev_url && '?key=' && lv_yxurl && '&token=' && lv_token.
es_return-type = 'S'.
es_return-message = '附件页面URL获取成功'.
ENDMETHOD.