此功能分两部分,第一部分定时器每天定点推送一条URL+图片+文字,第二部分点击URL进入页面,能看到生日祝福文字、背景图片、音乐。

第一部分定时器每天定点推送一条URL+图片+文字

ApplicationContext-elasticJob.xml设置定时任务,指定触发频率和运行类,

/wxapp/src/main/resources/spring/ApplicationContext-elasticJob.xml设置定时任务:

定时器知识:https://blog.csdn.net/Linweiqiang5/article/details/86741258

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:reg="http://www.dangdang.com/schema/ddframe/reg" xmlns:job="http://www.dangdang.com/schema/ddframe/job" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsdhttp://www.dangdang.com/schema/ddframe/reg http://www.dangdang.com/schema/ddframe/reg/reg.xsd http://www.dangdang.com/schema/ddframe/job http://www.dangdang.com/schema/ddframe/job/job.xsd"><!-- 生日祝福日报 --><job:simple id="BirthdayBlessingDailyJob" class="com.aoyang.wxapp.quartz.job.BirthdayBlessingDailyJob" registry-center-ref="regCenter"  cron="0 00 8 1/1 * ?"  sharding-total-count="1" /><!--configure registry center --><reg:zookeeper id="regCenter" server-lists="192.168.1.109:2181" namespace="wx-dd-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" /><!--configure job --><job:simple id="myElasticJob"                     class="com.aoyang.wxapp.quartz.job.MyElasticJob" registry-center-ref="regCenter" cron="0/10 * * * * ?"   sharding-total-count="1"/><!-- 组织人数处理 --><job:simple id="departmentUserNumberJob"          class="com.aoyang.wxapp.quartz.job.DepartmentUserNumberJob" registry-center-ref="regCenter"  cron="1 28 21 1/1 * ?"  sharding-total-count="1"  /><!-- 定时同步HR人员信息 --><job:simple id="employeeSyncFromHRJob"           class="com.aoyang.wxapp.quartz.job.EmployeeSyncFromHRJob" registry-center-ref="regCenter"  cron="1 30 21 1/1 * ? "  sharding-total-count="1"/><!-- 更新人员信息到微信 --><job:simple id="employeeSyncToWeixinJob"                     class="com.aoyang.wxapp.quartz.job.EmployeeSyncToWeixinJob" registry-center-ref="regCenter"  cron="1 1 20 1/1 * ?"  sharding-total-count="1"  /><!-- 用车:隔天任务处理 --><job:simple id="vehicleGgsReportSynchronizeJob" class="com.aoyang.wxapp.quartz.job.VehicleGgsReportSynchronizeJob" registry-center-ref="regCenter"  cron="0 0 1 1/1 * ?"  sharding-total-count="1" /><!-- 车辆使用日报 --><job:simple id="vehicleReportDailySynchronizeJob" class="com.aoyang.wxapp.quartz.job.VehicleReportDailySynchronizeJob" registry-center-ref="regCenter"  cron="1 30 13 1/1 * ?"  sharding-total-count="1" /><!-- 组织架构同步 --><job:simple id="organisationSynchronizeJob"    class="com.aoyang.wxapp.quartz.job.OrganisationSynchronizeJob" registry-center-ref="regCenter"  cron="1 33 23 1/1 * ?"  sharding-total-count="1"  /><!-- 微信信息发送   --><job:simple id="weixinMsgSendSynchronizeJob"   class="com.aoyang.wxapp.quartz.job.WeixinMsgSendSynchronizeJob" registry-center-ref="regCenter"  cron="0/5 * * * * ?"  sharding-total-count="1" /><!-- BIS日推给组长 --><job:simple id="bisDailyReport"                class="com.aoyang.wxapp.quartz.job.BisDailyReport" registry-center-ref="regCenter"  cron="0 0 12 ? * SAT"  sharding-total-count="1" /><!-- itsm 自动催办 --><job:simple id="itsmAutoReminder" class="com.aoyang.wxapp.quartz.job.ItsmAutoReminder" registry-center-ref="regCenter"  cron="0 0/5 8-17 ? * MON-SAT"  sharding-total-count="1" /><!-- it服务统计日报推送 --><job:simple id="itServiceStatisticsMsg" class="com.aoyang.wxapp.quartz.job.ItServiceStatisticsMsg" registry-center-ref="regCenter"  cron="0 0 7 * * ?"  sharding-total-count="1" /><!-- 接收ESB耗材订单数据: 每天凌晨1,3,5各拉取一次 --><job:simple id="esbDailyOrder" class="com.aoyang.wxapp.quartz.job.EsbDailyOrder" registry-center-ref="regCenter"  cron="0 0 1,3,5 * * ?"  sharding-total-count="1" /><!-- 接收ESB资产采购入库数据:每天凌晨1,3,5各拉取一次  --><job:simple id="esbDailyAssetOrder" class="com.aoyang.wxapp.quartz.job.EsbDailyAssetOrder" registry-center-ref="regCenter" cron="0 0 1,3,5 * * ?"  sharding-total-count="1" /><!-- 接收ESB固定资产卡片数据:每天凌晨1,3,5各拉取一次 --><job:simple id="esbDailyFixedAssetCard" class="com.aoyang.wxapp.quartz.job.EsbDailyFixedAssetCard" registry-center-ref="regCenter" cron="0 0 1,3,5 * * ?" sharding-total-count="1" /><!-- 维护原资产表单ASSET_LIST:周一到周六每天23点59分运行 --><job:simple id="eDailyUpdateAssetList" class="com.aoyang.wxapp.quartz.job.EDailyUpdateAssetList" registry-center-ref="regCenter" cron="0 59 23 ? * MON-SAT" sharding-total-count="1" /> <!--接收固定资产清单:每隔1小时   张凯:实现打印功能而做的,,--><job:simple id="asPrtTimetask"  class="com.aoyang.wxapp.quartz.job.AsPrtTimetask" registry-center-ref="regCenter" cron="0 0 0/1 * * ?"   sharding-total-count="1"/><!-- 发送上个月资产耗材总费用:每月1号8点 --><job:simple id="pushLeaderTimetask"  class="com.aoyang.wxapp.quartz.job.PushLeaderTimetask" registry-center-ref="regCenter" cron="0 0 8 1 * ?"   sharding-total-count="1"/><job:simple id="stats7ClockTask"  class="com.aoyang.wxapp.quartz.job.Stats7ClockTask" registry-center-ref="regCenter" cron="0 0 7 * * ?"   sharding-total-count="1"/><job:simple id="stats8ClockTask"  class="com.aoyang.wxapp.quartz.job.Stats8ClockTask" registry-center-ref="regCenter" cron="0 0 8 * * ?"   sharding-total-count="1"/><job:simple id="ayyyGenerateIncomeTask"  class="com.aoyang.wxapp.quartz.job.AyyyGenerateIncomeTask" registry-center-ref="regCenter" cron="0 30 2 * * ?"   sharding-total-count="1"/></beans>

