
-define(DINGDING_ROBOT_URL, "https://oapi.dingtalk.com/robot/send?access_token=xxxx").
-define(DINGDING_SECURT, "yyy").
notify_robot() ->
Timestamp = 1701656608,
Sign = get_sign(Timestamp),
Url = lists:concat([?DINGDING_ROBOT_URL, "×tamp=", Timestamp, "&sign=", Sign]),
Header = [],
Type = "application/json",
Body = "",
Options = [],
case catch httpc:request(post, {Url, Header, Type, Body}, [{timeout, 3000}], Options) of
{ok, {_, _, Data}} ->
ok;
_Res ->
ok
end.
get_sign(Timestamp) ->
SecStr = lists:concat([Timestamp, "\n", ?DINGDING_SECURT]),
HMac256 = crypto:hmac(sha256, ?DINGDING_SECURT, SecStr),
Base64 = base64:encode(HMac256),
edoc_lib:escape_uri(binary_to_list(Base64)).