最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

B站自定義鉆石頭像

2023-04-07 20:42 作者:不曾紅到駭人聽聞  | 我要投稿

import time

from typing import Union

import requests

from hashlib import md5

from typing import Union

from urllib.parse import urlencode

from requests_toolbelt.multipart.encoder import MultipartEncoder

import imghdr


UID =? ?# 你的UID

ACCESS_KEY = "5e4a0522970a9e53d36c043f69edd011"??

FACE_PATH = r"E:\bili\custom_bilibili_nft\lee.jpg"

BG_PATH = r"E:\bili\custom_bilibili_nft\fl.jpg"??



class Crypto:


? ? APPKEY = ''

? ? APPSECRET = ''


? ? @staticmethod

? ? def md5(data: Union[str, bytes]) -> str:

? ? ? ? '''generates md5 hex dump of `str` or `bytes`'''

? ? ? ? if type(data) == str:

? ? ? ? ? ? return md5(data.encode()).hexdigest()

? ? ? ? return md5(data).hexdigest()


? ? @staticmethod

? ? def sign(data: Union[str, dict]) -> str:

? ? ? ? '''salted sign funtion for `dict`(converts to qs then parse) & `str`'''

? ? ? ? if isinstance(data, dict):

? ? ? ? ? ? _str = urlencode(data)

? ? ? ? elif type(data) != str:

? ? ? ? ? ? raise TypeError

? ? ? ? return Crypto.md5(_str + Crypto.APPSECRET)



class SingableDict(dict):

? ? @property

? ? def sorted(self):

? ? ? ? '''returns a alphabetically sorted version of `self`'''

? ? ? ? return dict(sorted(self.items()))


? ? @property

? ? def signed(self):

? ? ? ? '''returns our sorted self with calculated `sign` as a new key-value pair at the end'''

? ? ? ? _sorted = self.sorted

? ? ? ? return {**_sorted, 'sign': Crypto.sign(_sorted)}



def get_image_type(file_path):

? ? with open(file_path, 'rb') as f:

? ? ? ? data = f.read()

? ? return imghdr.what(None, data)



def upload_image(file_path):

? ? url = "https://api.bilibili.com/x/upload/app/image?access_key=" + ACCESS_KEY


? ? payload = {'bucket': 'medialist', 'dir': 'nft'}


? ? with open(file_path, 'rb') as f:

? ? ? ? type = f'image/{imghdr.what(f)}'

? ? ? ? print(type)

? ? ? ? files = [

? ? ? ? ? ? (

? ? ? ? ? ? ? ? 'file',

? ? ? ? ? ? ? ? (file_path, f, type),

? ? ? ? ? ? )

? ? ? ? ]

? ? ? ? response = requests.request("POST", url, data=payload, files=files)

? ? ? ? print(response.text)

? ? ? ? return response.json()['data']['location']



def get_one_card_id():

? ? url = "https://api.bilibili.com/x/vas/nftcard/cardlist"

? ? params = SingableDict(

? ? ? ? {

? ? ? ? ? ? "access_key": ACCESS_KEY,

? ? ? ? ? ? "act_id": "14",

? ? ? ? ? ? "appkey": "4409e2ce8ffd12b8",

? ? ? ? ? ? "disable_rcmd": "0",

? ? ? ? ? ? "ruid": UID,

? ? ? ? ? ? "statistics": "{\"appId\":1,\"platform\":3,\"version\":\"7.9.0\",\"abtest\":\"\"}",

? ? ? ? ? ? "ts": int(time.time()),

? ? ? ? }

? ? ).signed

? ? response = requests.request("GET", url, params=params)

? ? data = response.json()

? ? #if data['code'] == 0:

? ? ? ? #print(data)

? ? ? ? #return

? ? for card in data['data']['pre_list']:

? ? #for card in data['pre_list']:

? ? ? ? ? ? #print(card)

? ? ? ? ? ? ?#if card['card_id'] != null:

? ? ? ? ? ? ?#if card['card_type'] == 1 and card['card_id_list']:

? ? ? ? ? ? print("===============================================")

? ? ? ? ? ? ? ? #print(card['card_id_list'][0]['card_id'])

? ? ? ? ? ? print(card['card_id_list'])


