|
|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.http.HttpUtils;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -43,7 +44,7 @@ public class WeChatService {
|
|
|
/**
|
|
|
* 审批流程消息提醒
|
|
|
*/
|
|
|
- private static final String PUBLIC_RELEASE_EXAMINE ="2L9AJWl2yNfgd83Fw_f_E6HiaEvPf109iw_xFtI8PXI";
|
|
|
+ private static final String SEND_TEMPLATE_ID ="2L9AJWl2yNfgd83Fw_f_E6HiaEvPf109iw_xFtI8PXI";
|
|
|
|
|
|
|
|
|
|
|
|
@@ -105,35 +106,37 @@ public class WeChatService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ public Integer addNotice(String openid ,Integer id, Date date, String remarks){
|
|
|
+ String str= DateUtils.parseStrYYYYMMDDHHMMSS(date);
|
|
|
+ return addNotice(openid,id,date,remarks);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 推送微信订阅信息,跳转为公出信息
|
|
|
* @param openid 发送对象微信openid
|
|
|
- * @param type 状态 0驳回 1发起 2同意
|
|
|
- * @param date 日期
|
|
|
- * @param aname 发送者名称
|
|
|
* @param remarks 发送信息,不能大于十五个字
|
|
|
*/
|
|
|
-// public Integer addNotice(String openid ,Integer type,Integer id, Date date, String aname,String remarks) {
|
|
|
-// Map<String, Object> map=new HashMap<String, Object>();
|
|
|
-// String accessToken=getAccessToken();
|
|
|
-// String url=send_url.replace("ACCESS_TOKEN", accessToken);
|
|
|
-// map.put("access_token", accessToken);
|
|
|
-// map.put("touser", openid);
|
|
|
-// map.put("page", "pages/egressDetails/index?id="+id);
|
|
|
-// map.put("miniprogram_state", wxState);
|
|
|
-// if (type==1) {
|
|
|
-// map.put("template_id", PUBLIC_RELEASE_EXAMINE);
|
|
|
-// map.put("data",getPublicData(type,date, aname,remarks));
|
|
|
-// }else {
|
|
|
-// map.put("template_id", PUBLIC_RELEASE_EXAMINE_RESULT);
|
|
|
-// map.put("data",getPublicData(type,date, aname,remarks));
|
|
|
-// }
|
|
|
-// return SendHttpPost(map, url);
|
|
|
-//
|
|
|
-// }
|
|
|
+ public Integer addNotice(String openid ,Integer id, String dateTime, String remarks) {
|
|
|
+ Map<String, Object> map=new HashMap<String, Object>();
|
|
|
+ String accessToken=getAccessToken();
|
|
|
+ String url=send_url.replace("ACCESS_TOKEN", accessToken);
|
|
|
+ map.put("access_token", accessToken);
|
|
|
+ map.put("touser", openid);
|
|
|
+ map.put("page", "pages/egressDetails/index?id="+id);
|
|
|
+ map.put("miniprogram_state", wxState);
|
|
|
+ map.put("template_id", SEND_TEMPLATE_ID);
|
|
|
+ map.put("data",getPublicData(dateTime,remarks));
|
|
|
+ String resString = HttpUtils.sendPost(url, map);
|
|
|
+ JSONObject res = JSON.parseObject(resString);
|
|
|
+ if (res.get("errcode")!=null) {
|
|
|
+ log.error(String.format("errcode={%s}",res.getInteger("errcode").toString()));
|
|
|
+ return res.getInteger("errcode");
|
|
|
+ }else {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
//
|
|
|
// private Integer SendHttpPost(String params, String url) {
|
|
|
// String res= HttpUtils.sendPost(url,params);
|
|
|
@@ -144,208 +147,25 @@ public class WeChatService {
|
|
|
// return 1;
|
|
|
// }
|
|
|
// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 推送微信订阅信息,跳转为报销信息
|
|
|
-// * @param openid 发送对象微信openid
|
|
|
-// * @param type 状态 0驳回 1发起 2同意
|
|
|
-// * @param date 日期
|
|
|
-// * @param aname 发送者名称
|
|
|
-// * @param remarks 发送信息,不能大于十五个字
|
|
|
-// */
|
|
|
-// public Integer addExpenseAccountWeChatNotice(String openid ,Integer type,Integer id, Date date, String aname,String remarks) {
|
|
|
-// if (openid==null )log.error("openId不能为空");
|
|
|
-// Map<String, Object> map=new HashMap<String, Object>();
|
|
|
-// String accessToken=getExpenseAccountAccessToken();
|
|
|
-// String url=send_url.replace("ACCESS_TOKEN", accessToken);
|
|
|
-// map.put("access_token", accessToken);
|
|
|
-// map.put("touser", openid);
|
|
|
-// //这里要替换成当前的
|
|
|
-// map.put("page", "pages/egressDetails/index?id="+id);
|
|
|
-// map.put("miniprogram_state", wxState);
|
|
|
-// if (type==1) {
|
|
|
-// map.put("template_id", EXPENSE_RELEASE_EXAMINE);
|
|
|
-// map.put("data",getExpenseData(type,date, aname,remarks));
|
|
|
-// }else {
|
|
|
-// map.put("template_id", EXPENSE_RELEASE_EXAMINE_RESULT);
|
|
|
-// map.put("data",getExpenseData(type,date, aname,remarks));
|
|
|
-// }
|
|
|
-// return SendHttpPost(map, url);
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 公出订阅消息组装
|
|
|
-// * @param type
|
|
|
-// * @param date
|
|
|
-// * @param aname
|
|
|
-// * @param remarks
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// private Map<String, Object> getPublicData(Integer type,Date date, String aname, String remarks) {
|
|
|
-// Map<String, Object> we=new HashMap<String, Object>();
|
|
|
-// String strDate=DateUtils.formatDate(date, AFTConstants.YMDHMS_CHINESE);
|
|
|
-// if (remarks.length()>20)remarks=remarks.substring(0,17)+"...";
|
|
|
-// if (type==1) {
|
|
|
-// Map<String, Object> v1=new HashMap<String, Object>();
|
|
|
-// v1.put("value",strDate);
|
|
|
-// we.put("time5", v1);
|
|
|
-// Map<String, Object> v2=new HashMap<String, Object>();
|
|
|
-// v2.put("value", aname);
|
|
|
-// we.put("name3", v2);
|
|
|
-// Map<String, Object> v3=new HashMap<String, Object>();
|
|
|
-// v3.put("value", remarks);
|
|
|
-// we.put("thing10", v3);
|
|
|
-// }else {
|
|
|
-// String thing2="";
|
|
|
-// if (type==0){
|
|
|
-// thing2="驳回";
|
|
|
-// }else if (type==2){
|
|
|
-// thing2="通过";
|
|
|
-// }
|
|
|
-// Map<String, Object> v1=new HashMap<String, Object>();
|
|
|
-// v1.put("value",strDate);
|
|
|
-// we.put("date3", v1);
|
|
|
-// Map<String, Object> v2=new HashMap<String, Object>();
|
|
|
-// v2.put("value", thing2);
|
|
|
-// we.put("thing2", v2);
|
|
|
-// Map<String, Object> v3=new HashMap<String, Object>();
|
|
|
-// v3.put("value", remarks);
|
|
|
-// we.put("thing6", v3);
|
|
|
-// }
|
|
|
-// return we;
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 报销订阅消息组装
|
|
|
-// * @param type
|
|
|
-// * @param date
|
|
|
-// * @param aname
|
|
|
-// * @param remarks
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// private Map<String, Object> getExpenseData(Integer type,Date date, String aname, String remarks) {
|
|
|
-// Map<String, Object> we=new HashMap<String, Object>();
|
|
|
-// String strDate=DateUtils.formatDate(date, AFTConstants.YMDHMS_CHINESE);
|
|
|
-// if (remarks.length()>20)remarks=remarks.substring(0,17)+"...";
|
|
|
-// if (type==1) {
|
|
|
-// Map<String, Object> v2=new HashMap<String, Object>();
|
|
|
-// we.put("thing4", v2);
|
|
|
-// v2.put("value", aname);
|
|
|
-// Map<String, Object> v1=new HashMap<String, Object>();
|
|
|
-// we.put("time6", v1);
|
|
|
-// v1.put("value",strDate);
|
|
|
-// Map<String, Object> v3=new HashMap<String, Object>();
|
|
|
-// we.put("thing2", v3);
|
|
|
-// v3.put("value", remarks);
|
|
|
-// }else {
|
|
|
-// String thing5="";
|
|
|
-// if (type==0){
|
|
|
-// thing5="报销驳回";
|
|
|
-// }else if (type==2){
|
|
|
-// thing5="报销通过";
|
|
|
-// }
|
|
|
-// Map<String, Object> v1=new HashMap<String, Object>();
|
|
|
-// we.put("time3", v1);
|
|
|
-// v1.put("value",strDate);
|
|
|
-// Map<String, Object> v2=new HashMap<String, Object>();
|
|
|
-// we.put("thing5", v2);
|
|
|
-// v2.put("value", thing5);
|
|
|
-// Map<String, Object> v3=new HashMap<String, Object>();
|
|
|
-// we.put("thing4", v3);
|
|
|
-// v3.put("value", remarks);
|
|
|
-// }
|
|
|
-// return we;
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// public String getAccessToken() {
|
|
|
-// Date date = new Date();
|
|
|
-// if (redisUtil.presence("access_token")||redisUtil.presence("expires_in")) {
|
|
|
-// String access_token=redisUtil.getString("access_token");
|
|
|
-// String expires_in=redisUtil.getString("expires_in");
|
|
|
-// if (date.getTime() < Long.valueOf(expires_in)) {
|
|
|
-// LoggerUtils.debug(getClass(), "redis中获取accestoken");
|
|
|
-// return access_token;
|
|
|
-// } else {
|
|
|
-// LoggerUtils.debug(getClass(), "accestoken超时重新获取");
|
|
|
-// redisUtil.deleteString("access_token");
|
|
|
-// redisUtil.deleteString("expires_in");
|
|
|
-// return setSessionAccessToken(date,0);
|
|
|
-// }
|
|
|
-//
|
|
|
-// } else {
|
|
|
-// return setSessionAccessToken(date,0);
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// public String getExpenseAccountAccessToken() {
|
|
|
-// Date date = new Date();
|
|
|
-// if (redisUtil.presence("expense_access_token")||redisUtil.presence("expense_expires_in")) {
|
|
|
-// String access_token=redisUtil.getString("expense_access_token");
|
|
|
-// String expires_in=redisUtil.getString("expense_expires_in");
|
|
|
-// if (date.getTime() < Long.valueOf(expires_in)) {
|
|
|
-// LoggerUtils.debug(getClass(), "redis中获取accestoken");
|
|
|
-// return access_token;
|
|
|
-// } else {
|
|
|
-// LoggerUtils.debug(getClass(), "accestoken超时重新获取");
|
|
|
-// redisUtil.deleteString("expense_access_token");
|
|
|
-// redisUtil.deleteString("expense_expires_in");
|
|
|
-// return setSessionAccessToken(date,1);
|
|
|
-// }
|
|
|
-//
|
|
|
-// } else {
|
|
|
-// return setSessionAccessToken(date,1);
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// /**
|
|
|
-// *
|
|
|
-// * @param date 参数
|
|
|
-// * @param type 0公出小程序 1报销小程序
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// private String setSessionAccessToken(Date date,Integer type) {
|
|
|
-// String url =null;
|
|
|
-// if (type==0){
|
|
|
-// url=String.format(
|
|
|
-// "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", appId,
|
|
|
-// appSecret);
|
|
|
-// }else if(type==1){
|
|
|
-// url=String.format(
|
|
|
-// "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", expenseAppId,
|
|
|
-// expenseAppSecret);
|
|
|
-// }
|
|
|
-//
|
|
|
-// JSONObject js = HttpUtils.httpGet(url);
|
|
|
-// String errcode =js.getString("errcode");
|
|
|
-// if (errcode!=null) {
|
|
|
-// throw new BusinessException("获取AccessToken失败!");
|
|
|
-// }else {
|
|
|
-// LoggerUtils.debug(AsyncUtils.class,"获取并存入AccessToken成功,accesstoken="+js.getString("access_token"));
|
|
|
-// }
|
|
|
-// String access_token = js.getString("access_token");
|
|
|
-// Long expires_in = js.getLong("expires_in");
|
|
|
-// //返回时间为秒需要计算换成毫秒
|
|
|
-// expires_in=expires_in*1000;
|
|
|
-// expires_in+=date.getTime();
|
|
|
-// if (type==0){
|
|
|
-// redisUtil.setString("access_token", access_token);
|
|
|
-// redisUtil.setString("expires_in", expires_in.toString());
|
|
|
-// }else if (type==1){
|
|
|
-// redisUtil.setString("expense_access_token", access_token);
|
|
|
-// redisUtil.setString("expense_expires_in", expires_in.toString());
|
|
|
-// }
|
|
|
-//
|
|
|
-// return access_token;
|
|
|
-// }
|
|
|
-//
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 公出订阅消息组装
|
|
|
+ * @param dateTime 时间
|
|
|
+ * @param remarks 备注
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, Object> getPublicData(String dateTime, String remarks) {
|
|
|
+ Map<String, Object> we=new HashMap<String, Object>();
|
|
|
+ if (remarks.length()>20)remarks=remarks.substring(0,17)+"...";
|
|
|
+ Map<String, Object> v1=new HashMap<String, Object>();
|
|
|
+ v1.put("value",dateTime);
|
|
|
+ we.put("time15", v1);
|
|
|
+ Map<String, Object> v2=new HashMap<String, Object>();
|
|
|
+ v2.put("value", remarks);
|
|
|
+ we.put("thing13", v2);
|
|
|
+ return we;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|