/wx-quartz-job/src/main/java/com/aoyang/wxapp/quartz/job/BirthdayBlessingDailyJob.java

定时推送类BirthdayBlessingDailyJob,注入两个Service

staffService,用于查询今天过生日的人员名单,

sendService,用于将信息推送给人员名单,

/*** Project Name: 澳洋信息系统微信台平台 Date:2019年8月20日 Copyright(c) 2019 All Rights Reserved* * @author qiudc.* */
package com.aoyang.wxapp.quartz.job;import java.util.ArrayList;
import java.util.List;import javax.annotation.Resource;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;import com.aoyang.weixin.corp.model.msg.Article;
import com.aoyang.weixin.corp.model.msg.News;
import com.aoyang.weixin.corp.model.msg.resp.WxCorpNewsResponseMessage;
import com.aoyang.weixin.corp.service.WxCorpMessageSendService;
import com.aoyang.weixin.util.OAuth2Utils;
import com.aoyang.wxapp.service.fhoa.staff.StaffManager;
import com.aoyang.wxapp.util.PageData;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;@Component("birthdayBlessingDailyJob")
public class BirthdayBlessingDailyJob implements SimpleJob {private static final Logger LOGGER = LoggerFactory.getLogger(BirthdayBlessingDailyJob.class);private static final String BIRTHDAY_BLESSING_URL = "weixin/hr/birthdayBlessing";@Resource(name="staffService")private StaffManager staffService;@Autowiredprivate WxCorpMessageSendService sendService;@Value("${Hostname}")private String hostName;@Value("${agent.hr}")private int hrAgentId;public void syncVehicleReportDaily() throws Exception {LOGGER.info("生日祝福日报推送开始......");try {PageData resultPd = staffService.getBirthdayStaffList();if (resultPd != null) {String birtydayStaffId = resultPd.getString("STAFF_ID_LIST");String birtydayStaffIdAll = birtydayStaffId.replace(",", "|");//推送的文字内容、图片url、跳转链接String sendContent = String.format("澳洋集团祝您生日快乐!");        String picurl = "http://weixin.aoyang.com/group1/M00/05/8D/wKgBxl1LeCCADe4-AAoVjP4jB4A736.jpg";String url = OAuth2Utils.getOAuthUrl(hostName,BIRTHDAY_BLESSING_URL,hrAgentId);List<Article> articles = new ArrayList<Article>();articles.add(new Article("生日祝福", sendContent, picurl, url));News news = new News();news.setArticles(articles);//推送微信通知给所有今天过生日的人WxCorpNewsResponseMessage message = new WxCorpNewsResponseMessage();message.setNews(news);message.setTouser(birtydayStaffIdAll);//隶属于IT新服务message.setAgentid(hrAgentId);message.setTotag("@all"); //@all表示忽略本参数message.setToparty("@all");String backMsg = sendService.sendMessage(message);backMsg = (backMsg == null ? "" : backMsg);LOGGER.info("[ITSM] 推送消息 : 生日祝福" + ";返回的数据为:" + backMsg);}} catch (Exception e) {LOGGER.error("生日祝福日报推送时发生异常,{}", e);}LOGGER.info("生日祝福日报推送定时任务执行完毕");}@Overridepublic void execute(ShardingContext shardingContext) {try {LOGGER.info("分片值:" + shardingContext.getShardingItem());syncVehicleReportDaily();} catch (Exception e) {LOGGER.error(e.getMessage());}}
}

/wx-system-api/src/main/java/com/aoyang/wxapp/service/fhoa/staff/StaffManager.java

StaffManager接口

/*** Project Name: 澳洋信息系统微信管理平台* Date:2016年10月10日* Copyright(c) 2016 All Rights Reserved*/
package com.aoyang.wxapp.service.fhoa.staff;import java.util.List;
import java.util.Map;import com.aoyang.wxapp.entity.Page;
import com.aoyang.wxapp.util.PageData;/** * 员工管理接口*/
public interface StaffManager{/**通过id获取数据* @param pd* @throws Exception*/public PageData findById(PageData pd)throws Exception;/*** 根据用户ID查找.* * @param userId 用户ID.* @return* @throws Exception*/public PageData findByUserId(String userId) throws Exception;/*** 获取当天年月日String.*@return String*/String getTodayDate()throws Exception;/*** 生日祝福人员列表.*@return List<PageData>* @param */public PageData getBirthdayStaffList()throws Exception;}

/wx-system-service/src/main/java/com/aoyang/wxapp/service/fhoa/staff/impl/StaffService.java

StaffService实现StaffManager接口,

/*** Project Name: 澳洋信息系统微信管理平台* Date:2016年10月10日* Copyright(c) 2016 All Rights Reserved*/
package com.aoyang.wxapp.service.fhoa.staff.impl;
import com.aoyang.wxapp.dao.DaoSupport;
import com.aoyang.wxapp.entity.Page;
import com.aoyang.wxapp.service.fhoa.staff.StaffManager;
import com.aoyang.wxapp.util.PageData;/** * 员工管理.*/
@Service("staffService")
public class StaffService implements StaffManager{@Resource(name = "daoSupport")private DaoSupport dao;/**通过id获取数据* @param pd* @throws Exception*/public PageData findById(PageData pd)throws Exception{return (PageData)dao.findForObject("StaffMapper.findById", pd);}@Overridepublic PageData findByUserId(String userId) throws Exception {PageData pd = new PageData();pd.put("STAFF_ID", userId);Object obj = dao.findForObject("StaffMapper.findByUserId", userId);if(obj != null) {pd = (PageData)obj;return pd;}return null;}/*** 获取当天年月日String.*@return String*/@Overridepublic String getTodayDate() throws Exception {return (String)dao.findForObject("StaffMapper.getTodayDate", null);}/*** 生日祝福人员列表.*@return List<PageData>* @param */@Overridepublic PageData getBirthdayStaffList() throws Exception {return (PageData) dao.findForObject("StaffMapper.getBirthdayStaffList",null);}}

/wxapp/src/main/resources/mybatis1/fhoa/StaffMapper.xml

xml文件从数据库读取数据

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="StaffMapper"><!--表名 --><sql id="tableName">OA_STAFF</sql><!-- 字段 --><sql id="Field">NAME,NAME_EN,BIANMA,DEPARTMENT_ID,FUNCTIONS,TEL,EMAIL,SEX,BIRTHDAY,NATION,JOBTYPE,JOBJOINTIME,FADDRESS,POLITICAL,PJOINTIME,SFID,MARITAL,DJOINTIME,POST,POJOINTIME,EDUCATION,SCHOOL,MAJOR,FTITLE,CERTIFICATE,CONTRACTLENGTH,CSTARTTIME,CENDTIME,ADDRESS,USER_ID,BZ,HIDETEL,UPDATE_DATE,QQ,WECHAT,STATION,POSITION,HIREDATE,SHORTPHONE,WORKPLACE,WORKPHONE,STAFF_ID</sql><!-- 通过ID获取数据 --><select id="findById" parameterType="pd" resultType="pd">select<include refid="Field"></include>from<include refid="tableName"></include>whereSTAFF_ID = #{STAFF_ID}</select><!-- 通过ID获取数据 --><select id="findByUserId" parameterType="pd" resultType="pd">select<include refid="Field"></include>from<include refid="tableName"></include>whereSTAFF_ID = #{STAFF_ID}</select><!-- 获取当天年月日String --><select id="getTodayDate" resultType="string">select TO_CHAR(SYSDATE,'YYYY-MM-DD') from dual</select><!-- 获取今天生日的人员名单 --><select id="getBirthdayStaffList" resultType="pd">SELECTLISTAGG (STAFF_ID, ',') WITHIN GROUP (ORDER BY STAFF_ID) AS STAFF_ID_LISTFROM<include refid="tableName"></include> WHERESUBSTR (BIRTHDAY, 6, 5) = TO_CHAR (SYSDATE, 'MM-DD')</select></mapper>

/wx-weixin-core/src/main/java/com/aoyang/weixin/util/OAuth2Utils.java

package com.aoyang.weixin.util;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;/*** 微信OAuth工具类.* * @author huangcheng@aoyang.com.**/
public class OAuth2Utils {private static Log logger = LogFactory.getLog(OAuth2Utils.class);private OAuth2Utils() {};/** 回调验证的URL前缀. */private static final String OAUTH_URL_PREFIX = "http://weixin.aoyang.com/wxapp/weixin/authenticate.do?state=";private static final String OAUTH_URL_PREFIX_WITHOUT_DOMAIN = "/wxapp/weixin/authenticate.do?agentId=AGENT_ID&state=STATE";private static final String HTTP_PREFIX = "http://";/*** * @param hostName*            : 域名* @param contextPath* @param agentId* @return*/public static String getOAuthUrl(String hostName, String contextPath, int agentId) {if (contextPath == null || contextPath.trim().length() == 0) {throw new IllegalArgumentException("contextPath 不能为null");}// 解决contextPath携带参数的问题hostName = hostName.startsWith(HTTP_PREFIX) ? hostName : HTTP_PREFIX + hostName;String url = hostName + OAUTH_URL_PREFIX_WITHOUT_DOMAIN;String newUrl = url.replace("AGENT_ID", String.valueOf(agentId)).replace("STATE", contextPath);logger.info("拼接替换后的url为:" + newUrl);return newUrl;}/*** 获取回调的URL地址,此地址可以获取企业微信用户身份(UserId).* * @param contextPath*            应用程序上下文路径,不能为<code>null</code>或空值.*            如:weixin/addresslist/showmygroup.do, 不包含协议、端口号、域名、程序路径等.* @return 指向我们程序且回以获取用户身份信息的URL.*/@Deprecatedpublic static String getOAuthUrl(String contextPath, int agentId) {if (contextPath == null || contextPath.trim().length() == 0) {throw new IllegalArgumentException("contextPath 不能为null");}String url = OAUTH_URL_PREFIX + contextPath;url = url + "&agentId=" + agentId;logger.info("生成URL -->" + url);return url;}}

/wx-weixin-api/src/main/java/com/aoyang/weixin/corp/service/WxCorpMessageSendService.java

/*** Project Name: 澳洋信息系统微信台平台* Date:2016年11月12日* Copyright(c) 2016 All Rights Reserved* @author hc2900@126.com.* */
package com.aoyang.weixin.corp.service;import com.aoyang.weixin.corp.model.msg.resp.WxCorpResponseMessage;
import com.aoyang.weixin.exception.WxException;/*** 企业微信号向微信用户发送消息服务.* * @author hc2900@126.com* */
public interface WxCorpMessageSendService {/*** 企业接口向下属关注用户发送微信消息.* * @param message*            要发送的消息.* @return JSON格式的返回结果.格式如下:* *         <pre>* {* "errcode": 0,* "errmsg": "ok",* "invaliduser": "UserID1",* "invalidparty":"PartyID1",* "invalidtag":"TagID1"* }* * @return JSON格式的返回结果,可能 会返回 <code>null</code>.* * * @throws WxException 如果无法发送抛出异常。*/public String sendMessage(WxCorpResponseMessage message) throws WxException;/*** 企业接口向下属关注用户发送微信消息.* * @param jsonWxMessage String格式的微信消息.* @return JSON格式的返回结果,可能 会返回 <code>null</code>.* @throws WxException 如果无法发送抛出异常.*/public String sendMessage(String jsonWxMessage) throws WxException;/*** 企业接口向下属关注用户发送微信文本消息.* * @param touser*            成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,*            则向关注该企业应用的全部成员发送* @param toparty*            部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数* @param totag*            标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数* @param content*            消息内容* @param agentId*            企业微信应用ID,可以在微信管理后台获取不同的应用ID.* @return*/public String sendTextMessage(String touser, String toparty, String totag,String content, Integer agentId) throws WxException;}

/wx-weixin-core/src/main/java/com/aoyang/weixin/corp/model/msg/Article.java

package com.aoyang.weixin.corp.model.msg;/*** 图文类.* * @author hc2900@126.com**/
public class Article {/**图文标题.*/private String title;/**图文描述.*/private String description;/**图片链接,支持JPG,PNG,较好的效果为大图640*320,小图80*80.*/private String picurl;/**点击图文消息跳转链接.*/private String url;/*** 构造函数.*/public Article() {}/*** 构造函数.* * @param title 图文标题.* @param description 图文描述.* @param picUrl 图片链接.* @param url 跳转链接.*/public Article(String title, String description, String picUrl, String url) {super();this.title = title;this.description = description;this.picurl = picUrl;this.url = url;}/*** @return the title*/public String getTitle() {return title;}/*** @param title the title to set*/public void setTitle(String title) {this.title = title;}/*** @return the description*/public String getDescription() {return description;}/*** @param description the description to set*/public void setDescription(String description) {this.description = description;}/*** @return the picUrl*/public String getPicurl() {return picurl;}/*** @param picurl the picUrl to set*/public void setPicurl(String picurl) {this.picurl = picurl;}/*** @return the url*/public String getUrl() {return url;}/*** @param url the url to set*/public void setUrl(String url) {this.url = url;}}

/wx-weixin-core/src/main/java/com/aoyang/weixin/corp/model/msg/News.java

/*** Project Name: 澳洋信息系统微信台平台* Date:2016年10月9日* Copyright(c) 2016 All Rights Reserved* @author hc2900@126.com.* */
package com.aoyang.weixin.corp.model.msg;import java.util.Arrays;
import java.util.List;public class News {private List<Article> articles;public News() {}public News(List<Article> article) {this.articles = article;}public News(Article...articles ) {this.articles = Arrays.asList(articles);}public List<Article> getArticles() {return articles;}public void setArticles(List<Article> article) {this.articles = article;}}

配置文件:

/wxapp/src/main/resources/env/dev.properties

db_url=jdbc:oracle:thin:@172.30.112.197:1521:orclutf8
db_driverClassName=oracle.jdbc.OracleDriver
db_username=itsm20
db_password=Itsm20.123#huashengke---xinkefuwu
wx_corpID=ww22141d223bc1a1ad
wx_token=lFTdRHxw2CZsNnPY1rm
wx_encodingAESKey=o0JcSyWPz3HW5sbhpAbSjMUTWJtfC97kOf8hgQybkDc
wx_secret=v6DBWgCBbh6SiWoznl1AfAf-ZAta-xEftXy2JfqMGl0
wx_hostname=263fw85879.qicp.vip:19303
#wx_hostname=2399016x6l.qicp.vip:51286wx_agent_hr=1000016

/wxapp/src/main/resources/weixin.properties 调取 dev.properties

CorpID=${wx_corpID}
Token=${wx_token}
EncodingAESKey=${wx_encodingAESKey}
Secret=${wx_secret}
Hostname=${wx_hostname}agent.inventory=${wx_agent_inventory}
agent.itsm.new=${wx_agent_itsm_new}
agent.itsm.new.workbench=${wx_agent_itsm_new_workbench}
agent.stats=${wx_agent_stats}
agent.hr=${wx_agent_hr}consumables.apply.templateId=${consumables_apply_templateId}
knowledge.audit.templateId=${knowledge_audit_templateId}out.sourcing.templateId=${out_sourcing_templateId}
consumables.outbound.templateId=${consumables_outbound_templateId}
nonfixed.asset.nonvalueChange.templateId=${nonfixed_asset_nonvalueChange_templateId}
asset.inventory.audit.templateId=${asset_inventory_audit_templateId}
fixed.asset.nonvalueChange.templateId=${fixed_asset_nonvalueChange_templateId}

测试时使用的是:/wxapp/src/test/resources/weixin.properties

#huashengke---xinkefuwu
CorpID=ww22141d223bc1a1ad
Token=lFTdRHxw2CZsNnPY1rm
EncodingAESKey=o0JcSyWPz3HW5sbhpAbSjMUTWJtfC97kOf8hgQybkDc
Secret=v6DBWgCBbh6SiWoznl1AfAf-ZAta-xEftXy2JfqMGl0
#Hostname=2m04471c37.51mypc.cn:14127
Hostname=263fw85879.qicp.vip:19303
#Hostname=wei.aoyang.comagent.hr=1000016

第二部分点击URL进入页面,能看到生日祝福文字、背景图片、音乐

/wxapp/src/main/java/com/aoyang/wxapp/controller/hr/HrController.java

/*** Project Name: 澳洋信息系统微信台平台* Date:2017年1月3日* Copyright(c) 2016 All Rights Reserved* @author gongkx* */
package com.aoyang.wxapp.controller.hr;import java.util.Calendar;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;import com.aoyang.wxapp.controller.BaseController;
import com.aoyang.wxapp.service.fhoa.staff.StaffManager;
import com.aoyang.wxapp.service.kq.KqService;
import com.aoyang.wxapp.service.salary.HrService;
import com.aoyang.wxapp.util.DateTimeUtils;
import com.aoyang.wxapp.util.PageData;import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping(value = "/weixin/hr")
public class HrController extends BaseController {private static final Logger LOGGER = LoggerFactory.getLogger(HrController.class);@Autowiredprivate HrService hrService;@Resource(name = "staffService")private StaffManager staffService;@AutowiredKqService kq;/*** 生日祝福推送.* qiudc* @param page* @throws Exception*/@RequestMapping(value = "/birthdayBlessing")public ModelAndView birthdayBlessing(ModelAndView model) throws Exception {model.setViewName("hr/birthdayBlessing");String userId = getCurrentUserId();userId = "AY006278";if (!StringUtils.isEmpty(userId)) {PageData staff = staffService.findByUserId(userId);String todayDate = staffService.getTodayDate();String year = todayDate.substring(0, 4); //2019-08-25String birthday = staff.getString("BIRTHDAY");String month = birthday.substring(5, 7);String day = birthday.substring(8, 10);model.addObject("year", year);model.addObject("month", month);model.addObject("day", day);model.addObject("staff", staff);return model;}return model;}
}

页面JSP:

/wxapp/src/main/webapp/WEB-INF/jsp/hr/birthdayBlessing.jsp

注意导入音乐的写法,判断性别的写法,

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0"><title>祝您生日快乐</title><base href="<%=basePath%>"><!-- ace styles --><link rel="stylesheet" href="static/ace/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" /><!-- 下拉框 --><link rel="stylesheet" href="static/ace/css/chosen.css" /><!-- jsp文件头和头部 --><!--<link rel="stylesheet" href="static/ace/css/bootstrap.css" />--><!--<link rel="stylesheet" href="static/ace/css/font-awesome.css" />--><!-- 使用HR指定字体 --><link rel="stylesheet" href="static/ace/css/birthdayblessing.css" /><style>.main-container{background-image:url(static/weixin/images/birthday_bkgrd.jpg);background-repeat: no-repeat;background-size: cover;height: 100vh;padding: 45vw 4vw 4vw 4vw;}.userName{font-size: 22px;color: #EF8200;}</style>
</head>
<body class="no-skin"><div class="main-container" id="main-container"><!--   引用网络音乐-网易云音乐 --><!--  <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=298 height=52  --><!--  src="//music.163.com/outchain/player?type=2&id=469762679&auto=1&height=32" hidden="true"></iframe> --><!-- 引用本地音乐 --><audio id="birthdayAudio" src="static/sound/happyBirthday.ogg" preload="auto" loop autoplaystyle="clear:both;display:block;margin:auto" ></audio><div class="main-content"><p><c:if test="${staff.SEX == 1 }"><span>尊敬的</span> <span class="userName">${staff.NAME} </span><span>先生:</span><br/></c:if><c:if test="${staff.SEX == 2 }"><span>尊敬的</span> <span class="userName"> ${staff.NAME} </span><span>女士:</span><br/></c:if>&nbsp;&nbsp;&nbsp;&nbsp;光阴如水,日月如梭。又是一年时光悄然而去。在这特别的日子里,公司全体同仁给您送上生日最真挚的祝福。祝您生日快乐!阖家欢乐!公司的发展倾注了您和您家人的支持和奉献,感谢您的辛勤工作,在此向您和您的家人表示感谢!愿我们在今后的工作中和谐,同心共创美好明天。<br/></p><p align="right">${year} 年 ${month} 月 ${day} 日&nbsp;&nbsp;</p></div><!-- /.main-content --><!-- 返回顶部 --><a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse"><i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i></a></div><!-- /.main-container --><!-- basic scripts --><!-- 页面底部js¨ --><script type="text/javascript">window.jQuery || document.write("<script src='<%=basePath%>static/ace/js/jquery.js'>"+"<"+"/script>");</script><!-- <![endif]--><script type="text/javascript">if('ontouchstart' in document.documentElement) document.write("<script src='<%=basePath%>static/ace/js/jquery.mobile.custom.js'>"+"<"+"/script>");</script><script src="static/ace/js/bootstrap.js"></script><!-- 删除时确认窗口 --><script src="static/ace/js/bootbox.js"></script><!-- ace scripts --><script src="static/ace/js/ace/ace.js"></script><!-- 下拉框 --><script src="static/ace/js/chosen.jquery.js"></script><!-- 日期框 --><script src="static/ace/js/date-time/bootstrap-datepicker.js"></script><script src="static/js/jquery.tablerowspan.js"></script><!--提示框--><script type="text/javascript" src="static/js/jquery.tips.js"></script><!--<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>--><script type="text/javascript"></script></body>
</html>

css渲染文件:

/wxapp/src/main/webapp/static/ace/css/birthdayblessing.css

将 FZSEJW.ttf 字体文件放入 /wxapp/src/main/webapp/static/ace/fonts/FZSEJW.ttf

注意引用字体的写法 @font-face font-family ,

和 字体阴影的写法 text-shadow:2.5px 2.5px 2.5px #ffffff;

/* 方正少儿体fonts for /wxapp/src/main/webapp/WEB-INF/jsp/hr/birthdayBlessing.jsp */
@font-face{font-family: 'fangzhengshaoer'; src: url('../fonts/FZSEJW.ttf');
}html {-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;
}
body {margin: 0;font-family: fangzhengshaoer;font-size: 18px;color: #32282e;text-shadow:2.5px 2.5px 2.5px #ffffff;}summary {display: block;
}
video {display: inline-block;vertical-align: baseline;
}
audio:not([controls]) {display: none;height: 0;
}

写测试类,推送生日祝福给用户:

/wxapp/src/test/java/com/aoyang/wxapp/quartz/job/BirthdayBlessingDailyJobTest.java

运行测试方法,推送生日祝福到微信,点击推送消息,看能否打开网页。

/*** All rights Reserved,Designed By www.aoyang.com* @Title EmployeeSyncFromHRJobTest.java* @Package com.aoyang.wxapp.quartz.job* @Description :      * @Author  daixiongyan* @date 2019年8月8日* @Version V1.0* @Copyright : 2019.www.aoyang.com*/
package com.aoyang.wxapp.quartz.job;import javax.annotation.Resource;import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import com.aoyang.wxapp.BaseJunit4;
import com.aoyang.wxapp.service.fhoa.staff.StaffManager;
import com.aoyang.wxapp.util.PageData;/**
* @ClassName: EmployeeSyncFromHRJobTest
* @Description: TODO(这里用一句话描述这个类的作用)
* @author qiudechao
* @date 2019年8月8日
*
*/@RunWith(SpringJUnit4ClassRunner.class)
public class BirthdayBlessingDailyJobTest extends BaseJunit4{@Resource(name="birthdayBlessingDailyJob")private BirthdayBlessingDailyJob birthdayBlessingDailyJob;   @Resource(name="staffService")private StaffManager staffService;private static final Logger LOGGER = LoggerFactory.getLogger(BirthdayBlessingDailyJobTest.class);//birthdayBlessingDailyJob.syncVehicleReportDaily();分成两部分测试@Testpublic void test() {try {birthdayBlessingDailyJob.syncVehicleReportDaily();} catch (Exception e) {LOGGER.error("生日祝福出现异常:{}", e);}}
}

电脑端浏览生日祝福页面效果:

本地网址:http://localhost:9090/wxapp/weixin/hr/birthdayBlessing.do

外网映射网址:http://2399016x6l.qicp.vip:51286/wxapp/weixin/hr/birthdayBlessing.do

相关连接:

利用花生壳搭建微信小应用  https://blog.csdn.net/qiudechao1/article/details/100141669

开发案例---微信定时推送:生日祝福相关推荐

