Commit 314e480a authored by tianbo's avatar tianbo

特种设备公众号添加测试接口

parent 8cae9bbf
...@@ -42,4 +42,17 @@ public interface IWechatService { ...@@ -42,4 +42,17 @@ public interface IWechatService {
*/ */
String getWechatPicByMediaId(String mediaId); String getWechatPicByMediaId(String mediaId);
/**
* 发送测试公众号督查整改模板消息
*
* @return
*/
Boolean sendTestTemplateMsgSupervise();
/**
* 发送测试公众号预警模板消息
*
* @return
*/
Boolean sendTestTemplateMsgWarning();
} }
...@@ -41,6 +41,7 @@ import org.slf4j.Logger; ...@@ -41,6 +41,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -339,8 +340,6 @@ public class WechatController extends BaseController { ...@@ -339,8 +340,6 @@ public class WechatController extends BaseController {
return ResponseHelper.buildResponse(dto); return ResponseHelper.buildResponse(dto);
} }
public String login(String tel) { public String login(String tel) {
String token = ""; String token = "";
IdPasswordAuthModel loninData = new IdPasswordAuthModel(); IdPasswordAuthModel loninData = new IdPasswordAuthModel();
...@@ -356,7 +355,6 @@ public class WechatController extends BaseController { ...@@ -356,7 +355,6 @@ public class WechatController extends BaseController {
return token; return token;
} }
/** /**
* 根据微信code获取openId和手机号接口 * 根据微信code获取openId和手机号接口
* *
...@@ -378,7 +376,7 @@ public class WechatController extends BaseController { ...@@ -378,7 +376,7 @@ public class WechatController extends BaseController {
WechatRelation temp = wechatRelationServiceImpl.getOne(new LambdaQueryWrapper<WechatRelation>().eq(WechatRelation::getOpenId,openId)); WechatRelation temp = wechatRelationServiceImpl.getOne(new LambdaQueryWrapper<WechatRelation>().eq(WechatRelation::getOpenId,openId));
if(temp != null ) { if(temp != null ) {
wechatAccessDto.setTel(temp.getPhone()); wechatAccessDto.setTel(temp.getPhone());
if(redisUtils.hasKey(temp.getPhone() + "_token")) { if(redisUtils.hasKey(temp.getPhone() + "_token") && redisUtils.getExpire(temp.getPhone() + "_token") > 1) {
wechatAccessDto.setToken(redisUtils.get(temp.getPhone() + "_token").toString()); wechatAccessDto.setToken(redisUtils.get(temp.getPhone() + "_token").toString());
} else { } else {
wechatAccessDto.setToken(this.login(temp.getPhone())); wechatAccessDto.setToken(this.login(temp.getPhone()));
...@@ -662,4 +660,19 @@ public class WechatController extends BaseController { ...@@ -662,4 +660,19 @@ public class WechatController extends BaseController {
String url = HttpUtils.doPostWithFile(getPicUrl,file,"media",accessToken,"image"); String url = HttpUtils.doPostWithFile(getPicUrl,file,"media",accessToken,"image");
return ResponseHelper.buildResponse(url); return ResponseHelper.buildResponse(url);
} }
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@GetMapping(value = "/test/templateMsg/warning")
@ApiOperation(httpMethod = "GET", value = "测试发送公众号预警消息", notes = "测试发送公众号预警消息")
public ResponseModel testSendTemplateMsgWarning() {
return ResponseHelper.buildResponse(wechatService.sendTestTemplateMsgWarning());
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@GetMapping(value = "/test/templateMsg/supervise")
@ApiOperation(httpMethod = "GET", value = "测试发送公众号督查整改消息", notes = "测试发送公众号督查整改消息")
public ResponseModel testSendTemplateMsgSupervise() {
return ResponseHelper.buildResponse(wechatService.sendTestTemplateMsgSupervise());
}
} }
package com.yeejoin.amos.boot.module.tzs.biz.service.impl; package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMessageDto; import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMessageDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.WechatRelation;
import com.yeejoin.amos.boot.module.tzs.api.service.IWechatService; import com.yeejoin.amos.boot.module.tzs.api.service.IWechatService;
import com.yeejoin.amos.boot.module.tzs.biz.utils.HttpUtils; import com.yeejoin.amos.boot.module.tzs.biz.utils.HttpUtils;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
...@@ -15,7 +20,10 @@ import org.springframework.stereotype.Service; ...@@ -15,7 +20,10 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -41,6 +49,15 @@ public class WechatServiceImpl implements IWechatService { ...@@ -41,6 +49,15 @@ public class WechatServiceImpl implements IWechatService {
@Value("${tzs.wechat.url}") @Value("${tzs.wechat.url}")
private String wechatUrl; private String wechatUrl;
@Autowired
WechatRelationServiceImpl wechatRelationService;
@Value("${tzs.wechat.tempId.warning}")
private String templateId_Warning;
@Value("${tzs.wechat.tempId.supervise}")
private String templateId_Supervise;
@Value("${tzs.wechat.test.userId}")
private String testUserId;
@Override @Override
public String getAccessToken() { public String getAccessToken() {
if(redisUtils.hasKey(RedisKey.WECHAT_TOKEN)){ if(redisUtils.hasKey(RedisKey.WECHAT_TOKEN)){
...@@ -118,15 +135,13 @@ public class WechatServiceImpl implements IWechatService { ...@@ -118,15 +135,13 @@ public class WechatServiceImpl implements IWechatService {
} }
} }
@Override @Override
public JSONObject sendWechatModelMessage(String openId, WechatMessageDto wechatMessageDto) { public JSONObject sendWechatModelMessage(String openId, WechatMessageDto wechatMessageDto) {
String accessToken = this.getAccessToken(); String accessToken = this.getAccessToken();
String modelMessageUrl = wechatUrl + "/cgi-bin/message/template/send?access_token=" + accessToken; String modelMessageUrl = wechatUrl + "/cgi-bin/message/template/send?access_token=" + accessToken;
JSONObject messageBody = new JSONObject(); JSONObject messageBody = new JSONObject();
messageBody.put("touser",openId); messageBody.put("touser", openId);
messageBody.put("template_id",wechatMessageDto.getTemplateId()); messageBody.put("template_id", wechatMessageDto.getTemplateId());
if(wechatMessageDto.getUrl() != null) { if(wechatMessageDto.getUrl() != null) {
messageBody.put("url",wechatMessageDto.getUrl()); messageBody.put("url",wechatMessageDto.getUrl());
} }
...@@ -172,5 +187,52 @@ public class WechatServiceImpl implements IWechatService { ...@@ -172,5 +187,52 @@ public class WechatServiceImpl implements IWechatService {
return urlString; return urlString;
} }
@Override
public Boolean sendTestTemplateMsgWarning() {
List<WechatRelation> wechatRelationList =
wechatRelationService.list(new LambdaQueryWrapper<WechatRelation>().in(WechatRelation::getUserId,
Arrays.asList(testUserId.split(","))));
wechatRelationList.forEach(i -> {
WechatMessageDto wechatMessageDto1 = new WechatMessageDto();
wechatMessageDto1.setTemplateId(templateId_Warning);
Map<String, String> data1 = Maps.newHashMap();
data1.put("first", "【陕西省特种设备安全监察局】监督检查提醒");
data1.put("keyword1", "西安市碑林区市场监督管理局,系统发现您辖区内西安荣昌电梯有限公司2022年1月份应急救援时间合规率为66.96%,低于基准线90%,已自动为您制定监督检查任务,请按照要求进行监督检查后在系统进行信息登记。");
data1.put("keyword2", DateUtils.date2LongStr(new Date()));
wechatMessageDto1.setData(data1);
sendWechatModelMessage(i.getOpenId(), wechatMessageDto1);
WechatMessageDto wechatMessageDto2 = new WechatMessageDto();
wechatMessageDto2.setTemplateId(templateId_Warning);
Map<String, String> data2 = Maps.newHashMap();
data2.put("first", "【陕西省特种设备安全监察局】监督检查提醒");
data2.put("keyword1", "西安荣昌电梯有限公司,系统发现贵公司2022年1月份应急救援时间合规度为66.96%,低于基准线90%,西安市碑林区市场监督管理局将于近期进行监督检查,请做好准备。");
data2.put("keyword2", DateUtils.date2LongStr(new Date()));
wechatMessageDto2.setData(data2);
sendWechatModelMessage(i.getOpenId(), wechatMessageDto2);
});
return true;
}
@Override
public Boolean sendTestTemplateMsgSupervise() {
List<WechatRelation> wechatRelationList =
wechatRelationService.list(new LambdaQueryWrapper<WechatRelation>().in(WechatRelation::getUserId,
Arrays.asList(testUserId.split(","))));
wechatRelationList.forEach(i -> {
WechatMessageDto wechatMessageDto = new WechatMessageDto();
wechatMessageDto.setTemplateId(templateId_Supervise);
Map<String, String> data = Maps.newHashMap();
data.put("first", "【陕西省特种设备安全监察局】西安荣昌电梯有限公司,经西安市碑林区市场监督管理局监督检查,发现以下问题,请安排人员落实整改。");
data.put("keyword1", "西安荣昌电梯有限公司");
data.put("keyword2", "监管问题:2022年1月份应急救援时间合规度为66.96%,低于基准线90%;现场监督检查发现:没有建立事故应急措施和救援预案,无演练记录。");
data.put("keyword3", DateUtils.date2LongStr(new Date()));
data.put("keyword4", "李静");
wechatMessageDto.setData(data);
sendWechatModelMessage(i.getOpenId(), wechatMessageDto);
});
return true;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment