跳转至

Namespace qqmusic::utils

Namespace List > qqmusic > utils

简易Cookie管理器, 负责cookie的序列化和反序列化, 依赖 nlohmann::json 实现 目前不支持路径嵌套和Expires HttpOnly 这样的特性More...

Classes

Type Name
class AsyncExecutor
全局调度器类
struct Cookie
代表一条Cookie
class CookieJar
简易Cookie管理器, 负责cookie的序列化和反序列化, 依赖 nlohmann::json 实现 目前不支持路径嵌套和Expires HttpOnly 这样的特性
class Credential
凭据信息类
struct Device
设备信息
class Exception
全局异常类
struct OSVersion
class PathManager
返回默认路径
struct QimeiResult
class Session
上下文
class SessionGuard
一个 RAII 风格的Session切换器
class SessionManager
全局单例的Session管理器, 负责维护全局上下文栈, 并负责 session 实例的生成
class buffer
二进制缓冲区的统一表示

Public Types

Type Name
typedef http::response< http::dynamic_body > HttpResponse
enum qrc_type
QRC歌词种类

Public Functions

Type Name
qqmusic::Result< void > cache_device (const Device & device)
将设备信息缓存到文件缓存路径下的 device.json __
boost::asio::awaitable< void > custom_co_spawn_entry_point (boost::asio::awaitable< T, Executor > aw, std::function< void(std::exception_ptr, std::optional< T >)> handler)
Result<>不能进行拷贝, 也没有默认构造函数. boost::asio::co_spawn中会调用默认构造函数. 所以需要包装原本的异步任务, 使用移动构造函数来构造result
qqmusic::Result< Device > get_device_info ()
获取随机设备信息
qqmusic::Result< QimeiResult > get_qimei (qqmusic::utils::Device & device, std::string_view version)
std::string get_search_id ()
返回随机搜索ID
uint64_t hash33 (std::string_view str, uint64_t prev=0)
计算utf-8字符串的哈希值
buffer hex2buf (std::string_view hex)
十六进制字符串转成buffer
qqmusic::Result< nlohmann::json > parse_cookie (std::string_view cookie_str)
将Cookie字符串解析成Json对象
qqmusic::Result< std::string > qrc_decode (const qqmusic::utils::buffer & src, qqmusic::utils::qrc_type type)
解码加密的QRC歌词
buffer resp2buf (http::response< http::dynamic_body > && resp)
将请求回复报文体转换成二进制buffer
std::string sign (const nlohmann::json & params)
QQ音乐请求签名
T sync_exec (boost::asio::io_context & ioc, qqmusic::Task< T > task)
同步执行异步函数
T sync_exec (qqmusic::Task< T > task)
同步执行异步函数

Public Static Functions

Type Name
int decompress (const buffer & src, buffer & dest)
std::string head (std::span< uint8_t > data)
std::string middle (std::span< uint8_t > data)
void qmc1_decrypt (buffer & src)
std::string tail (std::span< uint8_t > data)

Detailed Description

API异常类, 提供全局错误类型表示

设备信息提供设备信息描述, 随机生成设备信息

QQ音乐账号凭据, 部分和会员, 用户相关的Api需要依靠传入凭据才能生效, 凭据由Login部分的 Api获取

-------------------------------qqmusic/utils/common.h--------------------------------------

@ brief 工具函数

@ date 2025-3-21

------------------------------qqmusic/details/cookie.h-------------------------------------

Date:

2025-3-21

-------------------------------------utils/credential.h------------------------------------

Date:

2025-3-21

--------------------------------qqmusic/details/device.h-----------------------------------

Date:

2025-3-21

----------------------------qqmusic/utils/exception.h--------------------------------------

Date:

2025-3-21

---------------------------------------utils/paths.h--------------------------------------- PathManager provide common interface to file system.

PathManager provide 3 types of files for io : log, cache, download * log for debug log info * cache for cached credential, identification, recent cached songs * download for downloaded media and lyrics

Default paths are: * Linux: * cache: $XDG_CACHE_HOME/qqmusic-api-cxx/cache OR $HOME/.cache/qqmusic-api-cxx/cache * log: $XDG_CACHE_HOME/qqmusic-api-cxx/log OR $HOME/.cache/qqmusic-api-cxx/log * download: $HOME/Download/qqmusic-api-cxx

Applications can set the path by themselves Usage:

@icode

"get instance first" auto& pm = PathManager::get_instance(); auto cache_path = cm.get_cache_path();

Public Types Documentation