  1. 微信自动化推送天气预报信息教程【Python版源代码】

    微信自动化推送教程 一.微信推送教程 - 呆瓜版教程[直接使用] 1 注册一个微信公众号 2 修改配置文件 3. 对接api实现 二.修改源码版教程 - [适合有基础] 1. 安装python3 2. ...

  2. 微信小程序云开发定时推送订阅消息

    微信小程序云开发定时推送订阅消息 1.找到自己想要的模板 (1)点击订阅消息 (2)点击公共模板库,然后找到想要选用的模板,点击选用. (3)在我的模板里面,复制模板id. 如果找不到想要用的模板,可 ...

  3. 微信小程序 - 云开发轮询实现定时推送订阅消息

    前言 受众:已有小程序和云开发经验(没有的话照着流程和官方文档也应该可以实现) 关于小程序的消息推送,我了解到的有以下几种实现方式 1.模板消息,已于2020 年 1 月 10 日下线 2.通过服务端 ...

  4. 通过GitHub Actions给微信公众测试号和钉钉群定时推送消息(Python)

    通过GitHub Actions给微信公众测试号和钉钉群定时推送消息(Python) https://github.com/QInzhengk/Math-Model-and-Machine-Learn ...

  5. 通过XXL-JOB定时推送bug信息到企业微信群1

