4 回答

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
我也遇到這個(gè)問題,我和隊(duì)友解決了。。。。。
解決方案:
刪除有效負(fù)載中的“iat”(這很重要):像這樣,
let payload = {
iss: *******,
exp: *******,
aud: "appstoreconnect-v1",
bid: "your_bundle_id",
};
網(wǎng)址:我用的是axios:
const { data } = await axios({
method: "GET",
url: "https://api.storekit.itunes.apple.com/inApps/v1/history/",
headers: {
"Content-type": "application/json",
Authorization: `Bearer ${token}`,
},
});
res.json(data);

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
我最近也需要解決這個(gè)問題,在學(xué)習(xí)了很多教程之后,這些教程經(jīng)常給出應(yīng)用程序商店連接 api 的錯(cuò)誤答案。我找到了一種讓它發(fā)揮作用的方法。我在 Java 中就是這樣做的。
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.interfaces.ECPrivateKey;
import java.security.KeyFactory;
import java.io.FileReader;
import java.util.Base64;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
// The code is like this so try it in whatever method you want,
// break it up into pieces so it's a bit more readable
// These variables are the minimum you should need
String keyFile = "/path/to/app_store_AuthKey_XXXX.p8";
// The XXXX is the same XXXX from the keyFile filename itself
String keyId = "XXXX";
String issuerId = "1234-1234-1234-1234-1234";
FileReader kfReader = new FileReader(keyFile);
PEMParser pemParser = new PEMParser(kfReader);
PrivateKeyInfo info = (PrivateKeyInfo) pemParser.readObject();
byte[] pkData = info.getEncoded();
// Convert the PrivateKeyInfo object to a PKCS8EncodedKeySpec object
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkData);
KeyFactory keyFactory = KeyFactory.getInstance("EC");
ECPrivateKey privateKey = (ECPrivateKey) keyFactory.generatePrivate(keySpec);
Algorithm algorithm = Algorithm.ECDSA256(null, privateKey);
Instant expiration = Instant.now().plus(TIMEOUT_MINUTES, ChronoUnit.MINUTES);
return JWT.create()
.withKeyId(keyId)
.withIssuer(issuerId)
.withExpiresAt(expiration)
.withAudience("appstoreconnect-v1")
.sign(algorithm);

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊
我試圖解決我自己的問題,即使用 JWT 連接到 Apple Music API,我在您的有效負(fù)載中注意到了兩件事。首先,您將 1200 添加到 IAT 中,修復(fù)了我的問題,所以謝謝您。第二個(gè)是函數(shù)現(xiàn)在返回一個(gè)浮點(diǎn)數(shù)。我認(rèn)為 API 需要一個(gè) int。我會(huì)嘗試"iat": parseInt(now)
或者now = Math.floor(new Date().getTime() / 1000)

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊
根據(jù)jsonwebtoken使用說明。options
您可以直接在空負(fù)載上使用,如下所示:
let signOptions = {
? ? issuer: issuerId,
? ? keyid: apiKeyId,
? ? expiresIn: '20m',
? ? audience: 'appstoreconnect-v1',
? ? algorithm: 'ES256'
};
let token = jwt.sign({}, privateKey, signOptions);
添加回答
舉報(bào)