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.

64 lines
2.1 KiB

  1. #!/usr/bin/env sh
  2. #Support for CQHTTP api. Push notification on CoolQ
  3. #CQHTTP_TOKEN="" Recommended to be not empty, QQ application token
  4. #CQHTTP_USER="" Required, QQ receiver ID
  5. #CQHTTP_APIROOT="" Required, CQHTTP Server URL (without slash suffix)
  6. #CQHTTP_CUSTOM_MSGHEAD="" Optional, custom message header
  7. CQHTTP_APIPATH="/send_private_msg"
  8. cqhttp_send() {
  9. _subject="$1"
  10. _content="$2"
  11. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  12. _debug "_statusCode" "$_statusCode"
  13. CQHTTP_TOKEN="${CQHTTP_TOKEN:-$(_readaccountconf_mutable CQHTTP_TOKEN)}"
  14. if [ -z "$CQHTTP_TOKEN" ]; then
  15. CQHTTP_TOKEN=""
  16. _info "You didn't specify a CQHTTP application token yet, which is unsafe. Assuming it to be empty."
  17. else
  18. _saveaccountconf_mutable CQHTTP_TOKEN "$CQHTTP_TOKEN"
  19. fi
  20. CQHTTP_USER="${CQHTTP_USER:-$(_readaccountconf_mutable CQHTTP_USER)}"
  21. if [ -z "$CQHTTP_USER" ]; then
  22. CQHTTP_USER=""
  23. _err "You didn't specify a QQ user yet."
  24. return 1
  25. fi
  26. _saveaccountconf_mutable CQHTTP_USER "$CQHTTP_USER"
  27. CQHTTP_APIROOT="${CQHTTP_APIROOT:-$(_readaccountconf_mutable CQHTTP_APIROOT)}"
  28. if [ -z "$CQHTTP_APIROOT" ]; then
  29. CQHTTP_APIROOT=""
  30. _err "You didn't specify the API root yet."
  31. return 1
  32. fi
  33. _saveaccountconf_mutable CQHTTP_APIROOT "$CQHTTP_APIROOT"
  34. CQHTTP_CUSTOM_MSGHEAD="${CQHTTP_CUSTOM_MSGHEAD:-$(_readaccountconf_mutable CQHTTP_CUSTOM_MSGHEAD)}"
  35. if [ -z "$CQHTTP_CUSTOM_MSGHEAD" ]; then
  36. CQHTTP_CUSTOM_MSGHEAD="A message from acme.sh:"
  37. else
  38. _saveaccountconf_mutable CQHTTP_CUSTOM_MSGHEAD "$CQHTTP_CUSTOM_MSGHEAD"
  39. fi
  40. _access_token="$(printf "%s" "$CQHTTP_TOKEN" | _url_encode)"
  41. _user_id="$(printf "%s" "$CQHTTP_USER" | _url_encode)"
  42. _message="$(printf "$CQHTTP_CUSTOM_MSGHEAD %s\\n%s" "$_subject" "$_content" | _url_encode)"
  43. _finalUrl="$CQHTTP_APIROOT$CQHTTP_APIPATH?access_token=$_access_token&user_id=$_user_id&message=$_message"
  44. response="$(_get "$_finalUrl")"
  45. if [ "$?" = "0" ] && _contains "$response" "\"retcode\":0,\"status\":\"ok\""; then
  46. _info "QQ send success."
  47. return 0
  48. fi
  49. _err "QQ send error."
  50. _debug "URL" "$_finalUrl"
  51. _debug "Response" "$response"
  52. return 1
  53. }