[Python] - 芒果Tv tk2

2018-12-25 admin 算法

# -*- coding: UTF-8 -*-
import json
import sys
import base64
import uuid
import time

py3 = sys.version_info[0] == 3
if py3:
    maketrans = bytes.maketrans
    bytearray2str = bytearray.decode
else:
    from string import maketrans 
    bytearray2str = str

encode_translation = maketrans(b'+/=', b'_~-')
decode_translation = maketrans(b'_~-', b'+/=')
def encode_tk2(s):
    if not isinstance(s, bytes):
        s = s.encode()
    s = bytearray(base64.b64encode(s).translate(encode_translation))
    s.reverse()
    return bytearray2str(s)

def decode_tk2(s):
    if not isinstance(s, bytes):
        s = s.encode()
    s = bytearray(s)
    s.reverse()
    s = base64.b64decode(s.translate(decode_translation))
    if not isinstance(s, str):
        s = s.decode()
    return s

def generate_tk2(did):
    s = 'did={}|pno=1030|ver=0.3.0301|clit={}'.format(did, int(time.time()))
    return encode_tk2(s)

print( generate_tk2(str(uuid.uuid4()) );

标签: 芒果TV tk2 python py mgtv

评论:

爱好学习
2019-04-09 06:28
老大能不能发个php版本的,这个不会用
演员
2018-12-28 10:18
来看看
WRZ
2018-12-28 02:43
大佬懂的语言真多!
admin
2018-12-29 14:19
@WRZ:不多不多,伪技术小白人员而已

发表评论:

Powered by emlog