Skip to content

Commit

Permalink
修复checkstyle检查出来的部分代码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Nov 7, 2017
1 parent 97d6f90 commit 67abc92
Show file tree
Hide file tree
Showing 21 changed files with 217 additions and 138 deletions.
4 changes: 2 additions & 2 deletions quality-checks/google_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="LineLength">
<property name="max" value="100"/>
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="AvoidStarImport"/>
Expand All @@ -52,7 +52,7 @@
</module>
<module name="NeedBraces"/>
<module name="LeftCurly">
<property name="maxLineLength" value="100"/>
<property name="maxLineLength" value="120"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import java.util.Map;

/**
* 微信开发所使用到的常量类
* 微信开发所使用到的常量类.
*
* @author chanjarster & binarywang
*/
public class WxConsts {
/**
* 微信推送过来的消息的类型,和发送给微信xml格式消息的消息类型
* 微信推送过来的消息的类型,和发送给微信xml格式消息的消息类型.
*/
public static class XmlMsgType {
public static final String TEXT = "text";
Expand All @@ -31,32 +31,65 @@ public static class XmlMsgType {
}

/**
* 主动发送消息(即客服消息)的消息类型
* 主动发送消息(即客服消息)的消息类型.
*/
public static class KefuMsgType {
public static final String TEXT = "text";//文本消息
public static final String IMAGE = "image";//图片消息
public static final String VOICE = "voice";//语音消息
public static final String VIDEO = "video";//视频消息
public static final String MUSIC = "music";//音乐消息
public static final String NEWS = "news";//图文消息(点击跳转到外链)
public static final String MPNEWS = "mpnews";//图文消息(点击跳转到图文消息页面)
public static final String FILE = "file";//发送文件(CP专用)
public static final String TEXTCARD = "textcard";//文本卡片消息(CP专用)
public static final String WXCARD = "wxcard";//卡券消息
/**
* 文本消息.
*/
public static final String TEXT = "text";
/**
* 图片消息.
*/
public static final String IMAGE = "image";
/**
* 语音消息.
*/
public static final String VOICE = "voice";
/**
* 视频消息.
*/
public static final String VIDEO = "video";
/**
* 音乐消息.
*/
public static final String MUSIC = "music";
/**
* 图文消息(点击跳转到外链).
*/
public static final String NEWS = "news";
/**
* 图文消息(点击跳转到图文消息页面).
*/
public static final String MPNEWS = "mpnews";
/**
* 发送文件(CP专用).
*/
public static final String FILE = "file";
/**
* 文本卡片消息(CP专用).
*/
public static final String TEXTCARD = "textcard";
/**
* 卡券消息.
*/
public static final String WXCARD = "wxcard";
/**
* 转发到客服的消息.
*/
public static final String TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
}

/**
* 表示是否是保密消息,0表示否,1表示是,默认0
* 表示是否是保密消息,0表示否,1表示是,默认0.
*/
public static class KefuMsgSafe {
public static final String NO = "0";
public static final String YES = "1";
}

/**
* 群发消息的消息类型
* 群发消息的消息类型.
*/
public static class MassMsgType {
public static final String MPNEWS = "mpnews";
Expand All @@ -67,7 +100,7 @@ public static class MassMsgType {
}

/**
* 群发消息后微信端推送给服务器的反馈消息
* 群发消息后微信端推送给服务器的反馈消息.
*/
public static class MassMsgStatus {
public static final String SEND_SUCCESS = "send success";
Expand All @@ -83,7 +116,7 @@ public static class MassMsgStatus {
public static final String ERR_21000 = "err(21000)";

/**
* 群发反馈消息代码所对应的文字描述
* 群发反馈消息代码所对应的文字描述.
*/
public static final Map<String, String> STATUS_DESC = new HashMap<>();

Expand All @@ -103,7 +136,7 @@ public static class MassMsgStatus {
}

/**
* 微信端推送过来的事件类型
* 微信端推送过来的事件类型.
*/
public static class EventType {
public static final String SUBSCRIBE = "subscribe";
Expand All @@ -124,7 +157,7 @@ public static class EventType {
}

/**
* 上传多媒体(临时素材)文件的类型
* 上传多媒体(临时素材)文件的类型.
*/
public static class MediaFileType {
public static final String IMAGE = "image";
Expand All @@ -135,78 +168,78 @@ public static class MediaFileType {
}

/**
* 自定义菜单的按钮类型
* 自定义菜单的按钮类型.
*/
public static class MenuButtonType {
/**
* 点击推事件
* 点击推事件.
*/
public static final String CLICK = "click";
/**
* 跳转URL
* 跳转URL.
*/
public static final String VIEW = "view";
/**
* 跳转到小程序
* 跳转到小程序.
*/
public static final String MINIPROGRAM = "miniprogram";
/**
* 扫码推事件
* 扫码推事件.
*/
public static final String SCANCODE_PUSH = "scancode_push";
/**
* 扫码推事件且弹出“消息接收中”提示框
* 扫码推事件且弹出“消息接收中”提示框.
*/
public static final String SCANCODE_WAITMSG = "scancode_waitmsg";
/**
* 弹出系统拍照发图
* 弹出系统拍照发图.
*/
public static final String PIC_SYSPHOTO = "pic_sysphoto";
/**
* 弹出拍照或者相册发图
* 弹出拍照或者相册发图.
*/
public static final String PIC_PHOTO_OR_ALBUM = "pic_photo_or_album";
/**
* 弹出微信相册发图器
* 弹出微信相册发图器.
*/
public static final String PIC_WEIXIN = "pic_weixin";
/**
* 弹出地理位置选择器
* 弹出地理位置选择器.
*/
public static final String LOCATION_SELECT = "location_select";
/**
* 下发消息(除文本消息)
* 下发消息(除文本消息).
*/
public static final String MEDIA_ID = "media_id";
/**
* 跳转图文消息URL
* 跳转图文消息URL.
*/
public static final String VIEW_LIMITED = "view_limited";
}

/**
* oauth2网页授权的scope
* oauth2网页授权的scope.
*/
public static class OAuth2Scope {
/**
* 不弹出授权页面,直接跳转,只能获取用户openid
* 不弹出授权页面,直接跳转,只能获取用户openid.
*/
public static final String SNSAPI_BASE = "snsapi_base";
/**
* 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息
* 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息.
*/
public static final String SNSAPI_USERINFO = "snsapi_userinfo";
}

/**
* 网页应用登录授权作用域
* 网页应用登录授权作用域.
*/
public static class QrConnectScope {
public static final String SNSAPI_LOGIN = "snsapi_login";
}

/**
* 永久素材类型
* 永久素材类型.
*/
public static class MaterialType {
public static final String NEWS = "news";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import me.chanjar.weixin.common.exception.WxErrorException;

/**
* WxErrorException处理器
* WxErrorException处理器.
*/
public interface WxErrorExceptionHandler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

/**
* <pre>
* 消息重复检查器
* 消息重复检查器.
* 微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次
* </pre>
*/
public interface WxMessageDuplicateChecker {

/**
* 判断消息是否重复.
* <h2>公众号的排重方式</h2>
* <p>
*
* <p>普通消息:关于重试的消息排重,推荐使用msgid排重。<a href="http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html">文档参考</a>。</p>
* <p>事件消息:关于重试的消息排重,推荐使用FromUserName + CreateTime 排重。<a href="http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html">文档参考</a></p>
* <p>
*
* <h2>企业号的排重方式</h2>
* <p>
* 官方文档完全没有写,参照公众号的方式排重。
* <p>
* <p>官方文档完全没有写,参照公众号的方式排重。</p>
* <p>或者可以采取更简单的方式,如果有MsgId就用MsgId排重,如果没有就用FromUserName+CreateTime排重</p>
*
* @param messageId messageId需要根据上面讲的方式构造
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,46 @@

/**
* <pre>
* 默认消息重复检查器
* 默认消息重复检查器.
* 将每个消息id保存在内存里,每隔5秒清理已经过期的消息id,每个消息id的过期时间是15秒
* </pre>
*/
public class WxMessageInMemoryDuplicateChecker implements WxMessageDuplicateChecker {

/**
* 一个消息ID在内存的过期时间:15秒
* 一个消息ID在内存的过期时间:15秒.
*/
private final Long timeToLive;

/**
* 每隔多少周期检查消息ID是否过期:5秒
* 每隔多少周期检查消息ID是否过期:5秒.
*/
private final Long clearPeriod;

/**
* 消息id->消息时间戳的map
* 消息id->消息时间戳的map.
*/
private final ConcurrentHashMap<String, Long> msgId2Timestamp = new ConcurrentHashMap<>();

/**
* 后台清理线程是否已经开启
* 后台清理线程是否已经开启.
*/
private final AtomicBoolean backgroundProcessStarted = new AtomicBoolean(false);

/**
* WxMsgIdInMemoryDuplicateChecker构造函数
* 无参构造方法.
* <pre>
* 一个消息ID在内存的过期时间:15秒
* 每隔多少周期检查消息ID是否过期:5秒
* </pre>
*/
public WxMessageInMemoryDuplicateChecker() {
this.timeToLive = 15 * 1000l;
this.clearPeriod = 5 * 1000l;
this.timeToLive = 15 * 1000L;
this.clearPeriod = 5 * 1000L;
}

/**
* WxMsgIdInMemoryDuplicateChecker构造函数
* 构造方法.
*
* @param timeToLive 一个消息ID在内存的过期时间:毫秒
* @param clearPeriod 每隔多少周期检查消息ID是否过期:毫秒
Expand All @@ -66,7 +66,8 @@ public void run() {
while (true) {
Thread.sleep(WxMessageInMemoryDuplicateChecker.this.clearPeriod);
Long now = System.currentTimeMillis();
for (Map.Entry<String, Long> entry : WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet()) {
for (Map.Entry<String, Long> entry :
WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet()) {
if (now - entry.getValue() > WxMessageInMemoryDuplicateChecker.this.timeToLive) {
WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet().remove(entry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.List;

/**
* 菜单(公众号和企业号共用的)
* 菜单(公众号和企业号共用的).
*
* @author Daniel Qian
*/
Expand All @@ -36,7 +36,8 @@ public static WxMenu fromJson(String json) {
* 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
*/
public static WxMenu fromJson(InputStream is) {
return WxGsonBuilder.create().fromJson(new InputStreamReader(is, StandardCharsets.UTF_8), WxMenu.class);
return WxGsonBuilder.create()
.fromJson(new InputStreamReader(is, StandardCharsets.UTF_8), WxMenu.class);
}

public List<WxMenuButton> getButtons() {
Expand Down
Loading

0 comments on commit 67abc92

Please sign in to comment.