{"id":18267661,"url":"https://github.com/oxeu/ricq_cp29_bot","last_synced_at":"2025-07-27T22:36:45.564Z","repository":{"id":153007225,"uuid":"627834023","full_name":"OXeu/ricq_cp29_bot","owner":"OXeu","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-14T11:06:48.000Z","size":266,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T20:57:22.445Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OXeu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-14T09:53:18.000Z","updated_at":"2024-07-29T06:58:37.000Z","dependencies_parsed_at":"2024-03-26T08:43:41.130Z","dependency_job_id":null,"html_url":"https://github.com/OXeu/ricq_cp29_bot","commit_stats":null,"previous_names":["oxeu/ricq_cp29_bot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OXeu%2Fricq_cp29_bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OXeu%2Fricq_cp29_bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OXeu%2Fricq_cp29_bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OXeu%2Fricq_cp29_bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OXeu","download_url":"https://codeload.github.com/OXeu/ricq_cp29_bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247964462,"owners_count":21025196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:28:12.443Z","updated_at":"2025-04-09T02:27:20.341Z","avatar_url":"https://github.com/OXeu.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ricq-axum-api\n\n1. 下载 UI 文件，放在工作目录 static 文件夹\n\n```bash\n wget https://github.com/lz1998/ricq-react-ui/releases/latest/download/static.zip \u0026\u0026 unzip static.zip \u0026\u0026 rm static.zip\n```\n\n2. 实现 Processor trait（仅包含登录后处理逻辑）\n\n\u003e 参考 [processor.rs](https://github.com/lz1998/ricq/blob/master/examples/ricq-axum-api/src/processor.rs#L28)\n\n```rust\n#[async_trait::async_trait]\npub trait Processor {\n    async fn on_login_success(\n        \u0026self,\n        client: Arc\u003cClient\u003e,\n        event_receiver: broadcast::Receiver\u003cQEvent\u003e,\n        credential: Credential,\n        network_join_handle: JoinHandle\u003c()\u003e,\n    );\n    async fn list_client(\u0026self) -\u003e Vec\u003cClientInfo\u003e;\n    async fn delete_client(\u0026self, uin: i64, protocol: u8);\n} \n```\n\n3. 创建 RicqAxumApi，并启动 axum 服务器\n\n```rust\n#![feature(async_closure)]\n\nuse std::net::SocketAddr;\nuse std::str::FromStr;\nuse std::sync::Arc;\n\nuse axum::{\n    routing::{get, get_service, post},\n    Extension, Router,\n};\nuse dashmap::DashMap;\nuse tower::ServiceBuilder;\nuse tower_http::services::ServeDir;\n\nuse ricq::Client;\nuse ricq_axum_api::handler::{bot, password, qrcode};\nuse ricq_axum_api::RicqAxumApi;\n\ntype ClientProcessor = DashMap\u003c(i64, u8), Arc\u003cClient\u003e\u003e;\n\n#[tokio::main]\nasync fn main() {\n    // 默认处理器，登录后什么也不做，仅作为容器\n    let processor = ClientProcessor::default();\n    let ricq_axum_api = Arc::new(RicqAxumApi::new(processor));\n\n    let app = Router::new()\n        .route(\"/ping\", get(async move || \"pong\"))\n        .nest(\n            \"/login\",\n            Router::new()\n                .nest(\n                    \"/qrcode\",\n                    Router::new()\n                        .route(\"/create\", post(qrcode::create))\n                        .route(\"/list\", get(qrcode::list))\n                        .route(\"/delete\", post(qrcode::delete))\n                        .route(\"/query\", post(qrcode::query)),\n                )\n                .nest(\n                    \"/password\",\n                    Router::new()\n                        .route(\"/create\", post(password::login))\n                        .route(\"/request_sms\", post(password::request_sms))\n                        .route(\"/submit_sms\", post(password::submit_sms))\n                        .route(\"/submit_ticket\", post(password::submit_ticket))\n                        .route(\"/list\", get(password::list))\n                        .route(\"/delete\", post(password::delete)),\n                ),\n        )\n        .nest(\n            \"/bot\",\n            Router::new()\n                .route(\"/list\", get(bot::list))\n                .route(\"/delete\", post(bot::delete)),\n        )\n        .fallback(get_service(ServeDir::new(\"static\")).handle_error(handle_error))\n        .layer(\n            ServiceBuilder::new()\n                .layer(Extension(ricq_axum_api))\n                .into_inner(),\n        );\n    let addr = SocketAddr::from_str(\"0.0.0.0:9000\").expect(\"failed to parse bind_addr\");\n    println!(\"listening on {}\", addr);\n    axum::Server::bind(\u0026addr)\n        .serve(app.into_make_service())\n        .await\n        .unwrap();\n}\n\nasync fn handle_error(_: std::io::Error) -\u003e impl axum::response::IntoResponse {\n    (axum::http::StatusCode::NOT_FOUND, \"Something went wrong...\")\n}\n```\n\n4. 访问 `http://localhost:9000`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxeu%2Fricq_cp29_bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxeu%2Fricq_cp29_bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxeu%2Fricq_cp29_bot/lists"}