第一步:企业微信群聊中添加机器人
第二步:将创建好的机器人webhook地址记住然后编写T100 代码
PUBLIC FUNCTION cs_efcli_post_qywx()
DEFINE l_http_req com.HTTPRequest
DEFINE l_http_resp com.HTTPResponse
DEFINE l_status_code STRING
DEFINE l_err_msg STRING
DEFINE l_msgtype util.JSONObject
DEFINE l_response_str STRING
DEFINE l_request STRING
DEFINE l_url STRING
DEFINE l_key LIKE wssbuc_t.wssbuc004
DEFINE l_json_arr util.JSONArray
DEFINE l_json_arr_data util.JSONArray
DEFINE l_msgtext util.JSONObject
DEFINE l_response RECORD
errcode LIKE type_t.num5,
errmsg STRING
END RECORD
DEFINE r_success LIKE type_t.num5
LET r_success =TRUE
LET l_key= NULL
LET l_key= "自己企业微信机器人KEY"
LET l_url= "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=",l_key
LET l_http_req = com.HTTPRequest.Create(l_url)
CALL l_http_req.setMethod("POST")
--CALL l_http_req.setCharset("UTF-8")
CALL l_http_req.setHeader("Content-Type","application/json")
LET l_msgtype = util.JSONObject.create()
CALL l_msgtype.put("msgtype","text") #文本类型
LET l_msgtext = util.JSONObject.create()
CALL l_msgtext.put("content","Hi1234567890") #发送的信息
CALL l_msgtype.put("text",l_msgtext)
#將request送出
LET l_request = l_msgtype.tostring()
CALL l_http_req.doTextRequest(l_request)
LET l_http_resp = l_http_req.getResponse()
#180316-00024#1 By 10167-----(S)
LET l_status_code = l_http_resp.getStatusCode()
CASE l_status_code
WHEN 200
LET l_response_str = l_http_resp.getTextResponse()
DISPLAY "Success Response:",l_response_str
CALL util.JSON.parse(l_response_str,l_response)
IF l_response.errcode = 0 THEN
LET r_success = TRUE
ELSE
LET r_success = FALSE
END IF
--LET r_success = TRUE
WHEN 401
LET l_err_msg = "ERROR : ",l_status_code," Token expired, please regain new token."
DISPLAY "Error Message:",l_err_msg
LET r_success = FALSE
WHEN 406
LET l_err_msg = "ERROR : ",l_status_code," The token is abnormal and cannot continue operation."
DISPLAY "Error Message:",l_err_msg
LET r_success = FALSE
WHEN 500
LET l_err_msg = "ERROR : ",l_status_code," Internal exception."
DISPLAY "Error Message:",l_err_msg
LET r_success = FALSE
WHEN 503
LET l_err_msg = "ERROR : ",l_status_code,
" Unable to connect to the database. Please check if the connection string or database is abnormal."
DISPLAY "Error Message:",l_err_msg
LET r_success = FALSE
OTHERWISE
LET l_status_code = l_http_resp.getStatusCode()
LET l_err_msg = "Some error occured in the HTTP communication : "
|| l_status_code ,
", Description:", l_http_resp.getStatusDescription()
DISPLAY "Error Message:",l_err_msg
LET r_success = FALSE
END CASE
RETURN r_success
END FUNCTION
第三步 调用成功