无损音乐网自动签到脚本分享

252 阅读2分钟

前言:分享python自动签到脚本。 照例分享下个人博客地址:shizuka.icu

签到脚本

import cv2
import requests
import time
import base64
import json
from aes import ECBCipher
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


headers = {
    "Referer": "https://www.hifini.com/user-login.htm",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
}

# 签到


def sign(cookies):
    print('开始签到...')
    resp = requests.post(
        url="https://www.hifini.com/sg_sign.htm", headers=headers, cookies=cookies, verify=False)
    print('签到响应值:', resp.content.decode(encoding='utf-8').strip())
    if '已经' in resp.content.decode(encoding='utf-8'):
        print('签过了')
    else:
        with open('test.txt', 'a', encoding="utf-8") as txt:
            now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
            txt.write(now + '\n')
            txt.write(str(resp.content.decode(encoding='utf-8')).strip() + '\n')

# 登录


def login(xn_token, xn_pointJson):
    data = {
        "email": "你的邮箱",
        "password": "md5加密的密码",
        "xn_token": xn_token,
        "xn_pointJson": xn_pointJson
    }
    headers["x-requested-with"] = "XMLHttpRequest"
    session = requests.session()
    # resp = session.post(
    #     url='https://www.hifini.com/user-login.htm', headers=headers, data=data, verify=False)
    # headers["x-requested-with"] = "XMLHttpRequest"
    cookies = session.post(
        url='https://www.hifini.com/user-login.htm', headers=headers, data=data).cookies
    cookie_dic = requests.utils.dict_from_cookiejar(cookies)
    # print(cookie_dic)
    # result = re.findall('href =\"(.*?)\"', resp.text)
    # cookies = session.post(
    #     url=f'https://www.hifini.com{result[0]}', headers=headers, data=data, verify=False).cookies
    # cookie_dic = requests.utils.dict_from_cookiejar(cookies)
    # print('cookies==>', cookie_dic['bbs_token'])
    sign(cookie_dic)


def get_img_info():
    json = {
        "captchaType": "blockPuzzle",
        "clientUid": "slider-9fa2b7dd-a0d9-4d8e-8f0d-1f61e662e30e",
        "ts": int(time.time() * 1000)
    }
    resp = requests.post(
        url="https://www.hifini.com/captcha_get.htm", headers=headers, json=json)
    repData = resp.json()["repData"]
    bg_base64__data = repData["originalImageBase64"]
    slider_base64__data = repData["jigsawImageBase64"]
    token = repData["token"]
    secretKey = repData["secretKey"]
    with open('bg.png', 'wb') as bg_png:
        img = base64.b64decode(bg_base64__data)
        bg_png.write(img)
    with open('slider.png', 'wb') as slider_png:
        img = base64.b64decode(slider_base64__data)
        slider_png.write(img)
    identify_gap('bg.png', 'slider.png', 'out.png', token, secretKey)


def identify_gap(bg, tp, out, token, secretKey):

    # 读取背景图片和缺口图片
    bg_img = cv2.imread(bg)  # 背景图片
    tp_img = cv2.imread(tp)  # 缺口图片

    # 识别图片边缘
    bg_edge = cv2.Canny(bg_img, 100, 200)
    tp_edge = cv2.Canny(tp_img, 100, 200)

    # 转换图片格式
    bg_pic = cv2.cvtColor(bg_edge, cv2.COLOR_GRAY2RGB)
    tp_pic = cv2.cvtColor(tp_edge, cv2.COLOR_GRAY2RGB)

    # 缺口匹配
    res = cv2.matchTemplate(bg_pic, tp_pic, cv2.TM_CCOEFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)  # 寻找最优匹配
    X = max_loc[0]  # 缺口的X轴坐标

    # 绘制方框
    th, tw = tp_pic.shape[:2]
    tl = max_loc  # 左上角点的坐标
    br = (tl[0]+tw, tl[1]+th)  # 右下角点的坐标
    cv2.rectangle(bg_img, tl, br, (0, 0, 255), 2)  # 绘制矩形

    cv2.imwrite(out, bg_img)  # 保存在本地
    x = tl[0]
    if x == 0:
        main()
    else:
        x = x + 0.1999969482422
        p_dic = {
            "x": x,
            "y": 5
        }
        check_captcha(json.dumps(p_dic).replace(" ", ""), token, secretKey)


def check_captcha(p_str, token, secretKey):
    ecb_obj = ECBCipher(secretKey)
    pointJson = ecb_obj.encrypted(p_str)
    # print('加密:', pointJson)
    json = {
        "captchaType": "blockPuzzle",
        "clientUid": "slider-9fa2b7dd-a0d9-4d8e-8f0d-1f61e662e30e",
        "token": token,
        "pointJson": pointJson,
        "ts": int(time.time() * 1000)
    }
    resp = requests.post(
        url="https://www.hifini.com/captcha_check.htm", headers=headers, json=json)
    res = resp.json()
    if res['error'] == False:
        login(token, pointJson)
    else:
        main()


def main():
    get_img_info()
    # login()


if __name__ == '__main__':
    main()
  • 可以挂到服务器上结合crontab去实现每日定时签到
crontab -e

59 23 * * * source /usr/local/docker/shell/hifi-sign.sh
  • hifi-sign.sh
#!/bin/bash
echo "将进行hifi网站签到------->"
python /usr/local/docker/shell/init.py #签到脚本地址