    通过XXL-JOB定时推送bug信息到企业微信群. 效果图 前提: 公司的Bug平台可以提供接口返回给你bug数据. 一.在企业微信群创建机器人 1.群右键创建机器人 2.拿到对应webhook. 二 ...

  6. 微信早安定时推送 简单方法教程(windows通用)

    无需计算机基础,跟着教程无脑学! 如果你还没做出这样的效果 请参考往期文章(必能学会): https://blog.csdn.net/A_Xunla/article/details/126521400 ...

  7. 自动化情侣微信早安信息定时推送

    文章目录 一.效果展示 二.配置config.txt(重点) 2.1 填写appID和appsecret 2.1 创建测试模板填写template_id 2.4 填写user 2.5 填写weathe ...

  8. 【微信早安定时推送3.0最牛版】微信消息推送后 可提醒可顶置,聊天框名称,头像都可修改~

    微信早安3.0最牛版重磅推出!!! 全网最全最详细教程,无基础看过的都说好,不白找. 往期推送: 微信早安推送1.0版: https://blog.csdn.net/A_Xunla/article/d ...

  9. 微信早安,利用uniCloud阿里云的云函数实现定时推送

    最近比较火的微信早安,看了一下小红书 @猪咪不是猪的教程,也动手做了一下,并做了一下实现定时的优化与符合我自己需求的修改.由于本人并不很熟悉python,所以部分修改是基于教程源码做修改的,在此也感谢 ...

最新文章