? ? ? ? ? ? ? ? #return card['card_id_list'][0]['card_id']

? ? ? ? ? ? ? ? #return card['card_id_list']

? ? print('沒有 R 級別膠囊計(jì)劃的卡')

? ? return None



def set_face(card_id):

? ? api = "https://api.bilibili.com/x/member/app/face/digitalKit/update"

? ? params = SingableDict(

? ? ? ? {

? ? ? ? ? ? "access_key": ACCESS_KEY,

? ? ? ? ? ? "appkey": "4409e2ce8ffd12b8",

? ? ? ? ? ? "build": "7090300",

? ? ? ? ? ? "c_locale": "zh_CN",

? ? ? ? ? ? "channel": "xiaomi",

? ? ? ? ? ? "disable_rcmd": "0",

? ? ? ? ? ? "mobi_app": "android",

? ? ? ? ? ? "platform": "android",

? ? ? ? ? ? "s_locale": "zh_CN",

? ? ? ? ? ? "statistics": "{\"appId\":1,\"platform\":3,\"version\":\"7.9.0\",\"abtest\":\"\"}",

? ? ? ? ? ? "ts": int(time.time()),

? ? ? ? }

? ? ).signed

? ? m = MultipartEncoder(

? ? ? ? fields={

? ? ? ? ? ? 'digital_kit_id': str(card_id),

? ? ? ? ? ? 'face': ('face', open(FACE_PATH, 'rb'), 'application/octet-stream'),

? ? ? ? }

? ? )

? ? headers = {

? ? ? ? "Content-Type": m.content_type,

? ? }

? ? response = requests.request("POST", api, data=m, headers=headers, params=params)

? ? if response.json()['code'] != 0:

? ? ? ? print(response.json())

? ? ? ? return

? ? print('設(shè)置頭像成功, 請等待審核')



def set_bg_img(img_url, card_id):

? ? api = "https://app.bilibili.com//x/v2/space/digital/bind";

? ? data = SingableDict(

? ? ? ? {

? ? ? ? ? ? "access_key": ACCESS_KEY,

? ? ? ? ? ? "appkey": "4409e2ce8ffd12b8",

? ? ? ? ? ? "build": "7090300",

? ? ? ? ? ? "c_locale": "zh_CN",

? ? ? ? ? ? "card_id": card_id,

? ? ? ? ? ? "channel": "xiaomi",

? ? ? ? ? ? "disable_rcmd": "0",

? ? ? ? ? ? "img_url": img_url,

? ? ? ? ? ? "mobi_app": "android",

? ? ? ? ? ? "platform": "android",

? ? ? ? ? ? "s_locale": "zh_CN",

? ? ? ? ? ? "space_bg_type": "1",

? ? ? ? ? ? "statistics": "{\"appId\":1,\"platform\":3,\"version\":\"7.9.0\",\"abtest\":\"\"}",

? ? ? ? ? ? "ts": int(time.time()),

? ? ? ? }

? ? ).signed

? ? headers = {

? ? ? ? "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",

? ? }

? ? response = requests.request("POST", api, data=data, headers=headers)

? ? if response.json()['code'] != 0:

? ? ? ? print(response.json())

? ? ? ? return

? ? print('設(shè)置背景成功')



def main():

? ? #card_id = 19186420047872

? ? card_id = get_one_card_id()

? ? if not card_id:

? ? ? ? return

? ? # img_url = upload_image(BG_PATH)

? ? # set_bg_img(img_url, card_id)

? ? set_face(card_id)



if __name__ == '__main__':

? ? main()


B站自定義鉆石頭像的評論 (共 條)

分享到微博請遵守國家法律
航空| 马公市| 桃江县| 三门峡市| 静海县| 应用必备| 泽库县| 景洪市| 巴中市| 通许县| 崇州市| 县级市| 西城区| 梓潼县| 铜鼓县| 浑源县| 宁南县| 明溪县| 镇巴县| 乐都县| 光山县| 荆州市| 夏邑县| 莲花县| 蒙自县| 开原市| 巴南区| 河北区| 鱼台县| 依安县| 西充县| 都安| 仙桃市| 绥滨县| 永州市| 友谊县| 北宁市| 郑州市| 延寿县| 永康市| 瑞金市|