我试图使用来自 JWT 的 developerToken 获取 Apple Music SDK 的 userToken,但未成功。我使用了 pelauimagineering/apple-music-token-generator,我可以获得一个有效的静态 userToken。但苹果建议做动态,所以我想再次使用 JWT。
有人可以告诉我我的代码有什么问题吗?谢谢
func fetchDeveloperToken() -> String? {
func fetchDeveloperToken() -> String? {
let iat = Date().timeIntervalSince1970
let days = TimeInterval(24*60*60*120) //120 days
let exp = TimeInterval(iat + days)
let kid = "TBESJXXXXX"
let iss = "KQ6Z6XXXXX"
let alg = "ES256"
let secret = "MIGTAgEAMBMGByqEU7ZHQsoVfmKCCxS5W6BnCgCgYIKoZIzj0AAQcggNoN7dTkNG/8timkkf+Z2toogAqN41YgOXXXXXXXXXXXXXXXXXXsecretkey"
let header:[AnyHashable:Any] = ["alg":alg, "kid":kid]
let payload:[AnyHashable:Any] = ["iss": iss,
"iat": iat,
"exp": exp]
let algorithm256 = JWTAlgorithmHS256()
return JWT.encodePayload(payload, withSecret: secret, withHeaders: header, algorithm: algorithm256)
}