Compare commits
1 Commits
v3.0.6-nat
...
v3.0.7-nat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cb7828acf |
@@ -4,6 +4,12 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @descriptions
|
||||
* @author bamanker
|
||||
* @date 2026/1/8 12:12
|
||||
* @return
|
||||
*/
|
||||
@Component
|
||||
public class DailyLoveConfigure {
|
||||
// public static String Access_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";
|
||||
@@ -26,6 +32,7 @@ public class DailyLoveConfigure {
|
||||
public static String Color_bbir;
|
||||
public static String Color_cbir;
|
||||
public static String Color_loveDay;
|
||||
public static String Color_weddingDay;
|
||||
public static String Color_remark;
|
||||
|
||||
@Value("${wechat.color.tomorrow:null}")
|
||||
@@ -113,6 +120,11 @@ public class DailyLoveConfigure {
|
||||
Color_loveDay = color_loveDay;
|
||||
}
|
||||
|
||||
@Value("${wechat.color.weddingDay:null}")
|
||||
public void setColor_weddingDay(String color_weddingDay) {
|
||||
Color_loveDay = color_weddingDay;
|
||||
}
|
||||
|
||||
@Value("${wechat.color.remark:null}")
|
||||
public void setColor_remark(String color_remark) {
|
||||
Color_remark = color_remark;
|
||||
@@ -182,28 +194,35 @@ public class DailyLoveConfigure {
|
||||
public static String Boy_Birthday;
|
||||
|
||||
@Value("${DL.boy-birthday}")
|
||||
public void setBoyBirthday(String BoyBirthday) {
|
||||
Boy_Birthday = BoyBirthday;
|
||||
public void setBoyBirthday(String boyBirthday) {
|
||||
Boy_Birthday = boyBirthday;
|
||||
}
|
||||
|
||||
public static String Girl_Birthday;
|
||||
|
||||
@Value("${DL.girl-birthday}")
|
||||
public void setGirlBirthday(String GirlBirthday) {
|
||||
Girl_Birthday = GirlBirthday;
|
||||
public void setGirlBirthday(String girlBirthday) {
|
||||
Girl_Birthday = girlBirthday;
|
||||
}
|
||||
|
||||
public static String Cat_Birthday;
|
||||
|
||||
@Value("${DL.cat-birthday}")
|
||||
public void setCatBirthday(String CatBirthday) {
|
||||
Cat_Birthday = CatBirthday;
|
||||
public void setCatBirthday(String catBirthday) {
|
||||
Cat_Birthday = catBirthday;
|
||||
}
|
||||
|
||||
public static String Love_Day;
|
||||
|
||||
@Value("${DL.love-day}")
|
||||
public void setLoveDay(String LoveDay) {
|
||||
Love_Day = LoveDay;
|
||||
public void setLoveDay(String loveDay) {
|
||||
Love_Day = loveDay;
|
||||
}
|
||||
|
||||
public static String Wedding_Day;
|
||||
|
||||
@Value("${DL.wedding-day}")
|
||||
public void setWeddingDay(String weddingDay) {
|
||||
Wedding_Day = weddingDay;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,12 @@ import tools.jackson.databind.ObjectMapper;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author bamanker
|
||||
* @descriptions
|
||||
* @date 2026/1/8 12:04
|
||||
* @return
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class PushDailyController {
|
||||
@@ -25,7 +31,6 @@ public class PushDailyController {
|
||||
final
|
||||
ObjectMapper mapper;
|
||||
|
||||
|
||||
final
|
||||
DataRemoteClient dataRemoteClient;
|
||||
|
||||
@@ -58,8 +63,6 @@ public class PushDailyController {
|
||||
String weatherResp = dataRemoteClient.getWeather(param1);
|
||||
JsonNode weatherJson = mapper.readTree(weatherResp).get("result").get("list").get(1);
|
||||
String city = mapper.readTree(weatherResp).get("result").get("area").asString();
|
||||
// JSONObject weatherJson1 = JSONObject.parseObject(weatherResp).getJSONArray("result").getJSONObject(0).getJSONArray("list").getJSONObject(1);
|
||||
// String city1 = JSONObject.parseObject(weatherResp).getJSONArray("result").getJSONObject(0).getString("area");
|
||||
Weather weather = mapper.treeToValue(weatherJson, Weather.class);
|
||||
|
||||
resultVo.setAttribute("tomorrow", new DataItem(weather.getDate() + " " + weather.getWeek(), DailyLoveConfigure.Color_tomorrow));
|
||||
@@ -75,17 +78,14 @@ public class PushDailyController {
|
||||
|
||||
String tipsResp = dataRemoteClient.getTips(param2);
|
||||
String tips = mapper.readTree(tipsResp).get("result").get("content").asString();
|
||||
// String tips1 = JSONObject.parseObject(tipsResp).getJSONArray("result").getJSONObject(0).getString("content");
|
||||
resultVo.setAttribute("tips", new DataItem(tips, DailyLoveConfigure.Color_tips));
|
||||
|
||||
String nightResp = dataRemoteClient.getNight(param2);
|
||||
String night = mapper.readTree(nightResp).get("result").get("content").asString();
|
||||
// String night1 = JSONObject.parseObject(nightResp).getJSONArray("result").getJSONObject(0).getString("content");
|
||||
resultVo.setAttribute("night", new DataItem(night, DailyLoveConfigure.Color_night));
|
||||
|
||||
String rainbowResp = dataRemoteClient.getRainbow(param2);
|
||||
String rainbow = mapper.readTree(rainbowResp).get("result").get("content").asString();
|
||||
// String rainbow1 = JSONObject.parseObject(rainbowResp).getJSONArray("result").getJSONObject(0).getString("content");
|
||||
resultVo.setAttribute("rainbow", new DataItem(rainbow, DailyLoveConfigure.Color_dailyCn));
|
||||
|
||||
// String englishResp = dataRemoteClient.getDailyEnglish(param2);
|
||||
@@ -101,44 +101,50 @@ public class PushDailyController {
|
||||
|
||||
|
||||
int girlBirthdays = DataUtils.getBirthdays(DailyLoveConfigure.Girl_Birthday);
|
||||
log.debug("gbir_day:{}", girlBirthdays);
|
||||
log.info("gbir_days:{}", girlBirthdays);
|
||||
resultVo.setAttribute("gbir_day", new DataItem(girlBirthdays - 1 + "", DailyLoveConfigure.Color_gbir));
|
||||
|
||||
int boyBirthdays = DataUtils.getChineseBirthdays(DailyLoveConfigure.Boy_Birthday);
|
||||
log.debug("bbir_day:{}", boyBirthdays);
|
||||
log.info("bbir_days:{}", boyBirthdays);
|
||||
resultVo.setAttribute("bbir_day", new DataItem(boyBirthdays - 1 + "", DailyLoveConfigure.Color_bbir));
|
||||
|
||||
int catBirthdays = DataUtils.getBirthdays(DailyLoveConfigure.Cat_Birthday);
|
||||
log.debug("cbir_day:{}", catBirthdays);
|
||||
log.info("cbir_days:{}", catBirthdays);
|
||||
resultVo.setAttribute("cbir_day", new DataItem(catBirthdays - 1 + "", DailyLoveConfigure.Color_cbir));
|
||||
|
||||
String words = "普通的一天";
|
||||
|
||||
if (DataUtils.getBirthdays(DailyLoveConfigure.Love_Day) == 1) {
|
||||
words = "明天是恋爱周年纪念日!永远爱你~mua";
|
||||
} else if ((DataUtils.getLoveDays(DailyLoveConfigure.Love_Day)) % 100 == 99) {
|
||||
} else if ((DataUtils.getDayDiff(DailyLoveConfigure.Love_Day)) % 100 == 99) {
|
||||
words = "明天是恋爱百日纪念日!提前庆祝哦~";
|
||||
} else if (DataUtils.getBirthdays(DailyLoveConfigure.Wedding_Day) == 1) {
|
||||
words = "明天是结婚周年纪念日!提前庆祝哦~";
|
||||
} else if (girlBirthdays == 1) {
|
||||
words = "明天是lili大宝贝的生日啦";
|
||||
} else if (boyBirthdays == 1) {
|
||||
words = "明天是ss的生日!别忘了哦~";
|
||||
words = "明天是菘菘的生日!别忘了哦~";
|
||||
} else if (catBirthdays == 1) {
|
||||
words = "明天是小离谱的生日!别忘了小鱼干!";
|
||||
}
|
||||
|
||||
resultVo.setAttribute("words", new DataItem(words, DailyLoveConfigure.Color_remark));
|
||||
|
||||
int loveDays = DataUtils.getLoveDays(DailyLoveConfigure.Love_Day);
|
||||
log.debug("love_day:{}", loveDays);
|
||||
int loveDays = DataUtils.getDayDiff(DailyLoveConfigure.Love_Day);
|
||||
log.info("love_days:{}", loveDays);
|
||||
resultVo.setAttribute("love_day", new DataItem(loveDays + 1 + "", DailyLoveConfigure.Color_loveDay));
|
||||
|
||||
log.debug("resultVo:{}", resultVo);
|
||||
int weddingDays = DataUtils.getDayDiff(DailyLoveConfigure.Wedding_Day);
|
||||
log.info("wedding_days:{}", weddingDays);
|
||||
resultVo.setAttribute("wedding_day", new DataItem(weddingDays + 1 + "", DailyLoveConfigure.Color_weddingDay));
|
||||
|
||||
log.info("resultVo:{}", resultVo);
|
||||
WechatTokenParam wechatTokenParam = new WechatTokenParam();
|
||||
wechatTokenParam.setAppid(DailyLoveConfigure.App_ID);
|
||||
wechatTokenParam.setSecret(DailyLoveConfigure.App_Secret);
|
||||
|
||||
String accessTokenResp = wechatRequestClient.getAccessToken(wechatTokenParam);
|
||||
log.debug("accessTokenJson:{}", accessTokenResp);
|
||||
log.info("accessTokenJson:{}", accessTokenResp);
|
||||
String token = mapper.readTree(accessTokenResp).get("access_token").asString();
|
||||
// String token1 = JSONObject.parseObject(accessTokenResp).getString("access_token");
|
||||
return wechatRequestClient.sendMsg(resultVo, token);
|
||||
@@ -206,37 +212,43 @@ public class PushDailyController {
|
||||
|
||||
|
||||
int girlBirthdays = DataUtils.getBirthdays(DailyLoveConfigure.Girl_Birthday);
|
||||
log.debug("gbir_day:{}", girlBirthdays);
|
||||
log.info("gbir_days:{}", girlBirthdays);
|
||||
resultVo.setAttribute("gbir_day", new DataItem(girlBirthdays + "", DailyLoveConfigure.Color_gbir));
|
||||
|
||||
int boyBirthdays = DataUtils.getChineseBirthdays(DailyLoveConfigure.Boy_Birthday);
|
||||
log.debug("bbir_day:{}", boyBirthdays);
|
||||
log.info("bbir_days:{}", boyBirthdays);
|
||||
resultVo.setAttribute("bbir_day", new DataItem(boyBirthdays + "", DailyLoveConfigure.Color_bbir));
|
||||
|
||||
int catBirthdays = DataUtils.getBirthdays(DailyLoveConfigure.Cat_Birthday);
|
||||
log.debug("cbir_day:{}", catBirthdays);
|
||||
log.info("cbir_days:{}", catBirthdays);
|
||||
resultVo.setAttribute("cbir_day", new DataItem(catBirthdays + "", DailyLoveConfigure.Color_cbir));
|
||||
|
||||
String words = "普通的一天";
|
||||
|
||||
if (DataUtils.getBirthdays(DailyLoveConfigure.Love_Day) == 0) {
|
||||
words = "今天是恋爱周年纪念日!永远爱你~mua";
|
||||
} else if ((DataUtils.getLoveDays(DailyLoveConfigure.Love_Day)) % 100 == 0) {
|
||||
} else if ((DataUtils.getDayDiff(DailyLoveConfigure.Love_Day)) % 100 == 0) {
|
||||
words = "今天是恋爱百日纪念日!永远爱你~";
|
||||
} else if (DataUtils.getBirthdays(DailyLoveConfigure.Wedding_Day) == 0) {
|
||||
words = "今天是结婚周年纪念日!永远爱你~";
|
||||
} else if (girlBirthdays == 0) {
|
||||
words = "今天是lili宝贝的生日!生日快乐哟~";
|
||||
} else if (boyBirthdays == 0) {
|
||||
words = "今天是ss的生日!别忘了好好爱他~";
|
||||
words = "今天是菘菘的生日!别忘了好好爱他~";
|
||||
} else if (catBirthdays == 0) {
|
||||
words = "今天是小离谱的生日!别忘了小鱼干!";
|
||||
}
|
||||
|
||||
resultVo.setAttribute("words", new DataItem(words, DailyLoveConfigure.Color_remark));
|
||||
|
||||
int loveDays = DataUtils.getLoveDays(DailyLoveConfigure.Love_Day);
|
||||
log.debug("love_day:{}", loveDays);
|
||||
int loveDays = DataUtils.getDayDiff(DailyLoveConfigure.Love_Day);
|
||||
log.info("love_days:{}", loveDays);
|
||||
resultVo.setAttribute("love_day", new DataItem(loveDays + "", DailyLoveConfigure.Color_loveDay));
|
||||
|
||||
int weddingDays = DataUtils.getDayDiff(DailyLoveConfigure.Wedding_Day);
|
||||
log.info("wedding_days:{}", weddingDays);
|
||||
resultVo.setAttribute("wedding_day", new DataItem(weddingDays + "", DailyLoveConfigure.Color_weddingDay));
|
||||
|
||||
log.debug("resultVo:{}", resultVo);
|
||||
WechatTokenParam wechatTokenParam = new WechatTokenParam();
|
||||
wechatTokenParam.setAppid(DailyLoveConfigure.App_ID);
|
||||
|
||||
@@ -9,6 +9,9 @@ import org.bouncycastle.util.Strings;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -35,7 +38,7 @@ public class DataUtils {
|
||||
Calendar dateToday = Calendar.getInstance();
|
||||
int todayYear = dateToday.get(Calendar.YEAR);
|
||||
//把生日的年改为今年,方便计算
|
||||
ChineseDate chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay,false);
|
||||
ChineseDate chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false);
|
||||
//农历日期对应的阳历日期
|
||||
int gregorianDay = chineseDate.getGregorianDay();
|
||||
//计算时间差
|
||||
@@ -121,22 +124,36 @@ public class DataUtils {
|
||||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算恋爱天数 days
|
||||
*
|
||||
* @param loveday
|
||||
* @return
|
||||
*/
|
||||
public static int getLoveDays(String loveday) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
int days = 0;
|
||||
try {
|
||||
long time = System.currentTimeMillis() - dateFormat.parse(loveday).getTime();
|
||||
days = (int) (time / (24 * 60 * 60 * 1000));
|
||||
// /**
|
||||
// * 计算恋爱天数 days
|
||||
// *
|
||||
// * @param loveDay
|
||||
// * @return
|
||||
// */
|
||||
// public static int getLoveDays(String loveDay) {
|
||||
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
// int days = 0;
|
||||
// try {
|
||||
// long time = System.currentTimeMillis() - dateFormat.parse(loveDay).getTime();
|
||||
// days = (int) (time / (24 * 60 * 60 * 1000));
|
||||
//
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return days;
|
||||
// }
|
||||
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return days;
|
||||
/**
|
||||
* @param startDay
|
||||
* @return int
|
||||
* @descriptions 计算日期茶 days
|
||||
* @author bamanker
|
||||
* @date 2026/1/8 12:38
|
||||
*/
|
||||
public static int getDayDiff(String startDay) {
|
||||
|
||||
LocalDate dateNow = LocalDate.now();
|
||||
LocalDate dateStart = LocalDate.parse(startDay);
|
||||
return (int) ChronoUnit.DAYS.between(dateStart, dateNow);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ DL:
|
||||
boy-birthday: 1995-3-30
|
||||
love-day: 2022-07-16
|
||||
cat-birthday: 2022-10-23
|
||||
wedding-day: 2025-10-08
|
||||
|
||||
wechat:
|
||||
app-id: wxba68702957f8b93e
|
||||
@@ -22,8 +23,8 @@ wechat:
|
||||
# ME: oo5bL6bK_4TC0tb-Wa5oiugTPVeQ
|
||||
#LILI: oo5bL6QafHJa9zQNYKS0fIhFC0zM
|
||||
open-id: oo5bL6QafHJa9zQNYKS0fIhFC0zM
|
||||
template-id-morning: E7eBkU0uzBFDwC9MiqPtHNlSlByDafw4BIqZvfOtTOs
|
||||
template-id-night: 5ExwX0ID1ccueXNb7v-dqTcDH-lYtHatg0Mqt4FDIaY
|
||||
template-id-morning: dWNAL-ZOzpBhnByFoTamt9DlJQYLB5z3ldKLvQstyU4
|
||||
template-id-night: oraLiXC-8740stYc1a7mpzUFHiAIRaM3JikqibZ2grE
|
||||
|
||||
color:
|
||||
now: '#99CCCC'
|
||||
@@ -39,6 +40,7 @@ wechat:
|
||||
bbir: '#FF3399'
|
||||
cbir: '#FF3399'
|
||||
loveDay: '#FF3399'
|
||||
weddingDay: '#FF3399'
|
||||
remark: '#FF6666'
|
||||
city: ""
|
||||
tips: ""
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.bamanker.dailylove.domain.DataItem;
|
||||
import com.bamanker.dailylove.domain.TianXinReqParam;
|
||||
import com.bamanker.dailylove.domain.Weather;
|
||||
import com.bamanker.dailylove.service.DataRemoteClient;
|
||||
import com.bamanker.dailylove.utils.DataUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -162,8 +163,8 @@ class DailyLoveApplicationTests {
|
||||
//
|
||||
// @Test
|
||||
// void test1() {
|
||||
// int loveDays = getBirthdays("2023-05-14");
|
||||
// log.info("-------------------------------{}", loveDays);
|
||||
// int weddingDays = DataUtils.getWeddingDays("2025-10-08");
|
||||
// log.info("wedding_days:{}", weddingDays);
|
||||
// }
|
||||
//
|
||||
// public static int getLoveDays(String loveday) {
|
||||
|
||||
Reference in New Issue
Block a user