You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

  1. #!/usr/bin/env sh
  2. #Support weixin work webhooks api
  3. #WEIXIN_WORK_WEBHOOK="xxxx"
  4. #optional
  5. #WEIXIN_WORK_KEYWORD="yyyy"
  6. #`WEIXIN_WORK_SIGNING_KEY`="SEC08ffdbd403cbc3fc8a65xxxxxxxxxxxxxxxxxxxx"
  7. # subject content statusCode
  8. weixin_work_send() {
  9. _subject="$1"
  10. _content="$2"
  11. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  12. _debug "_subject" "$_subject"
  13. _debug "_content" "$_content"
  14. _debug "_statusCode" "$_statusCode"
  15. WEIXIN_WORK_WEBHOOK="${WEIXIN_WORK_WEBHOOK:-$(_readaccountconf_mutable WEIXIN_WORK_WEBHOOK)}"
  16. if [ -z "$WEIXIN_WORK_WEBHOOK" ]; then
  17. WEIXIN_WORK_WEBHOOK=""
  18. _err "You didn't specify a weixin_work webhooks WEIXIN_WORK_WEBHOOK yet."
  19. _err "You can get yours from https://work.weixin.qq.com/api/doc/90000/90136/91770"
  20. return 1
  21. fi
  22. _saveaccountconf_mutable WEIXIN_WORK_WEBHOOK "$WEIXIN_WORK_WEBHOOK"
  23. WEIXIN_WORK_KEYWORD="${WEIXIN_WORK_KEYWORD:-$(_readaccountconf_mutable WEIXIN_WORK_KEYWORD)}"
  24. if [ "$WEIXIN_WORK_KEYWORD" ]; then
  25. _saveaccountconf_mutable WEIXIN_WORK_KEYWORD "$WEIXIN_WORK_KEYWORD"
  26. fi
  27. _content=$(echo "$_content" | _json_encode)
  28. _subject=$(echo "$_subject" | _json_encode)
  29. _data="{\"msgtype\": \"text\", \"text\": {\"content\": \"[$WEIXIN_WORK_KEYWORD]\n$_subject\n$_content\"}}"
  30. response="$(_post "$_data" "$WEIXIN_WORK_WEBHOOK" "" "POST" "application/json")"
  31. if [ "$?" = "0" ] && _contains "$response" "errmsg\":\"ok"; then
  32. _info "weixin_work webhooks event fired success."
  33. return 0
  34. fi
  35. _err "weixin_work webhooks event fired error."
  36. _err "$response"
  37. return 1
  38. }