val name = model[key] println("${name}:") val stores = result.getByPath("data.$key") as JSONArray stores.forEach { it?.let { store -> store as JSONObject if ("available" == store.getByPath("partsAvailability.${model}.pickupDisplay")) { HttpUtil.get("https://api.day.app/cfmJ23yrkJK2F62yHi92Cj/【${store["storeName"]}店】iPhone有货了") } else { println("${store["storeName"]} 无货") "> val name = model[key] println("${name}:") val stores = result.getByPath("data.$key") as JSONArray stores.forEach { it?.let { store -> store as JSONObject if ("available" == store.getByPath("partsAvailability.${model}.pickupDisplay")) { HttpUtil.get("https://api.day.app/cfmJ23yrkJK2F62yHi92Cj/【${store["storeName"]}店】iPhone有货了") } else { println("${store["storeName"]} 无货") "> val name = model[key] println("${name}:") val stores = result.getByPath("data.$key") as JSONArray stores.forEach { it?.let { store -> store as JSONObject if ("available" == store.getByPath("partsAvailability.${model}.pickupDisplay")) { HttpUtil.get("https://api.day.app/cfmJ23yrkJK2F62yHi92Cj/【${store["storeName"]}店】iPhone有货了") } else { println("${store["storeName"]} 无货") ">
class Main {
    fun check(model: Map<String, String>) {
        try {
            val url = "<https://iphone.odmay.cn/index/stocks>"
            val data = mapOf(
                "city" to "北京",
                "model" to JSONObject(model).toString()
            )
            val result = JSONObject(HttpUtil.post(url, data))
            (result.getByPath("data") as JSONObject).keys.forEach { key ->
                val name = model[key]
                println("${name}:")
                val stores = result.getByPath("data.$key") as JSONArray
                stores.forEach {
                    it?.let { store ->
                        store as JSONObject
                        if ("available" == store.getByPath("partsAvailability.${model}.pickupDisplay")) {
                            HttpUtil.get("<https://api.day.app/cfmJ23yrkJK2F62yHi92Cj/【${store["storeName"]}店】iPhone有货了>")
                        } else {
                            println("${store["storeName"]} 无货")
                        }
                    }
                }
                println("================")
                println()
            }
        } catch (e: Exception) {
            e.printStackTrace()
            HttpUtil.get("<https://api.day.app/cfmJ23yrkJK2F62yHi92Cj/发生异常了:${e.message}>")
        }
    }
}

fun main() {
    val task = Main()
    while (true) {
        // 型号 iPhone 13 pro max 256 黑色
        task.check(
            mapOf(
                "MLT93CH/A" to "iPhone 13 Pro 石墨色 256G",
                "MLTF3CH/A" to "iPhone 13 Pro 石墨色 512G"
            )
        )
        Thread.sleep(5000)
    }
}