前言
今天无聊,写了一个灵工艺Minecraft皮肤获取器,抓了几个API和找了一个MinecraftAPI — Crafatar
目前已将代码开源 发布地址 | Github开源
API调用
Mojang(官方) API
我们使用 Jeb_(首席创意设计师) 为例
软件提供了两种方式的获取皮肤,但是都需要首先经过MojangAPI从用户名获取UUID
1 2 3
| https://api.mojang.com/users/profiles/minecraft/{USERNAME} 拼接URL: https://api.mojang.com/users/profiles/minecraft/Jeb_
|
返回JSON
1 2 3 4
| { "name": "jeb_", "id": "853c80ef3c3749fdaa49938b674adae6" }
|
id就是获取到的UUID后面就可以用于查询皮肤信息。
1 2 3
| https://sessionserver.mojang.com/session/minecraft/profile/{UUID} 拼接URL: https://sessionserver.mojang.com/session/minecraft/profile/853c80ef3c3749fdaa49938b674adae6
|
然后就会返回一个JSON串,里面的皮肤JSON数据是base64进行存储的。
1 2 3 4 5 6 7 8 9 10 11
| { "id": "853c80ef3c3749fdaa49938b674adae6", "name": "jeb_", "properties": [ { "name": "textures", "value": "ewogICJ0ZXh0dXJlcyIgOiB7CiAgICAiQ0FQRSIgOiB7CiAgICAgICJpZCIgOiAiMDdjYjY1YWJhZjVlNGE2ZTg1NTA0NzdmZjZkNjczYzkiLAogICAgICAidHlwZSIgOiAiQ0FQRSIsCiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTc4NmZlOTliZTM3N2RmYjY4NTg4NTlmOTI2YzRkYmM5OTU3NTFlOTFjZWUzNzM0NjhjNWZiZjQ4NjVlNzE1MSIsCiAgICAgICJwcm9maWxlSWQiIDogIjg1M2M4MGVmM2MzNzQ5ZmRhYTQ5OTM4YjY3NGFkYWU2IiwKICAgICAgInRleHR1cmVJZCIgOiAiNTc4NmZlOTliZTM3N2RmYjY4NTg4NTlmOTI2YzRkYmM5OTU3NTFlOTFjZWUzNzM0NjhjNWZiZjQ4NjVlNzE1MSIKICAgIH0sCiAgICAiU0tJTiIgOiB7CiAgICAgICJpZC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lY3JhZnQubmV0L3RleHR1cmUvNTc4NmZlOTliZTM3N2RmYjY4NTg4NTlmOTI2YzRkYmM5OTU3NTFlOTFjZWUzNzM0NjhjNWZiZjQ4NjVlNzE1MSIsCiAgICAicHJvZmlsZUlkIiA6ICI4NTNjODBlZjNjMzc0OWZkYWE0OTkzOGI2NzRhZGFlNiIsCiAgICAidGV4dHVyZUlkIiA6ICI1Nzg2ZmU5OWJlMzc3ZGZiNjg1ODg1OWY5MjZjNGRiYzk5NTc1MWU5MWNlZTM3MzQ2OGM1ZmJmNDg2NWU3MTUxIgogIH0KfQ==", "signature": "n7rvOU6Tg46VVyvnuZoEIDjqFyKbaSHHVAI/+48LRzMZyLZ7O8bi04BtT+5xaaKfmrZfQQN6h4VxskTOG38tMfKRsqXTSTiCjMz2SUPJNqrjznbNrj6jQn2v0rULfXqY1MvyP5H8Dlf7z5RRdWrg9E+IS0PtqCAz7DjrX1JPCVi/ErWGnlKpcOvdHs8LQPYmCJYUcQd2yUPdeBcKlG5RB3kN0FnOCFiEGM3Og7rAJhlRXc2raj94SrU2d8XX6eyHVDQ/CbKGpXb3TtgtNiqYte0E7ltJzm9cWhSef5dcqzLkseUzzGT+LHW1rcjOXxVSnEt7KJgAkucXB928TAFhpsDRxNzfB9y+CyZEUAryQGTvkFrMB4iEcBvjM4uekHZXtJJFl9JrTYU0w+jtdvVQKmUNhRT5IBc/s9GbGV7VHUj7HS3qW1LMi/tBTJQQ/K8ffclNwz40bUaLuto/QZBydfr3c2sYlruylEEz/5oS0akcLGRwae4Q5DCs/LE5mjD+6cQCXu/bPhIw7bjepRDagfJXom2DVI4fy0iaiYNwY/1nPip7FnTntIv1Zir77j4Etq85bEwv6vEOvYp9SWrCd1wDV8KSZRLSJp6cy6ppjGfR/Fh9pdtYbMY6HEOe99XTi866H3qS/Qg4LIlIrfhEe3t9wC8sex9b8vnxEpdRjsA=" } ] }
|
现在你需要使用BASE64解码properties下的value就能获取到皮肤信息。
(可以用这个在线工具解码调试BASE64加密解密)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| 解密后: { "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是披风。然后就可以根据自己需求使用了。
Crafatar(第三方) API
如果你嫌官方的麻烦,可以用第三方API,当然稳定性跟随第三方开发者而定。
虽然是使用第三方,但是你还得通过MojangAPI先获取UUID
1
| https://api.mojang.com/users/profiles/minecraft/Jeb_
|
返回JSON
1 2 3 4
| { "name": "jeb_", "id": "853c80ef3c3749fdaa49938b674adae6" }
|
当你有了UUID那么就非常简单了,它直接使用对应的URL+UUID即可返回对应的数据.
例如
头像
1 2 3
| https://crafatar.com/avatars/853c80ef3c3749fdaa49938b674adae6 可以使用 ?size=数值 来控制图片大小 https://crafatar.com/avatars/853c80ef3c3749fdaa49938b674adae6?size=64
|
头颅
1
| https://crafatar.com/renders/head/853c80ef3c3749fdaa49938b674adae6
|
整个身体
1
| https://crafatar.com/renders/body/853c80ef3c3749fdaa49938b674adae6
|
皮肤与披风
1 2
| 皮肤 https://crafatar.com/skins/853c80ef3c3749fdaa49938b674adae6 披风 https://crafatar.com/capes/853c80ef3c3749fdaa49938b674adae6?default=853c80ef3c3749fdaa49938b674adae6
|
大致就是这样。