Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
shufflewzc committed Jan 4, 2022
1 parent c899eb4 commit 834a93e
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 28 deletions.
71 changes: 71 additions & 0 deletions jd_try_notify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#Source: https://github.com/Hyper-Beast

import requests
import json
import time
import os
import re
import sys
import random
import string


def load_send():
global send
cur_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(cur_path)
if os.path.exists(cur_path + "/sendNotify.py"):
try:
from sendNotify import send
except:
send=False
print("加载通知服务失败~")
else:
send=False
print("加载通知服务失败~")
load_send()


def printf(text):
print(text)
sys.stdout.flush()

def getinfo(ck):
url='https://api.m.jd.com/client.action'
headers={
'accept':'application/json, text/plain, */*',
'content-type':'application/x-www-form-urlencoded',
'origin':'https://prodev.m.jd.com',
'content-length':'249',
'accept-language':'zh-CN,zh-Hans;q=0.9',
'user-agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
'referer':'https://prodev.m.jd.com/',
'accept-encoding':'gzip, deflate, br',
'cookie':ck
}
uuid=''.join(random.sample(['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','a','b','c','z'], 40)).replace(" ","")
data='appid=newtry&functionId=try_MyTrials&uuid='+uuid+'&clientVersion=10.3.0&client=wh5&osVersion=15.1.1&area=16_1303_48712_48758&networkType=wifi&body=%7B%22page%22%3A1%2C%22selected%22%3A2%2C%22previewTime%22%3A%22%22%7D'
response=requests.post(url=url,headers=headers,data=data)
isnull=True
try:
for i in range(len(json.loads(response.text)['data']['list'])):
if(json.loads(response.text)['data']['list'][i]['text']['text']).find('试用资格将保留')!=-1:
print(json.loads(response.text)['data']['list'][i]['trialName'])
send("京东试用待领取物品通知",'账号名称:'+ptpin+'\n'+'商品名称:'+json.loads(response.text)['data']['list'][i]['trialName']+"\n"+"商品链接:https://item.jd.com/"+json.loads(response.text)['data']['list'][i]['skuId']+".html")
isnull=False
i+=1
if isnull==True:
print("没有在有效期内待领取的试用品")
except:
pass
if __name__ == '__main__':
try:
cks = os.environ["JD_COOKIE"].split("&")
except:
f = open("/jd/config/config.sh", "r", encoding='utf-8')
cks = re.findall(r'Cookie[0-9]*="(pt_key=.*?;pt_pin=.*?;)"', f.read())
f.close()
for ck in cks:
ptpin = re.findall(r"pt_pin=(.*?);", ck)[0]
printf("--账号:" + ptpin + "--")
getinfo(ck)
119 changes: 91 additions & 28 deletions sendNotify.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2021/9/16
# @Author : curtinlv
# @File : sendNotify.py
# @Software: PyCharm
#!/usr/bin/env python3
# _*_ coding:utf-8 _*_

#Modify: Kirin

import sys
import os, re
cur_path = os.path.abspath(os.path.dirname(__file__))
root_path = os.path.split(cur_path)[0]
sys.path.append(root_path)
import requests
import json
import time
import hmac
import hashlib
import base64
import urllib.parse
from requests.adapters import HTTPAdapter
from urllib3.util import Retry

cur_path = os.path.abspath(os.path.dirname(__file__))
root_path = os.path.split(cur_path)[0]
sys.path.append(root_path)

# 通知服务
BARK = '' # bark服务,自行搜索; secrets可填;
BARK_PUSH='' # bark自建服务器,要填完整链接,结尾的/不要
SCKEY = '' # Server酱的SCKEY; secrets可填
TG_BOT_TOKEN = '' # tg机器人的TG_BOT_TOKEN; secrets可填1407203283:AAG9rt-6RDaaX0HBLZQq0laNOh898iFYaRQ
TG_USER_ID = '' # tg机器人的TG_USER_ID; secrets可填 1434078534
TG_API_HOST='' # tg 代理api
TG_PROXY_IP = '' # tg机器人的TG_PROXY_IP; secrets可填
TG_PROXY_PORT = '' # tg机器人的TG_PROXY_PORT; secrets可填
DD_BOT_TOKEN = '' # 钉钉机器人的DD_BOT_TOKEN; secrets可填
DD_BOT_ACCESS_TOKEN = '' # 钉钉机器人的DD_BOT_ACCESS_TOKEN; secrets可填
DD_BOT_SECRET = '' # 钉钉机器人的DD_BOT_SECRET; secrets可填
QQ_SKEY = '' # qq机器人的QQ_SKEY; secrets可填
QQ_MODE = '' # qq机器人的QQ_MODE; secrets可填
QYWX_AM = '' # 企业微信
QYWX_KEY = '' # 企业微信BOT
PUSH_PLUS_TOKEN = '' # 微信推送Plus+

notify_mode = []
Expand All @@ -40,15 +43,17 @@
# GitHub action运行需要填写对应的secrets
if "BARK" in os.environ and os.environ["BARK"]:
BARK = os.environ["BARK"]
if "BARK_PUSH" in os.environ and os.environ["BARK_PUSH"]:
BARK_PUSH = os.environ["BARK_PUSH"]
if "SCKEY" in os.environ and os.environ["SCKEY"]:
SCKEY = os.environ["SCKEY"]
if "TG_BOT_TOKEN" in os.environ and os.environ["TG_BOT_TOKEN"] and "TG_USER_ID" in os.environ and os.environ["TG_USER_ID"]:
TG_BOT_TOKEN = os.environ["TG_BOT_TOKEN"]
TG_USER_ID = os.environ["TG_USER_ID"]
if "TG_API_HOST" in os.environ and os.environ["TG_API_HOST"]:
TG_API_HOST = os.environ["TG_API_HOST"]
if "DD_BOT_TOKEN" in os.environ and os.environ["DD_BOT_TOKEN"] and "DD_BOT_SECRET" in os.environ and os.environ["DD_BOT_SECRET"]:
DD_BOT_TOKEN = os.environ["DD_BOT_TOKEN"]
if "DD_BOT_ACCESS_TOKEN" in os.environ and os.environ["DD_BOT_ACCESS_TOKEN"] and "DD_BOT_SECRET" in os.environ and os.environ["DD_BOT_SECRET"]:
DD_BOT_ACCESS_TOKEN = os.environ["DD_BOT_ACCESS_TOKEN"]
DD_BOT_SECRET = os.environ["DD_BOT_SECRET"]
if "QQ_SKEY" in os.environ and os.environ["QQ_SKEY"] and "QQ_MODE" in os.environ and os.environ["QQ_MODE"]:
QQ_SKEY = os.environ["QQ_SKEY"]
Expand All @@ -62,18 +67,26 @@
if "QYWX_AM" in os.environ:
if len(os.environ["QYWX_AM"]) > 1:
QYWX_AM = os.environ["QYWX_AM"]


if "QYWX_KEY" in os.environ:
if len(os.environ["QYWX_KEY"]) > 1:
QYWX_KEY = os.environ["QYWX_KEY"]
# print("已获取并使用Env环境 QYWX_AM")

if BARK:
notify_mode.append('bark')
# print("BARK 推送打开")
if BARK_PUSH:
notify_mode.append('bark')
# print("BARK 推送打开")
if SCKEY:
notify_mode.append('sc_key')
# print("Server酱 推送打开")
if TG_BOT_TOKEN and TG_USER_ID:
notify_mode.append('telegram_bot')
# print("Telegram 推送打开")
if DD_BOT_TOKEN and DD_BOT_SECRET:
if DD_BOT_ACCESS_TOKEN and DD_BOT_SECRET:
notify_mode.append('dingding_bot')
# print("钉钉机器人 推送打开")
if QQ_SKEY and QQ_MODE:
Expand All @@ -87,6 +100,10 @@
notify_mode.append('wecom_app')
# print("企业微信机器人 推送打开")

if QYWX_KEY:
notify_mode.append('wecom_key')
# print("企业微信机器人 推送打开")


def message(str_msg):
global message_info
Expand All @@ -96,19 +113,30 @@ def message(str_msg):

def bark(title, content):
print("\n")
if not BARK:
print("bark服务的bark_token未设置!!\n取消推送")
return
print("bark服务启动")
try:
response = requests.get(
if BARK:
try:
response = requests.get(
f"""https://api.day.app/{BARK}/{title}/{urllib.parse.quote_plus(content)}""").json()
if response['code'] == 200:
print('推送成功!')
else:
if response['code'] == 200:
print('推送成功!')
else:
print('推送失败!')
except:
print('推送失败!')
except:
print('推送失败!')
if BARK_PUSH:
try:
response = requests.get(
f"""{BARK_PUSH}/{title}/{urllib.parse.quote_plus(content)}""").json()
if response['code'] == 200:
print('推送成功!')
else:
print('推送失败!')
except:
print('推送失败!')
print("bark服务启动")
if BARK=='' and BARK_PUSH=='':
print("bark服务的bark_token未设置!!\n取消推送")
return

def serverJ(title, content):
print("\n")
Expand Down Expand Up @@ -169,7 +197,7 @@ def dingding_bot(title, content):
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) # 签名
print('开始使用 钉钉机器人 推送消息...', end='')
url = f'https://oapi.dingtalk.com/robot/send?access_token={DD_BOT_TOKEN}&timestamp={timestamp}&sign={sign}'
url = f'https://oapi.dingtalk.com/robot/send?access_token={DD_BOT_ACCESS_TOKEN}&timestamp={timestamp}&sign={sign}'
headers = {'Content-Type': 'application/json;charset=utf-8'}
data = {
'msgtype': 'text',
Expand Down Expand Up @@ -217,6 +245,30 @@ def pushplus_bot(title, content):
print('推送失败!')
except Exception as e:
print(e)



print("xxxxxxxxxxxx")
def wecom_key(title, content):
print("\n")
if not QYWX_KEY:
print("QYWX_KEY未设置!!\n取消推送")
return
print("QYWX_KEY服务启动")
print("content"+content)
headers = {'Content-Type': 'application/json'}
data = {
"msgtype":"text",
"text":{
"content":title+"\n"+content.replace("\n", "\n\n")
}
}

print(f"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={QYWX_KEY}")
response = requests.post(f"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={QYWX_KEY}", json=data,headers=headers).json()
print(response)


# 企业微信 APP 推送
def wecom_app(title, content):
try:
Expand Down Expand Up @@ -311,9 +363,10 @@ def send(title, content):
:param content:
:return:
"""

for i in notify_mode:
if i == 'bark':
if BARK:
if BARK or BARK_PUSH:
bark(title=title, content=content)
else:
print('未启用 bark')
Expand All @@ -325,7 +378,7 @@ def send(title, content):
print('未启用 Server酱')
continue
elif i == 'dingding_bot':
if DD_BOT_TOKEN and DD_BOT_SECRET:
if DD_BOT_ACCESS_TOKEN and DD_BOT_SECRET:
dingding_bot(title=title, content=content)
else:
print('未启用 钉钉机器人')
Expand All @@ -351,6 +404,16 @@ def send(title, content):
elif i == 'wecom_app':
if QYWX_AM:
wecom_app(title=title, content=content)
else:
print('未启用企业微信应用消息推送')
continue
elif i == 'wecom_key':
if QYWX_KEY:

for i in range(int(len(content)/2000)+1):
wecom_key(title=title, content=content[i*2000:(i+1)*2000])


else:
print('未启用企业微信应用消息推送')
continue
Expand All @@ -363,4 +426,4 @@ def main():


if __name__ == '__main__':
main()
main()

0 comments on commit 834a93e

Please sign in to comment.