From 3714621173c606c4c58439ed8941100ce9ddea14 Mon Sep 17 00:00:00 2001
From: Codex Assistant <codex@example.com>
Date: 星期三, 05 十一月 2025 15:10:49 +0800
Subject: [PATCH] bug
---
backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java b/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java
index c050054..c59c7b8 100644
--- a/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java
+++ b/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerService.java
@@ -19,6 +19,7 @@
import com.rongyichuang.media.service.MediaV2Service;
import com.rongyichuang.media.dto.MediaSaveInput;
import com.rongyichuang.message.service.MessageService;
+import com.rongyichuang.auth.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -61,6 +62,9 @@
@Autowired
private MessageService messageService;
+
+ @Autowired
+ private JwtUtil jwtUtil;
public ActivityPlayer getMyActivityPlayer(Long activityId) {
@@ -240,6 +244,18 @@
String phone = input.getPlayerInfo().getPhone();
String name = input.getPlayerInfo().getName();
+ // 鑾峰彇褰撳墠鐢ㄦ埛鐨剋xopenid锛堜粠JWT token涓級
+ String currentWxOpenid = null;
+ try {
+ String token = userContextUtil.getTokenFromRequest();
+ if (token != null && jwtUtil.validateToken(token)) {
+ currentWxOpenid = jwtUtil.getWxOpenidFromToken(token);
+ log.debug("浠嶫WT token涓幏鍙栧埌wxopenid: {}", currentWxOpenid);
+ }
+ } catch (Exception e) {
+ log.warn("鑾峰彇褰撳墠鐢ㄦ埛wxopenid鏃跺彂鐢熷紓甯�: {}", e.getMessage());
+ }
+
// 鍏堟煡鎵剧幇鏈夌敤鎴�
Optional<User> existingUserOpt = userService.findByPhone(phone);
@@ -251,6 +267,18 @@
// 鏇存柊鐢ㄦ埛鐨勭敓鏃ヤ俊鎭�
if (input.getPlayerInfo().getBirthDate() != null) {
user.setBirthday(input.getPlayerInfo().getBirthDate());
+ }
+
+ // 鏇存柊wxopenid锛堝鏋滃綋鍓峵oken涓寘鍚笖涓嶄负绌猴級
+ if (currentWxOpenid != null && !currentWxOpenid.trim().isEmpty()) {
+ // 妫�鏌ヨ繖涓猳penid鏄惁宸茬粡琚叾浠栫敤鎴蜂娇鐢�
+ Optional<User> existingUserWithOpenid = userService.findByWxOpenid(currentWxOpenid);
+ if (existingUserWithOpenid.isEmpty() || existingUserWithOpenid.get().getId().equals(user.getId())) {
+ user.setWxOpenid(currentWxOpenid);
+ log.info("鏇存柊鐢ㄦ埛wxopenid: {}", currentWxOpenid);
+ } else {
+ log.warn("wxopenid {} 宸茶鍏朵粬鐢ㄦ埛浣跨敤锛岀敤鎴稩D: {}", currentWxOpenid, existingUserWithOpenid.get().getId());
+ }
}
user = userService.save(user);
@@ -270,6 +298,18 @@
newUser.setBirthday(input.getPlayerInfo().getBirthDate());
}
+ // 璁剧疆wxopenid锛堝鏋滃綋鍓峵oken涓寘鍚笖涓嶄负绌猴級
+ if (currentWxOpenid != null && !currentWxOpenid.trim().isEmpty()) {
+ // 妫�鏌ヨ繖涓猳penid鏄惁宸茬粡琚叾浠栫敤鎴蜂娇鐢�
+ Optional<User> existingUserWithOpenid = userService.findByWxOpenid(currentWxOpenid);
+ if (existingUserWithOpenid.isEmpty()) {
+ newUser.setWxOpenid(currentWxOpenid);
+ log.info("涓烘柊鐢ㄦ埛璁剧疆wxopenid: {}", currentWxOpenid);
+ } else {
+ log.warn("wxopenid {} 宸茶鍏朵粬鐢ㄦ埛浣跨敤锛岀敤鎴稩D: {}", currentWxOpenid, existingUserWithOpenid.get().getId());
+ }
+ }
+
newUser = userService.save(newUser);
log.info("涓哄皬绋嬪簭鎶ュ悕鎴愬姛鍒涘缓鏂扮敤鎴凤紝鐢ㄦ埛ID: {}", newUser.getId());
return newUser;
--
Gitblit v1.8.0