typedef HttpResponse

using qqmusic::utils::HttpResponse = typedef http::response<http::dynamic_body>;

enum qrc_type

QRC歌词种类

enum qqmusic::utils::qrc_type {
    cloud,
    local
};


Public Functions Documentation

function cache_device

将设备信息缓存到文件缓存路径下的 device.json __

qqmusic::Result< void > qqmusic::utils::cache_device (
    const Device & device
) 

See also: qqmusic::utils::PathManager


function custom_co_spawn_entry_point

Result<>不能进行拷贝, 也没有默认构造函数. boost::asio::co_spawn中会调用默认构造函数. 所以需要包装原本的异步任务, 使用移动构造函数来构造result

template<typename T, typename Executor>
boost::asio::awaitable< void > qqmusic::utils::custom_co_spawn_entry_point (
    boost::asio::awaitable< T, Executor > aw,
    std::function< void(std::exception_ptr, std::optional< T >)> handler
) 

Parameters:

  • aw 异步任务
  • handler 回调函数

Note:

回调函数的签名是void(std::exception_ptr, std::optional<T>), 前一个参数是处理异常的, 后一个参数是正常的返回结果. 如果出错, 则返回结果的std::optional置空

See also: qqmusic::Result


function get_device_info

获取随机设备信息

qqmusic::Result< Device > qqmusic::utils::get_device_info () 

Returns:

包含正确结果或异常的Result < Device >


function get_qimei

qqmusic::Result< QimeiResult > qqmusic::utils::get_qimei (
    qqmusic::utils::Device & device,
    std::string_view version
) 

function get_search_id

返回随机搜索ID

std::string qqmusic::utils::get_search_id () 


function hash33

计算utf-8字符串的哈希值

uint64_t qqmusic::utils::hash33 (
    std::string_view str,
    uint64_t prev=0
) 

Parameters:

  • str 待求值字符串
  • prev 多次求值时传入上次求出的结果, 默认为0

Returns:

64位整数格式的哈希


function hex2buf

十六进制字符串转成buffer

buffer qqmusic::utils::hex2buf (
    std::string_view hex
) 

Parameters:

  • hex 十六进制编码字符串

Returns:

qqmusic::utils::buffer类型buffer


将Cookie字符串解析成Json对象

qqmusic::Result< nlohmann::json > qqmusic::utils::parse_cookie (
    std::string_view cookie_str
) 

key1=value1; key2=value2; key3=value3; key4=value4
     |
     v
{
    "key1": "value1",
    "key2": "value2",
    "key3": "value3",
    "key4": "value4",
}

function qrc_decode

解码加密的QRC歌词

qqmusic::Result< std::string > qqmusic::utils::qrc_decode (
    const qqmusic::utils::buffer & src,
    qqmusic::utils::qrc_type type
) 

Parameters:

  • src 被加密的歌词
  • type 歌词类型

Returns:

解码后的字符串, 如果出错会返回Exception


function resp2buf

将请求回复报文体转换成二进制buffer

buffer qqmusic::utils::resp2buf (
    http::response< http::dynamic_body > && resp
) 

Parameters:

  • resp 回复报文

Returns:

qqmusic::utils::buffer类型buffer


function sign

QQ音乐请求签名

std::string qqmusic::utils::sign (
    const nlohmann::json & params
) 

Parameters:

  • params 请求数据表单

Returns:

签名结果


function sync_exec

同步执行异步函数

template<typename T>
T qqmusic::utils::sync_exec (
    boost::asio::io_context & ioc,
    qqmusic::Task< T > task
) 

Parameters:

  • ioc 当前io_context引用
  • task 异步任务

Returns:

返回执行结果

Exception:

  • std::runtime_error

function sync_exec

同步执行异步函数

template<typename T>
T qqmusic::utils::sync_exec (
    qqmusic::Task< T > task
) 

Parameters:

  • task 异步任务

Returns:

返回执行结果


Public Static Functions Documentation

function decompress

static int qqmusic::utils::decompress (
    const buffer & src,
    buffer & dest
) 

function head

static std::string qqmusic::utils::head (
    std::span< uint8_t > data
) 

function middle

static std::string qqmusic::utils::middle (
    std::span< uint8_t > data
) 

function qmc1_decrypt

static void qqmusic::utils::qmc1_decrypt (
    buffer & src
) 

function tail

static std::string qqmusic::utils::tail (
    std::span< uint8_t > data
) 


The documentation for this class was generated from the following file src/utils/async-executor.cc