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.

75 lines
2.5 KiB

  1. #!/usr/bin/env sh
  2. #Support for CQHTTP api. Push notification on CoolQ
  3. #CQHTTP_TOKEN="" Required, 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. _err "You didn't specify a CQHTTP application token yet. If it's empty please pass \"__ACME_SH_TOKEN_EMPTY__\" (without quote)."
  17. return 1
  18. fi
  19. _saveaccountconf_mutable CQHTTP_TOKEN "$CQHTTP_TOKEN"
  20. if [ "$CQHTTP_TOKEN" = "__ACME_SH_TOKEN_EMPTY__" ]; then
  21. CQHTTP_TOKEN=""
  22. fi
  23. CQHTTP_USER="${CQHTTP_USER:-$(_readaccountconf_mutable CQHTTP_USER)}"
  24. if [ -z "$CQHTTP_USER" ]; then
  25. CQHTTP_USER=""
  26. _err "You didn't specify a QQ user yet."
  27. return 1
  28. fi
  29. _saveaccountconf_mutable CQHTTP_USER "$CQHTTP_USER"
  30. CQHTTP_APIROOT="${CQHTTP_APIROOT:-$(_readaccountconf_mutable CQHTTP_APIROOT)}"
  31. if [ -z "$CQHTTP_APIROOT" ]; then
  32. CQHTTP_APIROOT=""
  33. _err "You didn't specify a QQ user yet."
  34. return 1
  35. fi
  36. _saveaccountconf_mutable CQHTTP_APIROOT "$CQHTTP_APIROOT"
  37. CQHTTP_APIROOT="${CQHTTP_APIROOT:-$(_readaccountconf_mutable CQHTTP_APIROOT)}"
  38. if [ -z "$CQHTTP_APIROOT" ]; then
  39. CQHTTP_APIROOT=""
  40. _err "You didn't specify a QQ user yet."
  41. return 1
  42. fi
  43. _saveaccountconf_mutable CQHTTP_APIROOT "$CQHTTP_APIROOT"
  44. CQHTTP_CUSTOM_MSGHEAD="${CQHTTP_CUSTOM_MSGHEAD:-$(_readaccountconf_mutable CQHTTP_CUSTOM_MSGHEAD)}"
  45. if [ -z "$CQHTTP_CUSTOM_MSGHEAD" ]; then
  46. CQHTTP_CUSTOM_MSGHEAD="A message from acme.sh:"
  47. else
  48. _saveaccountconf_mutable CQHTTP_CUSTOM_MSGHEAD "$CQHTTP_CUSTOM_MSGHEAD"
  49. fi
  50. _access_token="$(printf "%s" "$CQHTTP_TOKEN" | _url_encode)"
  51. _user_id="$(printf "%s" "$CQHTTP_USER" | _url_encode)"
  52. _message="$(printf "$CQHTTP_CUSTOM_MSGHEAD %s\\n%s" "$_subject" "$_content" | _url_encode)"
  53. _finalUrl="$CQHTTP_APIROOT$CQHTTP_APIPATH?access_token=$_access_token&user_id=$_user_id&message=$_message"
  54. response="$(_get "$_finalUrl")"
  55. if [ "$?" = "0" ] && _contains "$response" "\"retcode\":0,\"status\":\"ok\""; then
  56. _info "QQ send success."
  57. return 0
  58. fi
  59. _err "QQ send error."
  60. _err "URL: $_finalUrl"
  61. _err "Response: $response"
  62. return 1
  63. }