使用HTTP协议的都可以参考,如快递接口等。
注意如果连接不成功,可能是因为系统没有配置DNS,不能上网导致不能连接成功。
参考:https://archive.sap.com/discussions/thread/535031
TYPES:BEGIN OF tp_title,
funnam TYPE char20,
dattyp TYPE c,
lgnnam TYPE char20,
END OF tp_title.
TYPES: BEGIN OF tp_payqx,
buscod TYPE c,
busmod TYPE c,
modals TYPE c,
END OF tp_payqx.
TYPES: BEGIN OF tp_paydtx,
yurref TYPE c,
eptdat TYPE c,
epttim TYPE c,
dbtacc TYPE c,
dbtbbk TYPE c,
c_dbtbbk TYPE c,
trsamt TYPE c,
ccynbr TYPE c,
c_ccynbr TYPE c,
stlchn TYPE c,
c_stlchn TYPE c,
nusage TYPE c,
busnar TYPE c,
crtacc TYPE c,
crtnam TYPE c,
brdnbr TYPE c,
crtbnk TYPE c,
ctycod TYPE c,
crtpvc TYPE c,
crtcty TYPE c,
crtdtr TYPE c,
ntfch1 TYPE c,
ntfch2 TYPE c,
crtsqn TYPE c,
END OF tp_paydtx.
TYPES: BEGIN OF tp_body,
funnam TYPE char20,
dattyp TYPE c,
lgnnam TYPE char20,
buscod TYPE c,
busmod TYPE c,
modals TYPE c,
yurref TYPE c,
eptdat TYPE c,
epttim TYPE c,
dbtacc TYPE c,
dbtbbk TYPE c,
c_dbtbbk TYPE c,
trsamt TYPE c,
ccynbr TYPE c,
c_ccynbr TYPE c,
stlchn TYPE c,
c_stlchn TYPE c,
nusage TYPE c,
busnar TYPE c,
crtacc TYPE c,
crtnam TYPE c,
brdnbr TYPE c,
crtbnk TYPE c,
ctycod TYPE c,
crtpvc TYPE c,
crtcty TYPE c,
crtdtr TYPE c,
ntfch1 TYPE c,
ntfch2 TYPE c,
crtsqn TYPE c,
END OF tp_body.
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA:
it_dbcon TYPE dbcon OCCURS 0,
wa_dbcon TYPE dbcon.
DATA: http_client TYPE REF TO if_http_client,
lv_xstring TYPE xstring,
lv_string TYPE string,
v_string TYPE string,
return_str TYPE string.
DATA: proxy_host TYPE string VALUE '172.27.70.66' ,
proxy_port TYPE string VALUE '8080',
proxy_user TYPE string ,
proxy_pass TYPE string .
DATA: len TYPE i.
CONSTANTS:
* C_T01 TYPE STRING VALUE
* '<?xml version = "1.0" encoding = "GB2312"?>',
* C_T02 TYPE STRING VALUE
* '<bocb2e version="100" security="true" lang="chs">',
c_t01 TYPE string VALUE
'<?xml version="1.0" encoding = "GBK"?>',
c_t03 TYPE string VALUE '</bocb2e>'.
LOOP AT zttr_eppk INTO zttr_eppk.
CONCATENATE c_t01
'<CMBSDKPGK>'
'<INFO>'
'<FUNNAM>' 'Payment' '</FUNNAM>'
'<DATTYP>' '2' '</DATTYP>'
'<LGNNAM>' 'ZL01' '</LGNNAM>'
'</INFO>'
'<SDKPAYRQX>'
'<BUSCOD>' 'N02031' '</BUSCOD>'
'<BUSMOD>' '00001' '</BUSMOD>'
'</SDKPAYRQX>'
'<SDKPAYDTX>'
'<YURREF>' zttr_eppk-yurref '</YURREF>'
'<EPTDAT>' zttr_eppk-eptdat '</EPTDAT>'
'<EPTTIM>' zttr_eppk-epttim '</EPTTIM>'
'<DBTACC>' zttr_eppk-dbtacc '</DBTACC>'
'<C_DBTBBK>' zttr_eppk-c_dbtbbk '</C_DBTBBK>'
* '<TRSAMT>' zttr_eppk-trsamt '</TRSAMT>'
'<C_CCYNBR>' zttr_eppk-ccynbr '</C_CCYNBR>'
'<C_STLCHN>' zttr_eppk-c_ccynbr '</C_STLCHN>'
'<NUSAGE>' zttr_eppk-nusage '</NUSAGE>'
'<CRTACC>' zttr_eppk-crtacc '</CRTACC>'
'<CRTNAM>' zttr_eppk-crtnam '</CRTNAM>'
'<CRTBNK>' zttr_eppk-crtbnk '</CRTBNK>'
'<CRTPVC>' zttr_eppk-crtpvc '</CRTPVC>'
'<CRTCTY>' zttr_eppk-crtcty '</CRTCTY>'
'<CRTSQN>' zttr_eppk-oprlgn '</CRTSQN>'
'</SDKPAYDTX>'
'</CMBSDKPGK>'
INTO v_string.
ENDLOOP.
*----------------------------------------------------------------------*
* Deal with layout format to xml *
*----------------------------------------------------------------------*
SELECT *
INTO CORRESPONDING FIELDS OF TABLE it_dbcon
FROM dbcon
WHERE con_name = connect.
IF sy-subrc = 0.
READ TABLE it_dbcon INTO wa_dbcon WITH KEY con_name = connect.
IF sy-subrc <> 0.
MESSAGE 'ERROR ' TYPE 'E'.
ENDIF.
ENDIF.
CALL METHOD cl_http_client=>create
EXPORTING
host = '172.0.0.1'
service = '8080'
proxy_host = '172.0.0.1'
proxy_service = '8080'
scheme = '1'
* ssl_id =
* sap_username =
* sap_client =
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
len = STRLEN( v_string ).
http_client->propertytype_logon_popup = http_client->co_enabled .
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
CALL METHOD http_client->request->set_cdata
EXPORTING
data = v_string
offset = 0
length = len.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
CLEAR return_str.
return_str = http_client->response->get_cdata( ).
CONDENSE return_str NO-GAPS.
CALL METHOD http_client->close.