fix(apple-login): 修复JWT解析与Base64URL解码错误
This commit is contained in:
@@ -1,23 +1,21 @@
|
||||
package com.yolo.keyborad.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.yolo.keyborad.common.BaseResponse;
|
||||
import com.yolo.keyborad.common.ErrorCode;
|
||||
import com.yolo.keyborad.common.ResultUtils;
|
||||
|
||||
import com.yolo.keyborad.exception.BusinessException;
|
||||
import com.yolo.keyborad.model.dto.IosPayVerifyReq;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
|
||||
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
|
||||
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.openai.OpenAiChatOptions;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.boot.context.properties.bind.DefaultValue;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/*
|
||||
@@ -31,24 +29,8 @@ import reactor.core.publisher.Flux;
|
||||
@Tag(name = "测试控制器", description = "测试控制器")
|
||||
public class DemoController {
|
||||
|
||||
private final ChatClient openAiChatClient;
|
||||
|
||||
private final ChatModel chatModel;
|
||||
|
||||
public DemoController(@Qualifier("openAiChatModel") ChatModel chatModel) {
|
||||
|
||||
this.chatModel = chatModel;
|
||||
|
||||
// 构造时,可以设置 ChatClient 的参数
|
||||
// {@link org.springframework.ai.chat.client.ChatClient};
|
||||
this.openAiChatClient = ChatClient.builder(chatModel)
|
||||
.defaultOptions(OpenAiChatOptions.builder()
|
||||
.build())
|
||||
// 实现 Chat Memory 的 Advisor
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@Resource
|
||||
private ChatClient client;
|
||||
|
||||
@GetMapping("/test")
|
||||
@Operation(summary = "测试接口", description = "测试接口")
|
||||
@@ -60,11 +42,20 @@ public class DemoController {
|
||||
|
||||
@GetMapping("/talk")
|
||||
@Operation(summary = "测试聊天接口", description = "测试接口")
|
||||
public Flux<String> testTalk(String userInput){
|
||||
return openAiChatClient
|
||||
@Parameter(name = "userInput",required = true,description = "测试聊天接口",example = "talk to something")
|
||||
public Flux<String> testTalk(@DefaultValue("you are so cute!") String userInput){
|
||||
return client
|
||||
.prompt("You're a 25-year-old guy—witty and laid-back, always replying in English.\n" +
|
||||
"Read the user's last message, then write three short and funny replies that sound like something a guy would say. Go easy on the emojis.\n" +
|
||||
"Keep each under 20 words. Use '/t' to separate them—no numbers or extra labels.").user("you are so cute!")
|
||||
.stream().content();
|
||||
"Keep each under 20 words. Use '/t' to separate them—no numbers or extra labels.")
|
||||
.user(userInput)
|
||||
.stream()
|
||||
.content();
|
||||
}
|
||||
|
||||
@Operation(summary = "IOS内购凭证校验", description = "IOS内购凭证校验")
|
||||
public BaseResponse<String> iosPay(@RequestBody IosPayVerifyReq req) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package com.yolo.keyborad.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yolo.keyborad.common.BaseResponse;
|
||||
import com.yolo.keyborad.common.ResultUtils;
|
||||
import com.yolo.keyborad.model.dto.AppleLoginReq;
|
||||
import com.yolo.keyborad.service.impl.IAppleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -30,11 +36,13 @@ public class UserController {
|
||||
/**
|
||||
* 苹果登录
|
||||
*
|
||||
* @param code JWT
|
||||
* @param appleLoginReq identityToken
|
||||
*/
|
||||
@PostMapping("/appleLogin")
|
||||
public String appleLogin(String code) throws Exception {
|
||||
String subjectId = appleService.login(code);
|
||||
return JSON.toJSONString(subjectId);
|
||||
@Operation(summary = "苹果登录", description = "苹果登录接口")
|
||||
@Parameter(name = "code",required = true,description = "苹果登录凭证",example = "123456")
|
||||
public BaseResponse<String> appleLogin(@RequestBody AppleLoginReq appleLoginReq) throws Exception {
|
||||
String subjectId = appleService.login(appleLoginReq.getIdentityToken());
|
||||
return ResultUtils.success(subjectId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user