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.

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

相关推荐
小华同学ai4 小时前
wflow-web:开源啦 ,高仿钉钉、飞书、企业微信的审批流程设计器,轻松打造属于你的工作流设计器
前端·钉钉·飞书
qq_344403452 天前
钉钉内集成第三方免密登录(Vue+.Net)
钉钉
市象2 天前
钉钉向广告低头
互联网·钉钉·企业办公
国通快递驿站3 天前
AntFlow一款开源免费且自主可控的仿钉钉工作流引擎
开源·钉钉·antflow
Dark_programmer3 天前
uni-app - - - - - 钉钉小程序 uni.showToast回调函数不执行问题(PC端钉钉小程序 接口API回调函数不执行)
小程序·uni-app·钉钉
weixin_449310846 天前
利用钉钉与金蝶云星空进行付款单自动化集成
运维·自动化·钉钉
CL_IN7 天前
钉钉日常报销单与金蝶云星空集成技术详解
前端·数据库·钉钉
猫姐°7 天前
python实现钉钉群机器人消息通知(消息卡片)
python·机器人·钉钉
凉风听雪8 天前
钉钉平台开发小程序
小程序·钉钉·开发者工具
大风起兮云飞扬丶8 天前
钉钉接入自定义机器人
机器人·钉钉