This commit is contained in:
2024-11-11 17:31:55 +08:00
parent 74e6d5a1da
commit e5e514b522
8 changed files with 92 additions and 92 deletions

View File

@@ -51,7 +51,7 @@ public class MyTaskScheduler {
// 定时任务,每十五天执行一次 // 定时任务,每十五天执行一次
// @Scheduled(cron = "0 0 0 ? * MON") // @Scheduled(cron = "0 0 0 ? * MON")
// @Scheduled(cron = "0 0 0 */15 * ?") @Scheduled(cron = "0 0 0 */15 * ?")
public void checkExpiry() { public void checkExpiry() {
// 检测正式用户是否快要过期 // 检测正式用户是否快要过期
QueryWrapper<Account> qw = new QueryWrapper<>(); QueryWrapper<Account> qw = new QueryWrapper<>();
@@ -85,7 +85,7 @@ public class MyTaskScheduler {
} }
} }
} }
// @Scheduled(cron = "0 0 9 * * ?") @Scheduled(cron = "0 0 9 * * ?")
public void sendTrialOrderExcelToManagements() { public void sendTrialOrderExcelToManagements() {
// 获取前一天日期 // 获取前一天日期
LocalDate yesterday = LocalDate.now().minusDays(1); LocalDate yesterday = LocalDate.now().minusDays(1);

View File

@@ -19,21 +19,21 @@ public class AccountTask {
/** /**
* 每周日晚上刷新 年付用户、月付用户的积分 * 每周日晚上刷新 年付用户、月付用户的积分
*/ */
// @Scheduled(cron = "59 59 23 ? * SUN") @Scheduled(cron = "59 59 23 ? * SUN")
// @Scheduled(cron = "59 59 23 * * ?") // @Scheduled(cron = "59 59 23 * * ?")
public void refreshCreditsMonthly() { public void refreshCreditsMonthly() {
log.info("每周日晚115959刷新付费用户积分为 6000"); log.info("每周日晚115959刷新付费用户积分为 6000");
accountService.refreshCreditsWeekly(); accountService.refreshCreditsWeekly();
} }
// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
public void getPaidUser() { public void getPaidUser() {
// 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单 // 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单
accountService.extendValidityForCC(); accountService.extendValidityForCC();
} }
// 每天凌晨0点执行一次 // 每天凌晨0点执行一次
// @Scheduled(cron = "0 0 0 * * ?") @Scheduled(cron = "0 0 0 * * ?")
public void cancelActivityBenefits() { public void cancelActivityBenefits() {
// 1、查询当前所有参与了活动且过期的用户 // 1、查询当前所有参与了活动且过期的用户
List<Account> accountList = accountService.getExpiredUserBySystemUser(4); List<Account> accountList = accountService.getExpiredUserBySystemUser(4);
@@ -46,7 +46,7 @@ public class AccountTask {
} }
// 每天检测正式用户到期情况每天凌晨0点执行 // 每天检测正式用户到期情况每天凌晨0点执行
// @Scheduled(cron = "0 0 0 * * ?") @Scheduled(cron = "0 0 0 * * ?")
public void paidUserToVisitor() { public void paidUserToVisitor() {
// 1、查询当前已过期正式用户或试用用户 // 1、查询当前已过期正式用户或试用用户
List<Account> accountList = accountService.getExpiredUserBySystemUser(1); List<Account> accountList = accountService.getExpiredUserBySystemUser(1);
@@ -63,7 +63,7 @@ public class AccountTask {
/** /**
* 将Code-Create上注册的用户添加为AiDA的游客 * 将Code-Create上注册的用户添加为AiDA的游客
*/ */
// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
public void registerUserToVisitor() { public void registerUserToVisitor() {
accountService.registerUserToVisitor(); accountService.registerUserToVisitor();
} }

View File

@@ -23,7 +23,7 @@ public class PaypalTask {
@Resource @Resource
private PayPalCheckoutService payPalCheckoutService; private PayPalCheckoutService payPalCheckoutService;
// @Scheduled(cron = "0/30 * * * * ?") @Scheduled(cron = "0/30 * * * * ?")
public void orderConfirm() throws SerializeException { public void orderConfirm() throws SerializeException {
// log.info("PayPal orderConfirm 被执行......"); // log.info("PayPal orderConfirm 被执行......");

View File

@@ -22,7 +22,7 @@ public class StripeTask {
@Resource @Resource
private StripeService stripeService; private StripeService stripeService;
// @Scheduled(cron = "0/30 * * * * ?") @Scheduled(cron = "0/30 * * * * ?")
public void orderConfirm() throws SerializeException { public void orderConfirm() throws SerializeException {
// 查看超过30分钟以上仍未支付的订单 置为超时订单 // 查看超过30分钟以上仍未支付的订单 置为超时订单

View File

@@ -116,9 +116,9 @@ public class ThirdPartyController {
return Response.success(accountService.updateNoLoginRequiredNew(noLoginRequiredDTO, request)); return Response.success(accountService.updateNoLoginRequiredNew(noLoginRequiredDTO, request));
} }
@CrossOrigin // @CrossOrigin
@GetMapping("/auth/google_callback") // @GetMapping("/auth/google_callback")
public Response<String> googleCallback(@RequestParam("code") String code, HttpSession session) { // public Response<String> googleCallback(@RequestParam("code") String code, HttpSession session) {
return Response.success(accountService.googleCallback(code, session)); // return Response.success(accountService.googleCallback(code, session));
} // }
} }

View File

@@ -183,7 +183,7 @@ public interface AccountService extends IService<Account> {
void halfPricePromotion(); void halfPricePromotion();
String googleCallback(String code, HttpSession session); // String googleCallback(String code, HttpSession session);
List<String> getPaidCustomerEmail(); List<String> getPaidCustomerEmail();
} }

View File

@@ -1854,82 +1854,82 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
log.info("邮箱绑定更改完成用户id:{},新邮箱:{}", accountId, newMailbox); log.info("邮箱绑定更改完成用户id:{},新邮箱:{}", accountId, newMailbox);
} }
@Override // @Override
public String googleCallback(String code, HttpSession session) { // public String googleCallback(String code, HttpSession session) {
try { // try {
log.info("code:" + code); // log.info("code:" + code);
// 使用 code 获取 Google 用户信息 // // 使用 code 获取 Google 用户信息
GoogleUser googleUser = getGoogleUserFromCode(code); // GoogleUser googleUser = getGoogleUserFromCode(code);
log.info("googleUser:" + JSON.toJSONString(googleUser)); // log.info("googleUser:" + JSON.toJSONString(googleUser));
//
// 检查数据库中是否已有该用户 // // 检查数据库中是否已有该用户
// QueryWrapper<AccountExtend> qw = new QueryWrapper<>(); //// QueryWrapper<AccountExtend> qw = new QueryWrapper<>();
// qw.lambda().eq(AccountExtend::getAuth, googleUser.getId()); //// qw.lambda().eq(AccountExtend::getAuth, googleUser.getId());
// List<AccountExtend> accountExtends = accountExtendMapper.selectList(qw); //// List<AccountExtend> accountExtends = accountExtendMapper.selectList(qw);
// Account existingUser = findUserByGoogleId(googleUser.getId()); //// Account existingUser = findUserByGoogleId(googleUser.getId());
return "Login successful"; // return "Login successful";
// if (CollectionUtil.isNotEmpty(accountExtends)) { //// if (CollectionUtil.isNotEmpty(accountExtends)) {
// // 用户已存在,直接登录 //// // 用户已存在,直接登录
//// session.setAttribute("user", existingUser); ////// session.setAttribute("user", existingUser);
// return "Login successful"; //// return "Login successful";
// } else { //// } else {
// // 用户不存在,创建新用户(自动注册) //// // 用户不存在,创建新用户(自动注册)
//// User newUser = googleAuthService.registerNewUser(googleUser); ////// User newUser = googleAuthService.registerNewUser(googleUser);
//// session.setAttribute("user", newUser); ////// session.setAttribute("user", newUser);
// return "Registration and login successful"; //// return "Registration and login successful";
// } //// }
} catch (Exception e) { // } catch (Exception e) {
return "Error processing Google login: " + e.getMessage(); // return "Error processing Google login: " + e.getMessage();
} // }
}
private static final String TOKEN_URL = "https://oauth2.googleapis.com/token";
private static final String USER_INFO_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
private static final String CLIENT_ID = "194770296147-njd68pm7tnapgonkj2h48mhf63n15n3f.apps.googleusercontent.com";
private static final String CLIENT_SECRET = "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";
private static final String REDIRECT_URI = "https://develop.api.aida.com.hk/api/third/party/auth/google_callback";
public GoogleUser getGoogleUserFromCode(String code) {
// Step 1: Exchange code for access_token
String accessToken = getAccessToken(code);
log.info("accessToken" + accessToken);
// Step 2: Use access_token to get Google User info
return getGoogleUserInfo(accessToken);
}
private String getAccessToken(String code) {
RestTemplate restTemplate = new RestTemplate();
Map<String, String> params = new HashMap<>();
params.put("client_id", CLIENT_ID);
params.put("client_secret", CLIENT_SECRET);
params.put("redirect_uri", REDIRECT_URI);
params.put("grant_type", "authorization_code");
params.put("code", code);
// 使用 RestTemplate 发起请求以获取 access_token
GoogleTokenResponse response = restTemplate.postForObject(TOKEN_URL, params, GoogleTokenResponse.class);
return response.getAccessToken();
}
private GoogleUser getGoogleUserInfo(String accessToken) {
RestTemplate restTemplate = new RestTemplate();
String url = USER_INFO_URL + "?access_token=" + accessToken;
return restTemplate.getForObject(url, GoogleUser.class);
}
// public User findUserByGoogleId(String googleId) {
// // 从数据库中根据 Google ID 查找用户
// return userRepository.findByGoogleId(googleId);
// } // }
//
// public User registerNewUser(GoogleUser googleUser) { // private static final String TOKEN_URL = "https://oauth2.googleapis.com/token";
// // 创建并保存新用户 // private static final String USER_INFO_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
// User newUser = new User(); // private static final String CLIENT_ID = "194770296147-njd68pm7tnapgonkj2h48mhf63n15n3f.apps.googleusercontent.com";
// newUser.setGoogleId(googleUser.getId()); // private static final String CLIENT_SECRET = "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";
// newUser.setEmail(googleUser.getEmail()); // private static final String REDIRECT_URI = "https://develop.api.aida.com.hk/api/third/party/auth/google_callback";
// newUser.setUsername(googleUser.getName()); //
// return userRepository.save(newUser); // public GoogleUser getGoogleUserFromCode(String code) {
// // Step 1: Exchange code for access_token
// String accessToken = getAccessToken(code);
// log.info("accessToken" + accessToken);
//
// // Step 2: Use access_token to get Google User info
// return getGoogleUserInfo(accessToken);
// } // }
//
// private String getAccessToken(String code) {
// RestTemplate restTemplate = new RestTemplate();
// Map<String, String> params = new HashMap<>();
// params.put("client_id", CLIENT_ID);
// params.put("client_secret", CLIENT_SECRET);
// params.put("redirect_uri", REDIRECT_URI);
// params.put("grant_type", "authorization_code");
// params.put("code", code);
//
// // 使用 RestTemplate 发起请求以获取 access_token
// GoogleTokenResponse response = restTemplate.postForObject(TOKEN_URL, params, GoogleTokenResponse.class);
// return response.getAccessToken();
// }
//
// private GoogleUser getGoogleUserInfo(String accessToken) {
// RestTemplate restTemplate = new RestTemplate();
// String url = USER_INFO_URL + "?access_token=" + accessToken;
// return restTemplate.getForObject(url, GoogleUser.class);
// }
//
//// public User findUserByGoogleId(String googleId) {
//// // 从数据库中根据 Google ID 查找用户
//// return userRepository.findByGoogleId(googleId);
//// }
//
//// public User registerNewUser(GoogleUser googleUser) {
//// // 创建并保存新用户
//// User newUser = new User();
//// newUser.setGoogleId(googleUser.getId());
//// newUser.setEmail(googleUser.getEmail());
//// newUser.setUsername(googleUser.getName());
//// return userRepository.save(newUser);
//// }
} }

View File

@@ -2,7 +2,7 @@
#spring.profiles.active=test #spring.profiles.active=test
#<23><><EFBFBD><EFBFBD>application-prod<6F>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) #<23><><EFBFBD><EFBFBD>application-prod<6F>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
#spring.profiles.active=prod spring.profiles.active=prod
#<23><><EFBFBD><EFBFBD>application-dev<65>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) #<23><><EFBFBD><EFBFBD>application-dev<65>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
spring.profiles.active=dev #spring.profiles.active=dev