我在对接apple pay的时候一直401,实在不知道问题,求各位大神指点一下,不知道是我代码的问题,还是这几个参数问题,或者是缺少了配置,下面是我的代码
public Object getIosOrderId(String transactionId) {
try {
String keyId = "keyId";
String issuerId = "issuerId";
String bundleId = "bundleId";
String url = "https://api.storekit-sandbox.itunes.apple.com/inApps/v2/transactions/" + transactionId;
String path = "AuthKey.p8";
String authKey = FileUtils.readFile(path);
String token = "Bearer " + new BearerTokenAuthenticator(authKey, keyId, issuerId, bundleId).generateToken();
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[]{IosVerifyUtils.myX509TrustManager},new java.security.SecureRandom());
URL console = new URL(url);
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
conn.setSSLSocketFactory(sc.getSocketFactory());
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
conn.setRequestMethod("GET");
conn.setRequestProperty("content-type", "text/json");
conn.setRequestProperty("Proxy-Connection", "Keep-Alive");
conn.setRequestProperty("Authorization", token);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setConnectTimeout(3000);
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = "";
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line);
}
JSONObject jsonObject = JSONObject.parseObject(sb.toString());
log.info("ios支付回值:" + jsonObject);
String jwsTransactionBase64 = jsonObject.getString("signedTransactionInfo").split("\.")[1];
String jwsTransactionBase = new String(Base64.getDecoder().decode(jwsTransactionBase64));
return jwsTransactionBase;
} catch (Exception e) {
log.error("{}",e);
}
return null;
}