找回密码
 立即注册
搜索
查看: 3246|回复: 0

[开发交流] python封装持续更新已完成读取配置和校验MD5

[复制链接]
发表于 2022-5-21 19:09:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区

您需要 登录 才可以下载或查看,没有账号?立即注册

×
在做一个pyqt程序,找了半天网络验证感觉这个挺好用,写了下模块校验。get_md5()#获取当前exe文件袋md5和云端对比返回结果,True为通过,False为md5不匹配soft_conf()#读取当前软件就配置,True返回版本,公告,下载地址,False返回空
[Python] 纯文本查看 复制代码
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import time
import traceback
import hashlib
import requests
import json
import os

class Ver():
    def __init__(self):
        self.url = 'https://bbs.52bangqi.com/plugin.php?id=xinxiu_network:login'
        self.key =  ''   #传输密钥key:
        self.file ='ver.exe'    #打包后的exe绝对路径

    def soft_conf(self):
        url = self.url+'&key={0}&action=login_config'.format(self.key)
        head={
            "Content-Type":"application/x-www-form-urlencoded"
        }
        try:
            res = requests.get(url,headers=head,)
            s = self.paser(res.text)
            #print(s)
            if int(s['code']) == 200:
                version = s['data']['version']
                notice = s['data']['Notice']
                updateurl = s['data']['updateurl']
                return version,notice,updateurl
        except:
            print(traceback.format_exc())
        return  []

    def paser(self,txt):
        return json.loads(txt)

    def get_md5(self):
        '''
        客户端和服务端md5检验
        :return:
        '''
        url = self.url+'&key={0}&action=login_md5&rmd5={1}'.format(self.key,self.check_md5(self.file))
        print(self.check_md5(self.file))
        head={
            "Content-Type":"application/x-www-form-urlencoded"
        }
        try:
            res = requests.get(url,headers=head,)
            s = self.paser(res.text)
            #print(s)
            if int(s['code']) == 200:
                md5 = s['data']['md5']
                return True
        except:
            print(traceback.format_exc())
        return  False

    def check_md5(self,file):
        #获取打包后的exe文件md5
        md = hashlib.md5()
        try:
            with open(file=file, mode='rb') as csna:
                block = csna.read(1024)
                while block:
                    md.update(block)
                    block = csna.read(1024)
            return md.hexdigest()
            # if md.hexdigest() == self.get_md5():
            #     print('验证成功,软件为正版')
            #     return True
        except:
            print(traceback.format_exc())
        print('验证失败')
        return  False
    def get_path(self):

        #文件绝对路径
        return os.path.dirname(os.path.abspath(__file__))
if  __name__ =='__main__':
    #while True:
    s = Ver()
    #s.soft_conf()
    if s.get_md5():
        print("正版")
    else:
        print("请勿使用盗版程序")
    time.sleep(100)

评分

参与人数 1好评 +1 收起 理由
admin + 1 很给力!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|新秀网络验证系统API ( 豫ICP备2021033257号-1 )

GMT+8, 2024-3-29 16:38 , Processed in 0.205833 second(s), 63 queries , Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表