servers, Account account) {
StringBuilder sb = new StringBuilder();
+ Base64.Encoder encoder = Base64.getEncoder();
+ // tip
+ if (new Date().getTime()>account.getToDate().getTime()){
+ V2rayAccount alertMessage = new V2rayAccount();
+ alertMessage.setPs("通知-账号已经过期,请联系管理员:"+Utils.toDateStr(account.getToDate(),null));
+ sb.append("vmess://").append(encoder.encodeToString(JSON.toJSONString(alertMessage).getBytes(StandardCharsets.UTF_8))).append("\n");
+ return sb.toString();
+ }
+
+
for (V2rayAccount v2rayAccount : buildV2rayAccount(servers, account)) {
- String encode = Base64.getEncoder().encodeToString(JSON.toJSONString(v2rayAccount).getBytes(StandardCharsets.UTF_8));
+ String encode = encoder.encodeToString(JSON.toJSONString(v2rayAccount).getBytes(StandardCharsets.UTF_8));
sb.append("vmess://").append(encode).append("\n");
}
+ // tip 流量 和 有效期
+ V2rayAccount tip = new V2rayAccount();
+ tip.setAdd("127.0.0.2");
+ Stat stat = statService.createOrGetStat(account);
+ tip.setPs("通知-流量:"+stat.getFlow()/1024/1024/1024+"/"+account.getBandwidth()+"G;流量重置时间:"+Utils.toDateStr(stat.getToDate(),"yyyy-MM-dd HH时"));
+ V2rayAccount tip2 = new V2rayAccount();
+ tip2.setPs("通知-账号有效期至:"+ Utils.toDateStr(account.getToDate(),null));
+ tip2.setAdd("127.0.0.3");
+ sb.append("vmess://").append(encoder.encodeToString(JSON.toJSONString(tip).getBytes(StandardCharsets.UTF_8))).append("\n");
+ sb.append("vmess://").append(encoder.encodeToString(JSON.toJSONString(tip2).getBytes(StandardCharsets.UTF_8))).append("\n");
+
return sb.toString();
}
diff --git a/vpn-admin/src/main/java/com/jhl/admin/util/Utils.java b/vpn-admin/src/main/java/com/jhl/admin/util/Utils.java
index 0c998886..8e08e8e5 100644
--- a/vpn-admin/src/main/java/com/jhl/admin/util/Utils.java
+++ b/vpn-admin/src/main/java/com/jhl/admin/util/Utils.java
@@ -3,6 +3,8 @@
import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
import com.jhl.admin.constant.KVConstant;
+import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -79,6 +81,19 @@ public static Date formatDate(Date date, SimpleDateFormat simpleDateFormat) {
}
+ public static String toDateStr(Date date ,String pattern){
+ if (StringUtils.isEmpty(pattern)){
+ pattern=KVConstant.YYYYMMddHHmm;
+ }
+ Assert.notNull(date,"The date must not be null");
+ try {
+ SimpleDateFormat thisSDF = new SimpleDateFormat(pattern);
+ return thisSDF.format(date);
+ }catch (Exception e){
+ throw new RuntimeException("转换错误", e);
+ }
+ }
+
public static void main(String[] args) {
System.out.println(formatDate(new Date(), null));
}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy