无聊写了个Minecraft皮肤获取,分享一些API

/ 0评 / 2

前言

今天无聊,写了一个灵工艺Minecraft皮肤获取器,抓了几个API和找了一个MinecraftAPI — Crafatar
目前已将代码开源 发布地址 | Github开源

本 博 惯 例

使用MojangAPI

我们使用 Jeb_(首席创意设计师) 为例
软件提供了两种方式的获取皮肤,但是都需要首先经过MojangAPI从用户名获取UUID

https://api.mojang.com/users/profiles/minecraft/Jeb_

返回JSON

{
  "name": "jeb_",
  "id": "853c80ef3c3749fdaa49938b674adae6"
}

id就是获取到的UUID后面就可以用于查询皮肤信息

https://sessionserver.mojang.com/session/minecraft/profile/853c80ef3c3749fdaa49938b674adae6

然后就会返回一个JSON串,里面的皮肤JSON数据是base64进行存储的 可以用这个在线工具解码调试BASE64加密解密

{
  "id": "853c80ef3c3749fdaa49938b674adae6",
  "name": "jeb_",
  "properties": [
    {
      "name": "textures",
      "value": "ewogICJ0ZXh0dXJlcyIgOiB7CiAgICAiQ0FQRSIgOiB7CiAgICAgICJpZCIgOiAiMDdjYjY1YWJhZjVlNGE2ZTg1NTA0NzdmZjZkNjczYzkiLAogICAgICAidHlwZSIgOiAiQ0FQRSIsCiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTc4NmZlOTliZTM3N2RmYjY4NTg4NTlmOTI2YzRkYmM5OTU3NTFlOTFjZWUzNzM0NjhjNWZiZjQ4NjVlNzE1MSIsCiAgICAgICJwcm9maWxlSWQiIDogIjg1M2M4MGVmM2MzNzQ5ZmRhYTQ5OTM4YjY3NGFkYWU2IiwKICAgICAgInRleHR1cmVJZCIgOiAiNTc4NmZlOTliZTM3N2RmYjY4NTg4NTlmOTI2YzRkYmM5OTU3NTFlOTFjZWUzNzM0NjhjNWZiZjQ4NjVlNzE1MSIKICAgIH0sCiAgICAiU0tJTiIgOiB7CiAgICAgICJpZCIgOiAiNWIyNzkzYjc4MjJkNDFhNmJkMjgxZGMwYmZhNmM3YWE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4NTlmOTI2YzRkYmM5OTU3NTFlOTFjZWUzNzM0NjhjNWZiZjQ4NjVlNzE1MSIsCiAgICAicHJvZmlsZUlkIiA6ICI4NTNjODBlZjNjMzc0OWZkYWE0OTkzOGI2NzRhZGFlNiIsCiAgICAidGV4dHVyZUlkIiA6ICI1Nzg2ZmU5OWJlMzc3ZGZiNjg1ODg1OWY5MjZjNGRiYzk5NTc1MWU5MWNlZTM3MzQ2OGM1ZmJmNDg2NWU3MTUxIgogIH0KfQ==",
      "signature": "n7rvOU6Tg46VVyvnuZoEIDjqFyKbaSHHVAI/+48LRzMZyLZ7O8bi04BtT+5xaaKfmrZfQQN6h4VxskTOG38tMfKRsqXTSTiCjMz2SUPJNqrjznbNrj6jQn2v0rULfXqY1MvyP5H8Dlf7z5RRdWrg9E+IS0PtqCAz7DjrX1JPCVi/ErWGnlKpcOvdHs8LQPYmCJYUcQd2yUPdeBcKlG5RB3kN0FnOCFiEGM3Og7rAJhlRXc2raj94SrU2d8XX6eyHVDQ/CbKGpXb3TtgtNiqYte0E7ltJzm9cWhSef5dcqzLkseUzzGT+LHW1rcjOXxVSnEt7KJgAkucXB928TAFhpsDRxNzfB9y+CyZEUAryQGTvkFrMB4iEcBvjM4uekHZXtJJFl9JrTYU0w+jtdvVQKmUNhRT5IBc/s9GbGV7VHUj7HS3qW1LMi/tBTJQQ/K8ffclNwz40bUaLuto/QZBydfr3c2sYlruylEEz/5oS0akcLGRwae4Q5DCs/LE5mjD+6cQCXu/bPhIw7bjepRDagfJXom2DVI4fy0iaiYNwY/1nPip7FnTntIv1Zir77j4Etq85bEwv6vEOvYp9SWrCd1wDV8KSZRLSJp6cy6ppjGfR/Fh9pdtYbMY6HEOe99XTi866H3qS/Qg4LIlIrfhEe3t9wC8sex9b8vnxEpdRjsA="
    }
  ]
}

现在你需要使用BASE64解码properties下的value就能获取到皮肤信息

{
  "textures" : {
    "CAPE" : {
      "id" : "07cb65abaf5e4a6e8550477ff6d673c9",
      "type" : "CAPE",
      "url" : "http://textures.minecraft.net/texture/5786fe99be377dfb6858859f926c4dbc995751e91cee373468c5fbf4865e7151",
      "profileId" : "853c80ef3c3749fdaa49938b674adae6",
      "textureId" : "5786fe99be377dfb6858859f926c4dbc995751e91cee373468c5fbf4865e7151"
    },
    "SKIN" : {
      "id" : "5b2793b7822d41a6bd281dc0bfa6c7aa",
      "type" : "SKIN",
      "url" : "http://textures.minecraft.net/texture/7fd9ba42a7c81eeea22f1524271ae85a8e045ce0af5a6ae16c6406ae917e68b5",
      "profileId" : "853c80ef3c3749fdaa49938b674adae6",
      "textureId" : "7fd9ba42a7c81eeea22f1524271ae85a8e045ce0af5a6ae16c6406ae917e68b5"
    }
  },
  "skin" : {
    "id" : "5b2793b7822d41a6bd281dc0bfa6c7aa",
    "type" : "SKIN",
    "url" : "http://textures.minecraft.net/texture/7fd9ba42a7c81eeea22f1524271ae85a8e045ce0af5a6ae16c6406ae917e68b5",
    "profileId" : "853c80ef3c3749fdaa49938b674adae6",
    "textureId" : "7fd9ba42a7c81eeea22f1524271ae85a8e045ce0af5a6ae16c6406ae917e68b5"
  },
  "cape" : {
    "id" : "07cb65abaf5e4a6e8550477ff6d673c9",
    "type" : "CAPE",
    "url" : "http://textures.minecraft.net/texture/5786fe99be377dfb6858859f926c4dbc995751e91cee373468c5fbf4865e7151",
    "profileId" : "853c80ef3c3749fdaa49938b674adae6",
    "textureId" : "5786fe99be377dfb6858859f926c4dbc995751e91cee373468c5fbf4865e7151"
  }
}

拥有披风的同时也会返回披风数据 皮肤数据是skin,cape是披风
以上就是MojangAPI的使用

使用Crafatar第三方API

虽然是使用第三方,但是你还得通过MojangAPI先获取UUID

https://api.mojang.com/users/profiles/minecraft/Jeb_

返回JSON

{
  "name": "jeb_",
  "id": "853c80ef3c3749fdaa49938b674adae6"
}

当你有了UUID那么就非常简单了,它直接使用对应的URL+UUID即可返回对应的数据 例如

头像 Jeb_头像

https://crafatar.com/avatars/853c80ef3c3749fdaa49938b674adae6
可以使用 ?size=数值 来控制图片大小
https://crafatar.com/avatars/853c80ef3c3749fdaa49938b674adae6?size=64

头颅 Jeb_头颅

https://crafatar.com/renders/head/853c80ef3c3749fdaa49938b674adae6

整个身体 Jeb_身体

https://crafatar.com/renders/body/853c80ef3c3749fdaa49938b674adae6

皮肤 Jeb_皮肤 披风 Jeb_披风

皮肤 https://crafatar.com/skins/853c80ef3c3749fdaa49938b674adae6
披风 https://crafatar.com/capes/853c80ef3c3749fdaa49938b674adae6?default=853c80ef3c3749fdaa49938b674adae6

文笔不好,就不写骚话了,就这样8,希望这篇文章对你有所帮助

发表评论

电子邮件地址不会被公开。 必填项已用*标注