1.se24 IF_HTTP_EXTENSION 创建类
*---获取 调用方法 GET or post
DATA(lv_method) = server->request->get_method( ).
CASE lv_method.
WHEN 'GET'.
me->get( server ).
WHEN 'POST'.
me->post( server ).
WHEN OTHERS.
server->response->set_status( CODE = 405 reason = '请求方法不支持,请联系管理员' ).
ENDCASE.
METHOD post.
TYPES:BEGIN OF ty_detaillist,
amount(8) TYPE p DECIMALS 2, "不含税金额
taxamount(8) TYPE p DECIMALS 2, "税额
id TYPE string, "id
END OF ty_detaillist.
DATA :BEGIN OF odata,
invoicecode TYPE string, "发票代码
invoiceno TYPE string, "发票号码
invoicedrewdate TYPE date, "开票日期
amount(8) TYPE p DECIMALS 2, "不含税金额
taxamount(8) TYPE p DECIMALS 2, "税额
amountwithtax(8) TYPE p DECIMALS 2, "价税合计
checkcode TYPE string, "校验码
invoicestatus TYPE integer, "发票状态
pdfurl TYPE string, "PDF地址
externaldocumentno TYPE string, "流水号
detaillist TYPE TABLE OF ty_detaillist,
END OF odata,
BEGIN OF odata1,
code TYPE string,
message TYPE string,
serialno TYPE string,
data LIKE odata,
END OF odata1,
BEGIN OF ls_request,
businesstype TYPE string,
data TYPE string,
END OF ls_request,
e_msg TYPE zrtbc010_s,
lv_json TYPE string,
lt_msg TYPE TABLE OF bapiret2,
ls_msg TYPE bapiret2,
ls_stru TYPE zrtfi123_s,
i_itab TYPE zrtfitt123a,
ls_itab TYPE LINE OF zrtfitt123a,
i_itab1 TYPE zrtfitt123b,
ls_itab1 TYPE LINE OF zrtfitt123b,
lv_num(6) TYPE n.
*&------获取body
lv_json = server->request->get_cdata( ).
IF lv_json IS INITIAL.
server->response->set_status(
EXPORTING
code = 404 " HTTP status code
reason = '未解析到Body参数,请检查' " HTTP status description
).
RETURN.
ENDIF.
REPLACE ALL OCCURRENCES OF '-' IN lv_json WITH ''.
*&------将JSON转换成内表
/ui2/cl_json=>deserialize(
EXPORTING
json = lv_json
CHANGING
data = ls_request
).
/ui2/cl_json=>deserialize(
EXPORTING
json = ls_request-data
CHANGING
data = odata1
).
*&------内表逻辑处理 strat-------
IF odata1-code = '200'.
*--------------ls_stru
ls_stru-zlsdbh = odata1-data-externaldocumentno. "流水单编号
*------------i_itab
ls_itab-zinvcode = odata1-data-invoicecode. "发票代码(全电没有)
ls_itab-zinvno = odata1-data-invoiceno. "发票号码
ls_itab-zinvdate = odata1-data-invoicedrewdate+0(8). "开票日期
ls_itab-zinvtotalprice = odata1-data-amount. "不含税金额
ls_itab-zinvtotaltax = odata1-data-taxamount. "税额
ls_itab-zinvtotalpricetax = odata1-data-amountwithtax. "价税合计
ls_itab-zjym = odata1-data-checkcode. "校验码(全电没有)
"税控码(taxCode)技术文档中:历史废弃字段,对接时无需处理
"二维码(ZEWM)技术文档没找到
IF odata1-data-invoicestatus = '10'.
ls_itab-zfpzt = '0'.
ELSEIF odata1-data-invoicestatus = '20'.
ls_itab-zfpzt = '4'.
ELSEIF odata1-data-invoicestatus = '30'.
ls_itab-zfpzt = '2'.
ENDIF.
* ls_itab-zfpzt = odata1-data-invoicestatus. "发票状态
ls_itab-zpdfurl = odata1-data-pdfurl. "fdf地址
APPEND ls_itab TO i_itab.
CLEAR:ls_itab.
*----------i_itab1
ls_itab1-zinvno = odata1-data-invoiceno. "发票号码
LOOP AT odata1-data-detaillist INTO DATA(ls_detaillist).
lv_num = lv_num + 1.
ls_itab1-buzei = lv_num. "发票凭证中的凭证项目
ls_itab1-zgdtotalprice = ls_detaillist-amount. "金额
ls_itab1-zgdtotaltax = ls_detaillist-taxamount. "税额
ls_itab1-zddmxxh = ls_detaillist-id. "订单明细ID
APPEND ls_itab1 TO i_itab1.
ENDLOOP.
CLEAR:ls_itab1,lv_num.
*---------
CALL FUNCTION 'Z_RTFI_XXFP_RECEIVE_INVOICE'
EXPORTING
i_stru = ls_stru
i_itab = i_itab
i_itab1 = i_itab1
IMPORTING
e_msg = e_msg.
IF e_msg-type = 'S'.
"将返回消息转成json返回回去
ls_msg-type = 'S'.
ls_msg-message = 'Success'.
ELSE.
"将返回消息转成json返回回去
ls_msg-type = 'E'.
ls_msg-message = e_msg-message.
ENDIF.
ELSE.
"将返回消息转成json返回回去
ls_msg-type = 'E'.
ls_msg-message = 'code<>200'.
ENDIF .
APPEND ls_msg TO lt_msg.
CLEAR:ls_msg.
*&------内表逻辑处理 end---------
server->response->set_cdata(
/ui2/cl_json=>serialize(
data = lt_msg
compress = abap_true "返回参数为空的情况就不展示
pretty_name = 'X' "大写:'' 小写:'L' 遇到下划线得第一个字母变大写,并且下划线消失,其他情况是小写:'X'
) ).
*&----设置成功得返回状态
server->response->set_status(
EXPORTING
code = 200 " HTTP status code
reason = 'OK' " HTTP status description
).
*------设置返回参数排列形式 [{"type":"S","message":"Success"}] 这种返回形式看着不方便
server->response->set_content_type( content_type = 'application/json;charset=UTF-8' ).
*&[
*&{
*&"type": "S",
*&"message": "Success"
*&}
*&]
ENDMETHOD.
2.sicf配置生成UIL