/**
* 每天将指定信息推送到微信个人
*/
@Override
public void sendWechatToUser() {
String url = WEI_MI_SHU_API + "/openapi/v1/chat/contact";
WeiZhiMiShuVO weiZhiMiShuVO = new WeiZhiMiShuVO();
//发送文字信息
weiZhiMiShuVO.setType(1);
try {
//拿到发送的消息列表
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
SimpleDateFormat format_h = new SimpleDateFormat("yyyy-MM-dd");
//今天的日期
String toDate = format_h.format(new Date());
//相恋的日期
String lian = "2022-03-28";
//两个日期相差的天数
int cha = DateUtils.getDayByTwoDay(toDate, lian);
String todayDate = format.format(new Date());
//根据阳历计算农历
Calendar today = Calendar.getInstance();
String week = DateUtils.getDaysByWeekChina(toDate);
today.setTime(DateUtils.chineseDateFormat.parse(todayDate));
DateUtils lunar = new DateUtils(today);
String nongli = lunar.toString();
nongli = nongli.substring(nongli.indexOf("年") + 1);
StringBuilder sb = new StringBuilder();
sb.append("亲爱的老婆~早\n\n")
.append("充满希望的一天又开始了,今天也要一直开心,不能生我气气~")
.append("\n\n今天是:")
.append(todayDate)
.append(",星期")
.append(week)
.append(",农历")
.append(nongli)
.append("\n")
.append("是我们相爱的第:")
.append(cha)
.append("天")
.append("\n\n")
;
JSONObject tianqiObject = TianXingApiUtil.getWeather();
sb.append("目前济南天气:")
.append(tianqiObject.getString("weather"))
.append("\n")
.append("当前气温:")
.append(tianqiObject.getString("real"))
.append("\n")
.append("今天最高温度:")
.append(tianqiObject.getString("highest"))
.append("\n")
.append("最低温度:")
.append(tianqiObject.getString("lowest"))
.append("\n")
.append("风向:")
.append(tianqiObject.getString("wind"))
.append("\n")
.append("空气质量:")
.append(tianqiObject.getString("quality"))
.append("\n")
.append("空气质量指数:")
.append(tianqiObject.getString("aqi"))
.append("\n")
.append("小提示:")
.append(tianqiObject.getString("tips"));
//土味情话
sb.append("\n\n")
.append("爱你一日言:")
.append(TianXingApiUtil.getLoveWords())
.append("\n\n【早安寄语】")
.append(goodMorning());
weiZhiMiShuVO.setContent(sb.toString());
for (String str : SEND_USER) {
JSONObject object = new JSONObject();
object.put("apiKey", WEI_MI_SHU_KEY);
//好友昵称
object.put("name", str);
//好友备注
object.put("alias", str);
object.put("message", weiZhiMiShuVO);
String body = HttpUtil.createPost(url)
.body(JSON.toJSONString(object))
.execute()
.body();
System.out.println("传递的参数是:" + JSON.toJSONString(object));
System.out.println("发送成功了吗?" + body);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
|