mirror of
				https://github.com/whyour/qinglong.git
				synced 2025-11-04 20:06:08 +08:00 
			
		
		
		
	bark 推送改为 post 请求
This commit is contained in:
		
							parent
							
								
									c3908e956f
								
							
						
					
					
						commit
						69d9307be9
					
				| 
						 | 
				
			
			@ -27,7 +27,7 @@ export default class NotificationService {
 | 
			
		|||
    ['aibotk', this.aibotk],
 | 
			
		||||
    ['iGot', this.iGot],
 | 
			
		||||
    ['pushPlus', this.pushPlus],
 | 
			
		||||
    ['wePlusBot',this.wePlusBot],
 | 
			
		||||
    ['wePlusBot', this.wePlusBot],
 | 
			
		||||
    ['email', this.email],
 | 
			
		||||
    ['pushMe', this.pushMe],
 | 
			
		||||
    ['webhook', this.webhook],
 | 
			
		||||
| 
						 | 
				
			
			@ -209,16 +209,23 @@ export default class NotificationService {
 | 
			
		|||
    if (!barkPush.startsWith('http')) {
 | 
			
		||||
      barkPush = `https://api.day.app/${barkPush}`;
 | 
			
		||||
    }
 | 
			
		||||
    const url = `${barkPush}/${encodeURIComponent(
 | 
			
		||||
      this.title,
 | 
			
		||||
    )}/${encodeURIComponent(
 | 
			
		||||
      this.content,
 | 
			
		||||
    )}?icon=${barkIcon}&sound=${barkSound}&group=${barkGroup}&level=${barkLevel}&url=${barkUrl}&isArchive=${barkArchive}`;
 | 
			
		||||
    const url = `${barkPush}`;
 | 
			
		||||
    const body = {
 | 
			
		||||
      title: this.title,
 | 
			
		||||
      body: this.content,
 | 
			
		||||
      icon: barkIcon,
 | 
			
		||||
      sound: barkSound,
 | 
			
		||||
      group: barkGroup,
 | 
			
		||||
      isArchive: barkArchive,
 | 
			
		||||
      level: barkLevel,
 | 
			
		||||
      url: barkUrl,
 | 
			
		||||
    };
 | 
			
		||||
    try {
 | 
			
		||||
      const res: any = await got
 | 
			
		||||
        .get(url, {
 | 
			
		||||
        .post(url, {
 | 
			
		||||
          ...this.gotOption,
 | 
			
		||||
          headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
 | 
			
		||||
          json: body,
 | 
			
		||||
          headers: { 'Content-Type': 'application/json' },
 | 
			
		||||
        })
 | 
			
		||||
        .json();
 | 
			
		||||
      if (res.code === 200) {
 | 
			
		||||
| 
						 | 
				
			
			@ -519,7 +526,7 @@ export default class NotificationService {
 | 
			
		|||
 | 
			
		||||
    let content = this.content;
 | 
			
		||||
    let template = 'txt';
 | 
			
		||||
    if(this.content.length>800){
 | 
			
		||||
    if (this.content.length > 800) {
 | 
			
		||||
      template = 'html';
 | 
			
		||||
      content = content.replace(/[\n\r]/g, '<br>');
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -612,18 +619,15 @@ export default class NotificationService {
 | 
			
		|||
  private async pushMe() {
 | 
			
		||||
    const { pushMeKey, pushMeUrl } = this.params;
 | 
			
		||||
    try {
 | 
			
		||||
      const res: any = await got.post(
 | 
			
		||||
        pushMeUrl || 'https://push.i-i.me/',
 | 
			
		||||
        {
 | 
			
		||||
          ...this.gotOption,
 | 
			
		||||
          json: {
 | 
			
		||||
            push_key: pushMeKey,
 | 
			
		||||
            title: this.title,
 | 
			
		||||
            content: this.content,
 | 
			
		||||
          },
 | 
			
		||||
          headers: { 'Content-Type': 'application/json' },
 | 
			
		||||
      const res: any = await got.post(pushMeUrl || 'https://push.i-i.me/', {
 | 
			
		||||
        ...this.gotOption,
 | 
			
		||||
        json: {
 | 
			
		||||
          push_key: pushMeKey,
 | 
			
		||||
          title: this.title,
 | 
			
		||||
          content: this.content,
 | 
			
		||||
        },
 | 
			
		||||
      );
 | 
			
		||||
        headers: { 'Content-Type': 'application/json' },
 | 
			
		||||
      });
 | 
			
		||||
      if (res.body === 'success') {
 | 
			
		||||
        return true;
 | 
			
		||||
      } else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -358,17 +358,24 @@ function barkNotify(text, desp, params = {}) {
 | 
			
		|||
        BARK_PUSH = `https://api.day.app/${BARK_PUSH}`;
 | 
			
		||||
      }
 | 
			
		||||
      const options = {
 | 
			
		||||
        url: `${BARK_PUSH}/${encodeURIComponent(text)}/${encodeURIComponent(
 | 
			
		||||
          desp,
 | 
			
		||||
        )}?icon=${BARK_ICON}&sound=${BARK_SOUND}&group=${BARK_GROUP}&isArchive=${BARK_ARCHIVE}&level=${BARK_LEVEL}&url=${BARK_URL}&${querystring.stringify(
 | 
			
		||||
          params,
 | 
			
		||||
        )}`,
 | 
			
		||||
        url: `${BARK_PUSH}`,
 | 
			
		||||
        json: {
 | 
			
		||||
          title: text,
 | 
			
		||||
          body: desp,
 | 
			
		||||
          icon: BARK_ICON,
 | 
			
		||||
          sound: BARK_SOUND,
 | 
			
		||||
          group: BARK_GROUP,
 | 
			
		||||
          isArchive: BARK_ARCHIVE,
 | 
			
		||||
          level: BARK_LEVEL,
 | 
			
		||||
          url: BARK_URL,
 | 
			
		||||
          ...params,
 | 
			
		||||
        },
 | 
			
		||||
        headers: {
 | 
			
		||||
          'Content-Type': 'application/x-www-form-urlencoded',
 | 
			
		||||
          'Content-Type': 'application/json',
 | 
			
		||||
        },
 | 
			
		||||
        timeout,
 | 
			
		||||
      };
 | 
			
		||||
      $.get(options, (err, resp, data) => {
 | 
			
		||||
      $.post(options, (err, resp, data) => {
 | 
			
		||||
        try {
 | 
			
		||||
          if (err) {
 | 
			
		||||
            console.log('Bark APP 发送通知调用API失败😞\n', err);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -137,9 +137,9 @@ def bark(title: str, content: str) -> None:
 | 
			
		|||
    print("bark 服务启动")
 | 
			
		||||
 | 
			
		||||
    if push_config.get("BARK_PUSH").startswith("http"):
 | 
			
		||||
        url = f'{push_config.get("BARK_PUSH")}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}'
 | 
			
		||||
        url = f'{push_config.get("BARK_PUSH")}'
 | 
			
		||||
    else:
 | 
			
		||||
        url = f'https://api.day.app/{push_config.get("BARK_PUSH")}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}'
 | 
			
		||||
        url = f'https://api.day.app/{push_config.get("BARK_PUSH")}'
 | 
			
		||||
 | 
			
		||||
    bark_params = {
 | 
			
		||||
        "BARK_ARCHIVE": "isArchive",
 | 
			
		||||
| 
						 | 
				
			
			@ -149,7 +149,10 @@ def bark(title: str, content: str) -> None:
 | 
			
		|||
        "BARK_LEVEL": "level",
 | 
			
		||||
        "BARK_URL": "url",
 | 
			
		||||
    }
 | 
			
		||||
    params = ""
 | 
			
		||||
    data = {
 | 
			
		||||
        "title": title,
 | 
			
		||||
        "body": content,
 | 
			
		||||
    }
 | 
			
		||||
    for pair in filter(
 | 
			
		||||
        lambda pairs: pairs[0].startswith("BARK_")
 | 
			
		||||
        and pairs[0] != "BARK_PUSH"
 | 
			
		||||
| 
						 | 
				
			
			@ -157,10 +160,11 @@ def bark(title: str, content: str) -> None:
 | 
			
		|||
        and bark_params.get(pairs[0]),
 | 
			
		||||
        push_config.items(),
 | 
			
		||||
    ):
 | 
			
		||||
        params += f"{bark_params.get(pair[0])}={pair[1]}&"
 | 
			
		||||
    if params:
 | 
			
		||||
        url = url + "?" + params.rstrip("&")
 | 
			
		||||
    response = requests.get(url).json()
 | 
			
		||||
        data[bark_params.get(pair[0])] = pair[1]
 | 
			
		||||
    headers = {"Content-Type": "application/json;charset=utf-8"}
 | 
			
		||||
    response = requests.post(
 | 
			
		||||
        url=url, data=json.dumps(data), headers=headers, timeout=15
 | 
			
		||||
    ).json()
 | 
			
		||||
 | 
			
		||||
    if response["code"] == 200:
 | 
			
		||||
        print("bark 推送成功!")
 | 
			
		||||
| 
						 | 
				
			
			@ -385,6 +389,7 @@ def pushplus_bot(title: str, content: str) -> None:
 | 
			
		|||
        else:
 | 
			
		||||
            print("PUSHPLUS 推送失败!")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def weplus_bot(title: str, content: str) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    通过 微加机器人 推送消息。
 | 
			
		||||
| 
						 | 
				
			
			@ -396,7 +401,7 @@ def weplus_bot(title: str, content: str) -> None:
 | 
			
		|||
 | 
			
		||||
    template = "txt"
 | 
			
		||||
    if len(content) > 800:
 | 
			
		||||
      template = "html"
 | 
			
		||||
        template = "html"
 | 
			
		||||
 | 
			
		||||
    url = "https://www.weplusbot.com/send"
 | 
			
		||||
    data = {
 | 
			
		||||
| 
						 | 
				
			
			@ -704,7 +709,11 @@ def pushme(title: str, content: str) -> None:
 | 
			
		|||
        return
 | 
			
		||||
    print("PushMe 服务启动")
 | 
			
		||||
 | 
			
		||||
    url = push_config.get("PUSHME_URL") if push_config.get("PUSHME_URL") else "https://push.i-i.me/"
 | 
			
		||||
    url = (
 | 
			
		||||
        push_config.get("PUSHME_URL")
 | 
			
		||||
        if push_config.get("PUSHME_URL")
 | 
			
		||||
        else "https://push.i-i.me/"
 | 
			
		||||
    )
 | 
			
		||||
    data = {
 | 
			
		||||
        "push_key": push_config.get("PUSHME_KEY"),
 | 
			
		||||
        "title": title,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user