Java教程

SAP 银企直连 通过 Http Get 方式下载交易明细文件

本文主要是介绍SAP 银企直连 通过 Http Get 方式下载交易明细文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!


前言

SAP 银企直连,农业银行查询接口交易明细会生成固定格式的文本文件到前置机上面。
可以通过Http Get 方式下载。


提示:以下是本篇文章正文内容,下面案例可供参考

一、接口说明与核心代码

<?xml version="1.0" encoding="utf-8"?>
<ap>
  <CCTransCode>CQRA10</CCTransCode>
  <Corp>
    <StartDate>起始日期</StartDate>
    <EndDate>终止日期</EndDate>
  </Corp>
  <Channel>
    <LastJrnNo>0</LastJrnNo>
  </Channel>
  <Cmp>
    <DbAccNo>借方账号</DbAccNo>
    <DbProv>借方省市代码</DbProv>
    <DbCur>借方货币号</DbCur>
    <StartTime>末笔时间戳</StartTime>
  </Cmp>
</ap>
<?xml version="1.0" encoding="utf-8"?>
<ap>
  <Cme>
    <RecordNum>记录总数</RecordNum>
    <FieldNum>字段数</FieldNum>
  </Cme>
  <Cmp>
    <DbAccNo>借方账号</DbAccNo>
    <DbProv>借方省市代码</DbProv>
    <DbCur>借方货币号</DbCur>
    <BatchFileName>文件名</BatchFileName>
  </Cmp>
</ap>




下载文件:
账户明细文件信息 (文件名如上BatchFileName所示)
格式如下(MFS):
Prov|AccNo|Cur|TrDate|TimeStab|TrJrn|TrType|TrBankNo|AccName|AmtIndex|OppProv|OppAccNo|OppCur|OppName|OppBkName|CshIndex|ErrDate|ErrVchNo|Amt|Bal|PreAmt|TotChg|VoucherType|VoucherProv|VoucherBat|VoucherNo|CustRef|TransCode|Teller|VchNo|Abs|PostScript|TrFrom|
中文含义(附字典翻译):
省市代码|账号|货币码|交易日期|交易时间|日志号|交易类型|交易行号|户名|发生额标志|对方账号省市代码|对方账号|对方账号货币码|对方账号户名|对方账号开户行|现转标志|错账日期|错账传票号|交易金额|账户余额|上笔余额|手续费总额|凭证种类|凭证省市代号|凭证批次号|凭证号|客户参考号|交易码|柜员号|传票号|摘要|附言|交易来源|
注:返回的账户明细文件中不包含以上字段名。

  METHOD GET_FILE.
    DATA lv_rfc_name TYPE string.
    DATA lv_rfc_option TYPE string.
    DATA lv_host TYPE string.
    DATA lv_port TYPE string.
    DATA lv_uri TYPE string.
    DATA lv_file_xstring TYPE xstring.
    DATA lv_http_status TYPE i.

    mo_abc_ghtd_serv_cntr->get_rfc_name(
      EXPORTING
        is_bank_comm_key =  is_bank_comm_key
      IMPORTING
        ev_rfc_name      = lv_rfc_name
    ).

    IF lv_rfc_name is INITIAL.
      DATA lt_message type STANDARD TABLE OF bal_s_msg.
      DATA ls_message TYPE bal_s_msg.
      DATA lv_message_dummy TYPE string.

      MESSAGE e026(epic_example_cn_impl) INTO lv_message_dummy.
      CLEAR ls_message.
      MOVE-CORRESPONDING sy TO ls_message.
      APPEND ls_message TO lt_message.
      RAISE EXCEPTION TYPE cx_epic_bank_comm_impl
        EXPORTING
          impl_messages  = lt_message.
    ENDIF.

    mo_abc_ghtd_serv_cntr->get_connection_option(
      EXPORTING
        iv_rfc_name           =  lv_rfc_name
      IMPORTING
        ev_connection_option = lv_rfc_option
    ).

    resolve_host_port_from_option(
      EXPORTING
        iv_rfc_option = lv_rfc_option
      IMPORTING
        ev_host       = lv_host
        ev_port       = lv_port
    ).

    CONCATENATE gc_file_server_prefix iv_file_name INTO lv_uri.
    mo_abc_ghtd_serv_cntr->download_file(
      EXPORTING
        iv_host     = lv_host
        iv_port     = lv_port
        iv_uri      = lv_uri
        iv_protocol = 'HTTP/1.0'
      IMPORTING
        ev_file_xstring     = lv_file_xstring
        ev_http_status      = lv_http_status
    ).
    IF lv_http_status <> 200.

      CLEAR lt_message.
      CLEAR ls_message.
      CLEAR lv_message_dummy.

      MESSAGE e025(epic_example_cn_impl)  INTO lv_message_dummy.
      CLEAR ls_message.
      MOVE-CORRESPONDING sy TO ls_message.
      APPEND ls_message TO lt_message.
      RAISE EXCEPTION TYPE cx_epic_bank_comm_impl
        EXPORTING
          impl_messages  = lt_message.

    ENDIF.
    cl_abap_codepage=>convert_from(
         EXPORTING
           source                        = lv_file_xstring
           codepage                      = `GBK`
         RECEIVING
           result                        = ev_file
     ).

    REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf(1) IN ev_file WITH ''.
    REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf+1(1) IN ev_file WITH ''.

  ENDMETHOD.
  METHOD if_epic_abc_http_service~download_file_through_get.
    DATA: lo_client TYPE REF TO if_http_client.
    DATA lv_xstring TYPE xstring.

    DATA: errortext TYPE string.
    DATA lv_file_string TYPE string.
    DATA lv_file_xstring TYPE xstring.

    create_http_client(
      EXPORTING
        iv_host    = iv_host
        iv_service = iv_service
      IMPORTING
        eo_client  = lo_client
    ).

    CALL METHOD lo_client->request->set_method
      EXPORTING
        method = if_http_request=>co_request_method_get.

    CALL METHOD set_version_uri
      EXPORTING
        iv_protocol = iv_protocol
        iv_uri      = iv_uri
      CHANGING
        co_client   = lo_client.

    IF  iv_request_body IS NOT INITIAL.
      CALL METHOD set_request_body
        EXPORTING
          iv_body_xstring = iv_request_body
        changing
          co_client       = lo_client.

    ENDIF.

    CALL METHOD http_send
      EXPORTING
        iv_timeout = 2000
      changing
        co_client  = lo_client.

    CALL METHOD receive_data
      IMPORTING
        ev_file_xstring = ev_file_xstring
        ev_file_string = ev_file_string
        ev_http_status  = ev_http_status
      CHANGING
        co_client = lo_client.

    CALL METHOD http_close
      CHANGING
        co_client = lo_client.

  ENDMETHOD.

 


总结

另外也可以在前置机安装FTP服务器,通过FTP读取文件也很方便。

这篇关于SAP 银企直连 通过 Http Get 方式下载交易明细文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!