| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | 
							- #!/usr/bin/env python3  
 
- # -*- coding: utf-8 -*-  
 
- """
 
- @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
 
- @AUTHOR: ASJRD018
 
- @NAME: Ansjer
 
- @software: PyCharm
 
- @DATE: 2018/6/8 15:22
 
- @Version: python3.6
 
- @MODIFY DECORD:ansjer dev
 
- @file: encryHlsVodUrl.py
 
- @Contact: chanjunkai@163.com
 
- """
 
- # coding=utf-8
 
- # + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +
 
- #        ┏┓   ┏┓+ +
 
- #    ┏┛┻━━━┛┻┓ + +
 
- #    ┃       ┃  
 
- #    ┃   ━   ┃ ++ + + +
 
- #    ████━████ ┃+
 
- #    ┃       ┃ +
 
- #    ┃   ┻   ┃
 
- #    ┃       ┃ + +
 
- #    ┗━┓   ┏━┛
 
- #      ┃   ┃           
 
- #      ┃   ┃ + + + +
 
- #      ┃   ┃    Codes are far away from bugs with the animal protecting   
 
- #      ┃   ┃ +     神兽保佑,代码无bug  
 
- #      ┃   ┃
 
- #      ┃   ┃  +         
 
- #      ┃    ┗━━━┓ + +
 
- #      ┃        ┣┓
 
- #      ┃        ┏┛
 
- #      ┗┓┓┏━┳┓┏┛ + + + +
 
- #       ┃┫┫ ┃┫┫
 
- #       ┗┻┛ ┗┻┛+ + + +
 
- # + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +"""
 
- """
 
- """
 
- import base64
 
- import hashlib
 
- import time
 
- def md5(text, isBackByte=False):
 
-     """md5加密函数"""
 
-     md5 = hashlib.md5()
 
-     if isinstance(text, bytes):
 
-         md5.update(text)
 
-     else:
 
-         md5.update(text.encode('utf-8'))
 
-     if isBackByte:
 
-         # 返回二进制的加密结果
 
-         return md5.digest()
 
-         # 返回十六进制的机密结果
 
-     return md5.hexdigest()
 
- def base64_encode(text, isBytes=False):
 
-     """进行base64编码处理"""
 
-     if isBytes:
 
-         return base64.b64encode(text)
 
-     return base64.b64encode(bytes(text, encoding="utf-8"))
 
- def get_timestamp10():
 
-     """获取当前时间长度为10位长度的时间戳"""
 
-     return int(time.time())
 
- def getSignUrl(path):
 
-     secret = 'ansjer';  # 密钥--对应#st的哈希格式为 secret+url+e,e为时间戳单位s,url为请求地址  secure_link_md5 xiaozhong.com$uri$arg_e;
 
-     # 下载到期时间,time是当前时间,300表示300秒,也就是说从现在到300秒之内文件不过期
 
-     expire = get_timestamp10() + 1800;
 
-     res = md5(str(secret) + str(path) + str(expire), True)
 
-     md5str = str(base64_encode(res, True))
 
-     md5st = md5str.replace('b\'', '').replace('\'', '').replace('+', '-').replace('/', '_').replace('=', '')
 
-     url = 'http://52.8.197.107'+path+'.m3u8?' + 'st=' + str(md5st) + '&e=' + str(expire)
 
-     return url
 
- # print('生成代相关认证签名的地址:','http://192.168.136.45:8384/hls/5553.mp4/index.m3u8?' + 'st=' + str(md5) + '&e=' + str(expire))
 
- # print('生成代相关认证签名的地址:','http://52.8.197.107/444.mp4.m3u8?' + 'st=' + str(md5) + '&e=' + str(expire))
 
- # print('生成代相关认证签名的地址:','http://d3puj5e5oiunfy.cloudfront.net/444.mp4.m3u8?' + 'st=' + str(md5) + '&e=' + str(expire))
 
 
  |