|
@@ -8,6 +8,7 @@ import com.comtika.safe.common.utils.StringUtil;
|
|
|
import com.comtika.safe.common.utils.http.HttpUtil;
|
|
|
import com.comtika.safe.config.WeChatProperties;
|
|
|
import com.comtika.safe.entity.warn.help.WarnMessageHelp;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
@@ -20,6 +21,7 @@ import java.util.List;
|
|
|
* @DESC: todo 这个是发送消息方法,后期需要处理
|
|
|
**/
|
|
|
@Component
|
|
|
+@Log4j2
|
|
|
public class WxChatUtil {
|
|
|
@Autowired
|
|
|
private WeChatProperties weChatProperties;
|
|
@@ -28,12 +30,17 @@ public class WxChatUtil {
|
|
|
private static final String WX_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
|
|
|
// 发生公众号消息方法
|
|
|
public JSONObject sendTemplateMsg(String accessToken, String json) {
|
|
|
+ if(StringUtil.isEmpty(accessToken)) {
|
|
|
+ log.error("token 为空~~");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
String requestUrl = AC_PUSH_URL.replace(TOKEN_KEY, accessToken);
|
|
|
return JSONObject.parseObject(HttpUtil.doPost(requestUrl, json));
|
|
|
}
|
|
|
private static boolean isText = false;
|
|
|
|
|
|
|
|
|
+
|
|
|
// 获取程序的openid
|
|
|
public JSONObject findWeChatAuth2Data(String code, boolean isSmall) {
|
|
|
String url = null;
|
|
@@ -81,7 +88,7 @@ public class WxChatUtil {
|
|
|
token = getTocken(false);
|
|
|
// 下面发生消息
|
|
|
JSONObject jsonObject = sendTemplateMsg(token, json);
|
|
|
- System.out.println("发生结果为:" + jsonObject.toJSONString());
|
|
|
+ log.info("发生结果为:{}" , jsonObject.toJSONString());
|
|
|
return RespWrapper.makeSuccessResp(true);
|
|
|
}
|
|
|
public RespWrapper<Boolean> sendMessageToVisit(boolean isSuccess,String remark,String acOpenId,String token){
|
|
@@ -94,7 +101,7 @@ public class WxChatUtil {
|
|
|
token = getTocken(false);
|
|
|
// 下面发生消息
|
|
|
JSONObject jsonObject = sendTemplateMsg(token, json);
|
|
|
- System.out.println("发生结果为:" + jsonObject.toJSONString());
|
|
|
+ log.info("发生结果为:{}" , jsonObject.toJSONString());
|
|
|
return RespWrapper.makeSuccessResp(true);
|
|
|
}
|
|
|
public RespWrapper<Boolean> sendWarnMessageToUser(WarnMessageHelp help, List<String> acOpenIdList, String token){
|
|
@@ -107,6 +114,10 @@ public class WxChatUtil {
|
|
|
for(String acOpenId:acOpenIdList){
|
|
|
if(!isText){
|
|
|
token = getTocken(false);
|
|
|
+ if(StringUtil.isEmpty(token)){
|
|
|
+ log.error("获取token 失败,检查公众号是否配置");
|
|
|
+ return RespWrapper.makeFailResp("获取token 失败,检查公众号是否配置");
|
|
|
+ }
|
|
|
}
|
|
|
//回调地址
|
|
|
String json = MessageDataHandle.toJsonPN(false,null, acOpenId, AcTemplateMessage.WARN.templateId, vm.getData());
|