SAP EPIC 银企直连大部分银行用的是Http 接口,可以直接在SM59中创建?到外部服务器的HTTP连接即可与银行前置机通信,快速进行银企直连接口开发。
少部分银行用的是Socket (农业银行,南京银行等),这时有2种方式:
- JAVA 把Socket 封装成Http,然后ABAP调用;
- ABAP直接调用Socket;
可根据项目实际情况灵活选择。一般情况建议采用SAP标准的EPIC 银企直连解决方案,稳定可靠,开发工作量少,大大降低实施成本。
1.3.1关于通讯方式 ERP与ICT之间的交易数据包都采用TCP/IP协议的Socket同步短连接方式。 Socket 方式中报文结构为“包头+数据包”。包头固定为7个字节长,第1字节为是否加密标志(0-不加密,1-加密)。后6个字节是数据包的长度,即将报文长度直接转为字符串存储,长度不足6位则右边用空格补足,比如:“1234 ?”。比如汇兑的长度为1234字节的数据包,其包头为“01234 ?”共7位,其中数据包长度包含加密包标志位。由于加密需要双方约定专门的加密算法,因此一般ERP送的加密标志都为0-不加密。
WebSocket Communication with ABAP Push Channel using Text Messages?
Open WebSocket?
Send message to APC ? ?
Close WebSocket?
?If the form field amc of the URL contains "x", an opened WebSocket receives text messages from the ABAP Messaging Channel DEMO_AMC. ?Such messages are then sent in the APC handler class but can also be sent by program DEMO_SEND_AMC. ?The program DEMO_RECEIVE_AMC can receive text messages sent by the APC handler class.?
?If you send the message get handle, you will receive the connection attach handle of the APC-server.?
REPORT demo_apc_tcp_client.
CLASS apc_handler DEFINITION FINAL .
PUBLIC SECTION.
INTERFACES if_apc_wsp_event_handler.
DATA message TYPE string.
ENDCLASS.
CLASS apc_handler IMPLEMENTATION.
METHOD if_apc_wsp_event_handler~on_open.
ENDMETHOD.
METHOD if_apc_wsp_event_handler~on_message.
TRY.
message = i_message->get_text( ).
CATCH cx_apc_error INTO DATA(apc_error).
message = apc_error->get_text( ).
ENDTRY.
ENDMETHOD.
METHOD if_apc_wsp_event_handler~on_close.
message = 'Connection closed!'.
ENDMETHOD.
METHOD if_apc_wsp_event_handler~on_error.
ENDMETHOD.
ENDCLASS.
CLASS apc_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS apc_demo IMPLEMENTATION.
METHOD main.
DATA(tcp_server) = `C:\ncat\ncat.exe`.
DATA(ip_adress) = cl_gui_frontend_services=>get_ip_address( ).
DATA(port) = `12345`.
DATA(terminator) = `0A`.
DATA(msg) = `Hello TCP, answer me!`.
cl_demo_input=>new(
)->add_text(
`For the TCP server, download the freely available NCAT.EXE`
)->add_field( CHANGING field = tcp_server
)->add_field( CHANGING field = ip_adress
)->add_field( CHANGING field = port
)->add_field( CHANGING field = terminator
)->add_field( CHANGING field = msg
)->request( ).
"Server
IF cl_gui_frontend_services=>file_exist(
file = tcp_server ) IS INITIAL.
cl_demo_output=>display( 'TCP Server not found!' ).
LEAVE PROGRAM.
ENDIF.
cl_gui_frontend_services=>execute(
EXPORTING
application = `cmd.exe`
parameter = `/c ` && tcp_server &&
` -l ` && ip_adress && ` -p ` && port ).
WAIT UP TO 1 SECONDS.
TRY.
DATA(event_handler) = NEW apc_handler( ).
"Client
DATA(client) = cl_apc_tcp_client_manager=>create(
i_host = ip_adress
i_port = port
i_frame = VALUE apc_tcp_frame(
frame_type =
if_apc_tcp_frame_types=>co_frame_type_terminator
terminator =
terminator )
i_event_handler = event_handler ).
client->connect( ).
"Send mesasage from client
DATA(message_manager) = CAST if_apc_wsp_message_manager(
client->get_message_manager( ) ).
DATA(message) = CAST if_apc_wsp_message(
message_manager->create_message( ) ).
DATA(binary_terminator) = CONV xstring( terminator ).
DATA(binary_msg) =
cl_abap_conv_codepage=>create_out( )->convert( msg ).
CONCATENATE binary_msg binary_terminator
INTO binary_msg IN BYTE MODE.
message->set_binary( binary_msg ).
message_manager->send( message ).
"Wait for a message from server
CLEAR event_handler->message.
WAIT FOR PUSH CHANNELS
UNTIL event_handler->message IS NOT INITIAL
UP TO 10 SECONDS.
IF sy-subrc = 4.
cl_demo_output=>display(
'No handler for APC messages registered!' ).
ELSEIF sy-subrc = 8.
cl_demo_output=>display(
'Timeout occurred!' ).
ELSE.
cl_demo_output=>display(
|TCP client received:\n\n{ event_handler->message }| ).
ENDIF.
client->close(
i_reason = 'Application closed connection!' ).
CATCH cx_apc_error INTO DATA(apc_error).
cl_demo_output=>display( apc_error->get_text( ) ).
ENDTRY.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
apc_demo=>main( ).
?
<ap>
<CCTransCode>交易代码</CCTransCode>
<ProductID>产品标识</ProductID>
<ChannelType>渠道标识</ChannelType>
<CorpNo>企业技监局代码/客户号</CorpNo>
<OpNo>企业操作员编号</OpNo>
<AuthNo>认证码</AuthNo>
<ReqSeqNo>请求方流水号</ReqSeqNo>
<ReqDate>请求日期</ReqDate>
<ReqTime>请求时间</ReqTime>
<Sign>数字签名</Sign>
<FileFlag>文件标识</FileFlag>
<Corp>
<StartDate>起始日期</StartDate>
<EndDate>终止日期</EndDate>
</Corp>
<Channel>
<LastJrnNo>0</LastJrnNo>
</Channel>
<Cmp>
<DbAccNo>账号</DbAccNo>
<DbProv>省市代码</DbProv>
<DbCur>货币号</DbCur>
<StartTime>末笔时间戳</StartTime>
</Cmp>
</ap>
<ap>
<CCTransCode>CQRA10</CCTransCode>
<ProductID>ICC</ProductID>
<ChannelType>ERP</ChannelType>
<CorpNo>00000035</CorpNo>
<OpNo>0011</OpNo>
<AuthNo/>
<ReqSeqNo>2021042211375856</ReqSeqNo>
<ReqDate>20210422</ReqDate>
<ReqTime>193758</ReqTime>
<Sign/>
<FileFlag/>
<Corp>
<StartDate>20210401</StartDate>
<EndDate>20210421</EndDate>
</Corp>
<Channel>
<LastJrnNo>0</LastJrnNo>
</Channel>
<Cmp>
<DbAccNo>0023649</DbAccNo>
<DbProv>15</DbProv>
<DbCur>01</DbCur>
<StartTime/>
</Cmp>
</ap>
|