FUNCTION ZRFC_BC_SMSSEND_DINGTALK.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(DESTUSRID) TYPE CHAR255
*" VALUE(CONTENT) TYPE CHAR255
*" VALUE(SRC) TYPE CHAR50 OPTIONAL
*" EXPORTING
*" VALUE(STATUE) TYPE BAPI_MTYPE
*" VALUE(MESSTAB) TYPE BAPI_MSG
*"----------------------------------------------------------------------
DATA: LO_HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT,
LV_LEN TYPE I,
LV_SMSURL(200) TYPE C,
LV_RESPON TYPE STRING,
LV_SERVICE TYPE STRING,
LV_MSG TYPE STRING,
LV_CONTENT TYPE STRING,
HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT, "http客户端
LV_SERVER_NAME TYPE ZE_SERVER_NAME,
LV_SRC TYPE STRING,
DEST LIKE RFCDES-RFCDEST,
LJSONNODE TYPE REF TO ZCL_MDP_JSON_NODE,
L_SAP_COL_OBJECT TYPE REF TO ZCL_MDP_JSON_NODE,
LV_RESULTS TYPE STRING.
DATA: ITAB TYPE TABLE OF STRING.
DATA: P_CODE TYPE I,
P_REASON TYPE STRING.
SRC = 'SAPS4' && SY-SYSID && SRC.
*https://market.chinajack.com/index.php?receiver=8256&sender=admin&thirdpartyCode=1001&title=尊敬的用户:您好,您的SAP账户(8256)因输错密码多次被锁定,现已经解锁并初始化,密码是(Jk12345678),请妥善保管!&s=/w2/Maintenance/DingTalkSystem/sendMessage/
LV_CONTENT = CONTENT.
CALL METHOD CL_HTTP_UTILITY=>ESCAPE_URL
EXPORTING
UNESCAPED = LV_CONTENT
RECEIVING
ESCAPED = LV_CONTENT.
LV_SRC = SRC.
CALL METHOD CL_HTTP_UTILITY=>ESCAPE_URL
EXPORTING
UNESCAPED = LV_SRC
RECEIVING
ESCAPED = LV_SRC.
SELECT SINGLE VALUE INTO LV_SMSURL
FROM /THINKWAY/TBUS0P WHERE PPKEY = 'DINGURL' AND EXCHANGE_SYSTEM = 'SMS'.
* LV_SMSURL = '公司内部封装过的钉钉URL地址 '.
CONCATENATE 'http://' LV_SMSURL '/index.php?receiver=' DESTUSRID '&title='
LV_CONTENT '&thirdpartyCode=1001&sender=admin&s=/w2/Maintenance/DingTalkSystem/sendMessage/' INTO LV_SERVICE .
CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
EXPORTING
URL = LV_SERVICE
IMPORTING
CLIENT = HTTP_CLIENT
EXCEPTIONS
ARGUMENT_NOT_FOUND = 1
PLUGIN_NOT_ACTIVE = 2
INTERNAL_ERROR = 3
OTHERS = 4.
"设定传输请求内容格式以及编码格式
HTTP_CLIENT->REQUEST->SET_CONTENT_TYPE( CONTENT_TYPE = 'application/json; charset=utf-8' ).
"设置http method 为Get
HTTP_CLIENT->REQUEST->SET_METHOD( IF_HTTP_REQUEST=>CO_REQUEST_METHOD_POST ).
CALL METHOD HTTP_CLIENT->SEND
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3
HTTP_INVALID_TIMEOUT = 4
OTHERS = 5.
"接收
CALL METHOD HTTP_CLIENT->RECEIVE
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3.
"提取返回字符串
LV_RESULTS = HTTP_CLIENT->RESPONSE->GET_CDATA( ).
DATA: L_JSON_ROOT_OBJECT TYPE REF TO ZCL_MDP_JSON_NODE.
LJSONNODE = ZCL_MDP_JSON_NODE=>DESERIALIZE( JSON = LV_RESULTS ).
L_SAP_COL_OBJECT = LJSONNODE->OBJECT_GET_CHILD_NODE( KEY = 'success' ).
IF L_SAP_COL_OBJECT->VALUE EQ 1.
STATUE = 'S'.
ELSE.
STATUE = 'E'.
ENDIF.
ENDFUNCTION.
有了这个,可以减少这种低级损耗