diff --git a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/AgentSetter.java b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/AgentSetter.java index 7cda030d..891a7bac 100644 --- a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/AgentSetter.java +++ b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/AgentSetter.java @@ -27,7 +27,7 @@ public class AgentSetter implements Serializable { * 企业应用是否打开地理位置上报 */ @JSONField(name = "report_location_flag") - private String reportLocationType; + private ReportLocationType reportLocationType; /** * 企业应用头像的mediaid,通过多媒体接口上传图片获得mediaid,上传后会自动裁剪成方形和圆形两个头像 */ @@ -50,12 +50,12 @@ public class AgentSetter implements Serializable { * 是否接收用户变更通知。0:不接收;1:接收 */ @JSONField(name = "isreportuser") - private int isReportUser; + private boolean isReportUser; /** * 是否上报用户进入应用事件。0:不接收;1:接收 */ @JSONField(name = "isreportenter") - private int isReportEnter; + private boolean isReportEnter; public AgentSetter(int agentId) { this.agentId = agentId; @@ -65,82 +65,64 @@ public class AgentSetter implements Serializable { return agentId; } - public String getReportLocationType() { + public ReportLocationType getReportLocationType() { return reportLocationType; } - @JSONField(serialize = false) - public ReportLocationType getFormatReportLocationType() { - return reportLocationType != null ? ReportLocationType - .valueOf(reportLocationType.toUpperCase()) : null; - } - - public void setReportLocationType(ReportLocationType reportLocationType) { - this.reportLocationType = reportLocationType.name(); - } - public String getLogoMediaId() { return logoMediaId; } - public void setLogoMediaid(String logoMediaId) { - this.logoMediaId = logoMediaId; - } - public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - public String getDescription() { return description; } - public void setDescription(String description) { - this.description = description; - } - public String getRedirectDomain() { return redirectDomain; } + // ---------- setter 应该全部去掉 + + public void setReportLocationType(ReportLocationType reportLocationType) { + this.reportLocationType = reportLocationType; + } + + public void setLogoMediaid(String logoMediaId) { + this.logoMediaId = logoMediaId; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + public void setRedirectDomain(String redirectDomain) { this.redirectDomain = redirectDomain; } - public boolean getIsReportUser() { - return isReportUser == 1; - } - - public void setIsReportUser(boolean isReportUser) { - this.isReportUser = isReportUser ? 1 : 0; - } - - public boolean getIsReportEnter() { - return isReportEnter == 1; - } - - public void setIsReportEnter(boolean isReportEnter) { - this.isReportEnter = isReportEnter ? 1 : 0; - } - - // ---------- setter 应该全部去掉 - public void setAgentId(int agentId) { this.agentId = agentId; } - public void setReportLocationType(String reportLocationType) { - this.reportLocationType = reportLocationType; - } - public void setLogoMediaId(String logoMediaId) { this.logoMediaId = logoMediaId; } + public void setReportUser(boolean isReportUser) { + this.isReportUser = isReportUser; + } + + public void setReportEnter(boolean isReportEnter) { + this.isReportEnter = isReportEnter; + } + @Override public String toString() { return "agentId=" + agentId + ", reportLocationType=" diff --git a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Callback.java b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Callback.java index f2205028..983b2541 100644 --- a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Callback.java +++ b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Callback.java @@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.qy.model; import java.io.Serializable; +import com.alibaba.fastjson.annotation.JSONCreator; import com.alibaba.fastjson.annotation.JSONField; /** @@ -14,9 +15,9 @@ import com.alibaba.fastjson.annotation.JSONField; * @see */ public class Callback implements Serializable { - + private static final long serialVersionUID = 8575808461248605317L; - + /** * 企业应用接收企业号推送请求的访问协议和地址,支持http或https协议 */ @@ -31,7 +32,10 @@ public class Callback implements Serializable { @JSONField(name = "encodingaeskey") private String aesKey; - public Callback(String url, String token, String aesKey) { + @JSONCreator + public Callback(@JSONField(name = "url") String url, + @JSONField(name = "token") String token, + @JSONField(name = "aesKey") String aesKey) { this.url = url; this.token = token; this.aesKey = aesKey; diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/socket/WeixinRequestHandler.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/socket/WeixinRequestHandler.java index 4c6485fe..084c07db 100644 --- a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/socket/WeixinRequestHandler.java +++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/socket/WeixinRequestHandler.java @@ -1,5 +1,6 @@ package com.foxinmy.weixin4j.socket; +import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; import static io.netty.handler.codec.http.HttpResponseStatus.METHOD_NOT_ALLOWED; import io.netty.channel.ChannelFutureListener; @@ -55,6 +56,11 @@ public class WeixinRequestHandler extends protected void channelRead0(ChannelHandlerContext ctx, WeixinRequest request) throws WeixinException { final AesToken aesToken = request.getAesToken(); + if (aesToken == null) { + ctx.writeAndFlush(HttpUtil.createHttpResponse(BAD_REQUEST)) + .addListener(ChannelFutureListener.CLOSE); + return; + } if (request.getMethod().equals(HttpMethod.GET.name())) { if (MessageUtil.signature(aesToken.getToken(), request.getTimeStamp(), request.getNonce()).equals( @@ -62,8 +68,7 @@ public class WeixinRequestHandler extends ctx.write(new SingleResponse(request.getEchoStr())); return; } - ctx.writeAndFlush( - HttpUtil.createHttpResponse(FORBIDDEN)) + ctx.writeAndFlush(HttpUtil.createHttpResponse(FORBIDDEN)) .addListener(ChannelFutureListener.CLOSE); return; } else if (request.getMethod().equals(HttpMethod.POST.name())) { @@ -71,8 +76,7 @@ public class WeixinRequestHandler extends && !MessageUtil.signature(aesToken.getToken(), request.getTimeStamp(), request.getNonce()).equals( request.getSignature())) { - ctx.writeAndFlush( - HttpUtil.createHttpResponse(FORBIDDEN)) + ctx.writeAndFlush(HttpUtil.createHttpResponse(FORBIDDEN)) .addListener(ChannelFutureListener.CLOSE); return; } @@ -81,15 +85,13 @@ public class WeixinRequestHandler extends request.getTimeStamp(), request.getNonce(), request.getEncryptContent()).equals( request.getMsgSignature())) { - ctx.writeAndFlush( - HttpUtil.createHttpResponse(FORBIDDEN)) + ctx.writeAndFlush(HttpUtil.createHttpResponse(FORBIDDEN)) .addListener(ChannelFutureListener.CLOSE); return; } } } else { - ctx.writeAndFlush( - HttpUtil.createHttpResponse(METHOD_NOT_ALLOWED)) + ctx.writeAndFlush(HttpUtil.createHttpResponse(METHOD_NOT_ALLOWED)) .addListener(ChannelFutureListener.CLOSE); return; }