  1. Base64编码和解码
  2. java 继承类 变量、静态变量、构造函数执行顺序
  3. 2017第17周五当前困境思考2
  4. 使用 matlab 产生GK101任意波数据文件的方法
  5. 【2012百度之星/初赛上】C:集合的交与并
  6. python 美化输出_python基础_格式化输出(%用法和format用法)
  7. 亿航智能⻓续航⻜机有望在4-8周内首⻜亮相
  8. eclips常用快捷键
  9. 【Spark亚太研究院系列丛书】Spark实战高手之-构建Spark集群-安装Ubuntu系统(3)
  10. 谈谈对象和XML文件的转换
  11. wajueji.php,独家解析:为什么说斗山DX55-9C是5吨小挖掘机中的新机皇
  12. 微信小程序 数据库获取字符串 在view中显示换行
  13. 麦吉尔学和ubc计算机专业,申请多伦多、UBC和麦吉尔三所大学建筑专业的作品集要求...
  14. Linux是什么?它是哪个国家开发的
  15. 极致的遮罩处理(一):DeepFaceLab手动遮罩编辑。
  16. 《交互式程序设计 第2版》一1.2.4 交互语言
  17. 4种FPGA时钟分频 【附源码】:1.偶数分频;2.奇数分频(占空比50%);3.奇数分频(任意无占空比);4.小数分频;
  18. Oracle 计算表中的时间与当前时间差
  19. python语言公开发行版本诞生于哪年-python于哪一年正式发布
  20. 线性代数学习笔记——第七十八讲——用正交变换化二次型为标准型

热门文章

  1. C++ 多种取整函数的使用和区别: ceil() floor() round() trunc() rint() nearbyint()
  2. Java算术右移和逻辑右移
  3. php直播表情美颜的实现,如何在直播中实现优质的美颜SDK效果
  4. OSS报表系统实训笔记
  5. html四种选择器的特点,css四种选择器总结
  6. DevOps自动化测试的原则和实践
  7. Unity TileMap工具教程
  8. JSP前三章测试改错
  9. 锋利的jQuery学习总结
  10. 日本标点符号的输入总结