ABAP 借助公司封装的钉钉URL,封装的RFC给钉钉发送消息

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.

有了这个,可以减少这种低级损耗

相关推荐
LKID体2 天前
调用钉钉接口发送消息
钉钉
小俱的一步步2 天前
钉钉自定义机器人发送群消息(加签方式、http发送)
机器人·钉钉
ZJL-阿友6 天前
go语言 爬虫 钉钉群机器人
爬虫·golang·钉钉·钉钉群机器人
AI_NEW_COME7 天前
超越飞书钉钉:探索高效内部知识库平替方案与应用
人工智能·钉钉·飞书
CL_IN7 天前
高效数据集成:钉钉与企业系统无缝对接
java·前端·钉钉
nVisual10 天前
nVisual关于钉钉小程序打开项目及调试说明
小程序·钉钉·nvisual
inter_peng11 天前
[工具升级问题] 钉钉(linux版)升级带来的小麻烦
linux·运维·钉钉
国通快递驿站21 天前
AntFlow 0.20.0版发布,增加多数据源多租户支持,进一步助力企业信息化,SAAS化
java·spring boot·后端·开源·钉钉
蒙特网站1 个月前
钉钉与企业微信机器人:助力网站定时任务高效实现
机器人·钉钉·企业微信
Viktor_Ye1 个月前
实现金蝶云星空与钉钉数据无缝集成的技术方法
java·大数据·钉钉