{"id":21626671,"url":"https://github.com/rtakland/qweathersdk","last_synced_at":"2025-04-11T12:46:37.147Z","repository":{"id":65795801,"uuid":"592726763","full_name":"RTAkland/QWeatherSDK","owner":"RTAkland","description":"一个非官方的和风天气 Kotlin/Java SDK, 基于 WebAPI. An unofficial kotlin/java sdk for qweatehr based on web api","archived":false,"fork":false,"pushed_at":"2025-02-21T09:40:00.000Z","size":406,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T09:03:42.860Z","etag":null,"topics":["java","kotlin","qweather","sdk","weather"],"latest_commit_sha":null,"homepage":"https://rtakland.github.io/QWeatherSDK/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RTAkland.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2023-01-24T12:00:39.000Z","updated_at":"2025-02-21T09:40:04.000Z","dependencies_parsed_at":"2024-10-19T07:15:24.450Z","dependency_job_id":"9ec00c73-b20b-475a-92f0-ea04dc1faf2a","html_url":"https://github.com/RTAkland/QWeatherSDK","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RTAkland%2FQWeatherSDK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RTAkland%2FQWeatherSDK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RTAkland%2FQWeatherSDK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RTAkland%2FQWeatherSDK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RTAkland","download_url":"https://codeload.github.com/RTAkland/QWeatherSDK/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248402546,"owners_count":21097331,"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":["java","kotlin","qweather","sdk","weather"],"created_at":"2024-11-25T01:14:02.031Z","updated_at":"2025-04-11T12:46:37.132Z","avatar_url":"https://github.com/RTAkland.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://static.rtast.cn/static/qwsdk/qwsdkIcon.png\" alt=\"SDKIcon\"\u003e\n\n\u003ch3\u003eMade By \u003ca href=\"https://github.com/RTAkland\"\u003eRTAkland\u003c/a\u003e\u003c/h3\u003e\n\n\u003cimg src=\"https://static.rtast.cn/static/kotlin/made-with-kotlin.svg\" alt=\"MadeWithKotlin\"\u003e\n\n\u003cbr\u003e\n\u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/actions/workflow/status/RTAkland/QWeatherSDK/build.yml\"\u003e\n\u003cimg alt=\"Kotlin Version\" src=\"https://img.shields.io/badge/Kotlin-2.0.0-pink?logo=kotlin\"\u003e\n\u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/RTAkland/QWeatherSDK?logo=apache\"\u003e\n\u003ca href=\"https://jitpack.io/#RTAkland/QWeatherSDK\"\u003e\u003cimg alt=\"jitpackV\" src=\"https://jitpack.io/v/RTAkland/QWeatherSDK.svg\"\u003e\u003c/a\u003e\n\n\u003c/div\u003e\n\n# 概述\n\n\u003e 本项目是一个非官方的[`QWeather`](https://dev.qweather.com) `Kotlin / Java / Android SDK`, 可以在基于`JVM`的语言使用,\n\u003e 例如[`Kotlin`](https://kotl.in)、[`Java`](https://java.com)、[`Scala`](https://www.scala-lang.org/)\n\n\u003e 本项目基于`Web API` 所以只需要申请一个`Web API key` 和这个key对应的`Public ID`即可使用,\n\u003e 点击[这里](https://dev.qweather.com/docs/configuration/project-and-key/)\n\u003e 来查看如何申请一个`Web API key`\n\n# 目录\n\n\u003c!-- TOC --\u003e\n* [概述](#概述)\n* [目录](#目录)\n* [使用](#使用)\n  * [添加依赖](#添加依赖)\n    * [本地文件](#本地文件)\n    * [Jitpack](#jitpack)\n    * [fatjar](#fatjar)\n      * [Groovy DSL](#groovy-dsl)\n      * [Kotlin DSL](#kotlin-dsl)\n  * [使用例子](#使用例子)\n    * [Kotlin](#kotlin)\n    * [Java](#java)\n    * [Scala](#scala)\n* [数据类](#数据类)\n* [单元测试](#单元测试)\n* [注意事项](#注意事项)\n* [开发](#开发)\n  * [克隆项目](#克隆项目)\n  * [手动编译](#手动编译)\n* [开源](#开源)\n* [鸣谢](#鸣谢)\n\u003c!-- TOC --\u003e\n\n# 使用\n\n## 添加依赖\n\n### 本地文件\n\n\u003e 以 `Groovy DSL` 为例\n\n```groovy\n// 添加gson 和 QWeatherSDK 依赖\ndependencies {\n    implementation(\"com.google.code.gson:gson:2.10.1\")\n    implementation(files(\"./lib/QWeatherSDK.jar\"))\n}\n```\n\n\u003e 你也可以使用 [`jitpack`](https://jitpack.io) 来获取依赖\n\n### Jitpack\n\n```groovy\n\nrepositories {\n    // other repos...\n    maven { url \"https://jitpack.io\" }\n    // maven.rtast.cn, 二选一\n    maven { url \"https://maven.rtast.cn/releases/\" }\n}\n\ndependencies {\n    implementation(\"com.google.code.gson:gson:2.10.1\")\n    implementation(\"com.github.RTAkland:QWeatherSDK:v0.4.3\")\n}\n```\n\n### fatjar\n\n\u003e 如果想要将获取fatjar包你需要使用以下方法获取, 下面提供了两种脚本语言的解决方法\n\n#### Groovy DSL\n\n```groovy\nconfigurations {\n    embed\n    compile.extendsFrom(embed)\n}\n\n// other configurations...\n\njar {\n    duplicatesStrategy = DuplicatesStrategy.EXCLUDE  // 排除重复的依赖文件\n    from configurations.embed.collect {\n        it.isDirectory() ? it : zipTree(it)\n    }\n}\n\ndependencies {\n    implementation(\"com.github.RTAkland:QWeatherSDK:v0.4.3\")  // 这里需要用常规方法添加依赖\n    embed(api(\"com.github.RTAkland:QWeatherSDK:v0.4.3\"))  // 必须在这里使用embed再添加一次\n}\n```\n\n\u003e 使用embed将会把embed内包裹的库中的.class文件全部打包进, 你的jar文件中\n\u003e 如果库使用了别的库, 那embed也会把该库使用的库的.class文件打包进你的jar中 和 shadowJar比较类似\n\u003e 和gradle中的include类似, 但是gradle是将依赖jar打包进jar\n\u003e embed 不会和implementation关键字冲突, embed仅在编译时生效\n\u003e 使用embed后就可以在独立的环境运行而不需要额外下载依赖\n\n#### Kotlin DSL\n\n\u003e 以下是使用Kotlin作为Gradle构建脚本的解决方法\n\n```kotlin\n\n// other configurations...\n\ndependencies {\n    implementation(\"com.github.RTAkland:QWeatherSDK:v0.4.3\")  // 直接使用常规方法添加依赖\n}\n\ntasks.jar {\n    duplicatesStrategy = DuplicatesStrategy.EXCLUDE\n    val files = configurations.runtimeClasspath.get()\n        .filter { it.exists() }\n        .map { if (it.isDirectory) it else zipTree(it) }\n    from(files)\n}\n\n```\n\n## 使用例子\n\n### Kotlin\n\n```kotlin\nimport cn.rtast.qwsdk.QWeatherSDK\nimport cn.rtast.qwsdk.enums.Plans\n\nfun main() {\n    val qw = QWeatherSDK(\"\u003cthis is your key\u003e\",\"\u003cthis is your key's publicid\u003e\", Plans.Free)\n    // 可用的计划有 Free, Standard, Custom\n    val response = qw.weather().now(\"101010100\")  // 填入对应的数据, 这里只需要填写一个\n    println(response)  // 返回的数据已经被反序列化, 可以直接访问对应的数据类来获取数据\n}\n```\n\n### Java\n\n```java\nimport cn.rtast.qwsdk.QWeatherSDK;\nimport cn.rtast.qwsdk.enums.Plans;\n\npublic class Main {\n    public static void main(String[] args) {\n        QWeatherSDK qw = new QWeatherSDK(\"\u003cthis is your key\u003e\", \"\u003cthis is your key's publicid\u003e\", Plans.Free);\n        System.out.println(qw.weather().now(\"101010100\"));\n        // 最后两个参数有默认值, 通过给函数添加@JvmOverloads注解在编译时生成重载函数来实现Java参数默认值\n    }\n}\n```\n\n### Scala\n\n```scala\nimport cn.rtast.qwsdk.QWeatherSDK\nimport cn.rtast.qwsdk.enums.Plans\n\nobject Main extends App {\n  val qw = new QWeatherSDK(\"\u003cthis is your key\", \"\u003cthis is your key's publicid\u003e\", Plans.Free)\n  println(qw.weather().now(\"101010100\"))\n}\n```\n\n# 数据类\n\n\u003e 请点击[这里](/docs/README.md)查看\n\n# 单元测试\n\n\u003e 在`v0.2.0`版本添加了单元测试, 如果想要使用单元测试你需要添加两个环境变量 `QW_KEY` `QW_PLAN`,\n\u003e 这两个变量分别代表 [QWeather Key](https://dev.qweather.com/docs/configuration/project-and-key/) 和 key的版本,\n\u003e `QW_PLAN` 可用数据有 `free` `standard` `custom` ***不区分大小写, 但是变量名必须大写***\n\u003e 测试完成后你可以在`build/reports/tests/test/index.html` 找到测试报告\n\n\u003e 如果你的Key无法使用某些api那么这个测试则会直接跳过并判定为成功,\n\u003e 你可以在[这里](https://dev.qweather.com/docs/finance/subscription/#comparison)找到各种订阅之间的差别\n\n# 注意事项\n\n\u003e 本SDK无法使用[`太阳辐射`](https://dev.qweather.com/docs/api/solar-radiation/solar-radiation-hourly-forecast/)\n\u003e 因为没有条件测试返回结果, 并且官方文档也没有写明返回的数据, 故无法创建数据类实现接口\n\n\u003e 目前编译出的产物的JVM版本为 1.8, 所以你至少需要JVM1.8以上版本来使用此SDK\n\n# 开发\n\n* 建议使用`Intellij IDEA` 进行开发\n\n## 克隆项目\n\n```shell\n$ git clone https://github.com/RTAkland/QWeatherSDK.git\n```\n\n## 手动编译\n\n\u003e Linux/Unix/Mac OS\n\n```shell\n$ chmod +x ./gradlew\n$ ./gradlew build\n```\n\n\u003e Windows\n\n```shell\n$ .\\gradlew.bat build\n```\n\n# 开源\n\n- 本项目以[Apache-2.0](./LICENSE)许可开源, 即:\n    - 你可以直接使用该项目提供的功能, 无需任何授权\n    - 你可以在**注明来源版权信息**的情况下对源代码进行任意分发和修改以及衍生\n\n# 鸣谢\n\n\u003cdiv\u003e\n\n\u003cimg src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png\" alt=\"JetBrainsIcon\" width=\"128\"\u003e\n\n\u003ca href=\"https://www.jetbrains.com/opensource/\"\u003e\u003ccode\u003eJetBrains Open Source\u003c/code\u003e\u003c/a\u003e 提供的强大IDE支持\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtakland%2Fqweathersdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtakland%2Fqweathersdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtakland%2Fqweathersdk/lists"}