8 changed files with 189 additions and 1 deletions
-
58src/main/java/com/example/demo/Util/AppleTokenGenerator.java
-
6src/main/java/com/example/demo/Util/AuthKey_3J2S9VXU3V.p8
-
11src/main/java/com/example/demo/controller/cash/CashCollectionController.java
-
28src/main/java/com/example/demo/domain/DTO/PerformanceAdjustmentDTO.java
-
2src/main/java/com/example/demo/mapper/cash/CashCollectionMapper.java
-
3src/main/java/com/example/demo/service/cash/CashCollectionService.java
-
70src/main/java/com/example/demo/serviceImpl/cash/CashCollectionServiceImpl.java
-
12src/main/resources/cashMapper/CashCollectionMapper.xml
@ -0,0 +1,58 @@ |
|||
package com.example.demo.Util; |
|||
|
|||
import io.jsonwebtoken.Jwts; |
|||
import io.jsonwebtoken.SignatureAlgorithm; |
|||
import io.jsonwebtoken.io.Decoders; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Paths; |
|||
import java.security.KeyFactory; |
|||
import java.security.PrivateKey; |
|||
import java.security.spec.PKCS8EncodedKeySpec; |
|||
import java.util.Date; |
|||
|
|||
public class AppleTokenGenerator { |
|||
|
|||
// 你提供的真实信息(已全部填好) |
|||
private static final String KEY_ID = "3J2S9VXU3V"; |
|||
private static final String ISSUER_ID = "69a6de7e-1f9a-47e3-e053-5b8c7c11a4d1"; |
|||
private static final String P8_FILE_PATH = "E:/Work/newgold/gold-java/src/main/java/com/example/demo/Util/AuthKey_3J2S9VXU3V.p8"; |
|||
|
|||
public static String generateToken() { |
|||
try { |
|||
// 读取 P8 私钥内容 |
|||
String p8Content = Files.readString(Paths.get(P8_FILE_PATH)) |
|||
.replace("-----BEGIN PRIVATE KEY-----", "") |
|||
.replace("-----END PRIVATE KEY-----", "") |
|||
.replaceAll("\\s+", ""); |
|||
|
|||
// 解码私钥 |
|||
byte[] keyBytes = Decoders.BASE64.decode(p8Content); |
|||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); |
|||
KeyFactory keyFactory = KeyFactory.getInstance("EC"); |
|||
PrivateKey privateKey = keyFactory.generatePrivate(spec); |
|||
|
|||
// 生成苹果官方标准 JWT(补全typ字段,完全符合文档要求) |
|||
return Jwts.builder() |
|||
.setHeaderParam("alg", "ES256") |
|||
.setHeaderParam("kid", KEY_ID) |
|||
.setHeaderParam("typ", "JWT") // 🔴 苹果官方强制要求,之前漏了! |
|||
.setIssuer(ISSUER_ID) |
|||
.setAudience("appstoreconnect-v1") |
|||
.setIssuedAt(new Date()) |
|||
.setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 15)) // 15分钟有效期(≤20分钟) |
|||
.signWith(privateKey, SignatureAlgorithm.ES256) |
|||
.compact(); |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
// 运行直接输出可用 Token |
|||
public static void main(String[] args) { |
|||
String token = generateToken(); |
|||
System.out.println("复制下面这一行直接用:"); |
|||
System.out.println("Bearer " + token); |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
-----BEGIN PRIVATE KEY----- |
|||
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQge12P08wGtrp8dttS |
|||
6fA0dtL46GYnBYEumTnx3/g53qGgCgYIKoZIzj0DAQehRANCAATiWWs9qLs7eYCv |
|||
ZIfG0JYRrLjLqotAGdEtfTii1gh+IKK4snS499kwk+vKg1vHy2ZovyZDdvmW/z+i |
|||
WSzRu18f |
|||
-----END PRIVATE KEY----- |
|||
@ -0,0 +1,28 @@ |
|||
package com.example.demo.domain.DTO; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* @program: gold-java |
|||
* @ClassName PerformanceAdjustmentDTO |
|||
* @description: |
|||
* @author: Double |
|||
* @create: 2026−04-03 09:56 |
|||
* @Version 1.0 |
|||
**/ |
|||
|
|||
|
|||
|
|||
@Data |
|||
public class PerformanceAdjustmentDTO { |
|||
private Integer submitterId; // 提交人ID |
|||
private String submitterMarket; // 提交人市场 |
|||
private int[][] matrix = new int[6][6]; |
|||
private Double weight; // 权重 |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date Time; // 时间 |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue