|
|
@ -1,6 +1,5 @@ |
|
|
|
package com.supervise.rms.biz.wechat; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.supervise.rms.api.businessriskdate.BusinessRiskDate; |
|
|
|
import com.supervise.rms.api.pusinformation.PushInformation; |
|
|
@ -12,10 +11,7 @@ import io.swagger.annotations.Api; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
@ -44,9 +40,9 @@ public class WechatRest { |
|
|
|
private String WX_URL_MESSAGE_SEND; |
|
|
|
|
|
|
|
//0 30 9 ? * 2 每周一九点半
|
|
|
|
@PostMapping("/sendMessage") |
|
|
|
public void sendMessage(@RequestBody WeChatTemplateMsg data) throws Exception { |
|
|
|
String t = "imkugi6AM3SgT-GUciOMlkhPQUbfAiooDWxslzgO4Lc"; |
|
|
|
@GetMapping("/sendMessage") |
|
|
|
public void sendMessage() throws Exception { |
|
|
|
String t = "A_fAuJa6edQ-IK4hBRMqDw0OZAQY7DHay87ZOKspneE"; |
|
|
|
String accessToken = getAccessToken(appId,sppSecret); |
|
|
|
String wxUrl = WX_URL_MESSAGE_SEND.replace("ACCESS_TOKEN", accessToken); |
|
|
|
//查询库中openId
|
|
|
@ -54,9 +50,9 @@ public class WechatRest { |
|
|
|
for (PushInformation pushInformation : pushInformations) { |
|
|
|
//查询库中查询到所有企业的信息
|
|
|
|
List<BusinessRiskDate> businessRiskDate = businessRiskDateService.selectBusinessRiskDateByName(pushInformation.getEnterpriseName()); |
|
|
|
BusinessRiskDate riskDate = businessRiskDate.get(0); |
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
Map<String, Object> sendBody = new HashMap<>(); |
|
|
|
BusinessRiskDate riskDate = businessRiskDate.get(0); |
|
|
|
setTemplateStyle(riskDate,sendBody,t,wxUrl,pushInformation,restTemplate,riskDate.getVerifyResult(),businessRiskDate); |
|
|
|
} |
|
|
|
// String openId="o7sGD6r8GP3VEjA9iJz3us6Xg0aM";
|
|
|
@ -116,6 +112,11 @@ public class WechatRest { |
|
|
|
// //return forEntity.getBody();
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description //描述: 获取AccessToken
|
|
|
|
* @Param [appId, appsecret] |
|
|
|
* @return java.lang.String |
|
|
|
**/ |
|
|
|
public String getAccessToken(String appId,String appsecret){ |
|
|
|
String url = WX_URL_ACCESS_TOKEN.replace("APPID", appId).replace("APPSECRET", appsecret); |
|
|
|
RestTemplate restTemplate=new RestTemplate(); |
|
|
@ -125,17 +126,23 @@ public class WechatRest { |
|
|
|
return at; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description //描述: 企业经营异常推送
|
|
|
|
* @Param [riskDate, sendBody, t, wxUrl, pushInformation, restTemplate, verifyResult, businessRiskDate] |
|
|
|
* @return void |
|
|
|
**/ |
|
|
|
public void setTemplateStyle(BusinessRiskDate riskDate, Map<String, Object> sendBody,String t,String wxUrl,PushInformation pushInformation,RestTemplate restTemplate,String verifyResult,List<BusinessRiskDate> businessRiskDate){ |
|
|
|
Map<String, Object> sendMag = new HashMap<>(); |
|
|
|
sendMag.put("thing2", new TemplateData(riskDate.getBusinessName())); |
|
|
|
sendMag.put("thing7", new TemplateData(riskDate.getBusinessName())); |
|
|
|
List<BusinessRiskDate> businessRiskDates = businessRiskDateService.selectBusinessRiskDateSize(riskDate.getBusinessName(), riskDate.getExecutionTime()); |
|
|
|
if (verifyResult.equals("0")){ |
|
|
|
sendMag.put("thing5", new TemplateData("该公司暂无风险")); |
|
|
|
}else { |
|
|
|
sendMag.put("thing5", new TemplateData("该企业有"+businessRiskDate.size()+"条风险")); |
|
|
|
sendMag.put("thing5", new TemplateData("该企业有"+businessRiskDates.size()+"条风险")); |
|
|
|
} |
|
|
|
sendMag.put("time6", new TemplateData(riskDate.getExecutionTime())); |
|
|
|
sendMag.put("time8", new TemplateData(riskDate.getExecutionTime())); |
|
|
|
Map<String, String> miniprogram = new HashMap<>(); |
|
|
|
miniprogram.put("appid","wx11565021714ba796"); |
|
|
|
miniprogram.put("appid","wx05604ce2a8bede05"); |
|
|
|
miniprogram.put("pagepath","pages/index/enterpriseRisk?businessName="+riskDate.getBusinessName()+"&executionTime="+riskDate.getExecutionTime()); |
|
|
|
//拼接base参数
|
|
|
|
sendBody.put("miniprogram",miniprogram); |
|
|
@ -148,6 +155,8 @@ public class WechatRest { |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(forEntity.getBody()); |
|
|
|
String messageCode = jsonObject.getString("errcode"); |
|
|
|
String msgId = jsonObject.getString("msgid"); |
|
|
|
System.out.println("messageCode : " + messageCode + ", msgId: " +msgId); |
|
|
|
String msg = jsonObject.getString("errmsg"); |
|
|
|
System.out.println("messageCode : " + messageCode + ", msgId: " +msgId + ", msg: "+msg); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|