国产精品爱啪在线线免费观看_97视频精品_欧美精品一区二区在线播放_国产欧美久久一区二区三区

新秀網(wǎng)絡(luò)驗(yàn)證系統(tǒng)

標(biāo)題: python封裝持續(xù)更新已完成讀取配置和校驗(yàn)MD5 [打印本頁(yè)]

作者: q188224912    時(shí)間: 2022-5-21 19:09
標(biāo)題: python封裝持續(xù)更新已完成讀取配置和校驗(yàn)MD5
在做一個(gè)pyqt程序,找了半天網(wǎng)絡(luò)驗(yàn)證感覺(jué)這個(gè)挺好用,寫(xiě)了下模塊校驗(yàn)。get_md5()#獲取當(dāng)前exe文件袋md5和云端對(duì)比返回結(jié)果,True為通過(guò),F(xiàn)alse為md5不匹配soft_conf()#讀取當(dāng)前軟件就配置,True返回版本,公告,下載地址,F(xiàn)alse返回空
[Python] 純文本查看 復(fù)制代碼
#!/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絕對(duì)路徑

    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):
        '''
        客戶端和服務(wù)端md5檢驗(yàn)
        :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('驗(yàn)證成功,軟件為正版')
            #     return True
        except:
            print(traceback.format_exc())
        print('驗(yàn)證失敗')
        return  False
    def get_path(self):

        #文件絕對(duì)路徑
        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("請(qǐng)勿使用盜版程序")
    time.sleep(100)






歡迎光臨 新秀網(wǎng)絡(luò)驗(yàn)證系統(tǒng) (http://www.5566wy.com/) Powered by Discuz! X3.5