Skip to content

Commit 6643498

Browse files
committed
code clean up for common module
1 parent baf99d6 commit 6643498

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+963
-984
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class WxConsts {
1919
public static final String XML_MSG_LINK = "link";
2020
public static final String XML_MSG_EVENT = "event";
2121
public static final String XML_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
22-
22+
2323
///////////////////////
2424
// 主动发送消息(即客服消息)的消息类型
2525
///////////////////////
@@ -33,7 +33,7 @@ public class WxConsts {
3333
public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
3434
public static final String CUSTOM_MSG_SAFE_NO = "0";
3535
public static final String CUSTOM_MSG_SAFE_YES = "1";
36-
36+
3737
///////////////////////
3838
// 群发消息的消息类型
3939
///////////////////////
@@ -42,7 +42,7 @@ public class WxConsts {
4242
public static final String MASS_MSG_VOICE = "voice";
4343
public static final String MASS_MSG_IMAGE = "image";
4444
public static final String MASS_MSG_VIDEO = "mpvideo";
45-
45+
4646
///////////////////////
4747
// 群发消息后微信端推送给服务器的反馈消息
4848
///////////////////////
@@ -57,25 +57,11 @@ public class WxConsts {
5757
public static final String MASS_ST_涉嫌版权 = "err(20013)";
5858
public static final String MASS_ST_涉嫌互推_互相宣传 = "err(22000)";
5959
public static final String MASS_ST_涉嫌其他 = "err(21000)";
60-
60+
6161
/**
6262
* 群发反馈消息代码所对应的文字描述
6363
*/
6464
public static final Map<String, String> MASS_ST_2_DESC = new HashMap<String, String>();
65-
static {
66-
MASS_ST_2_DESC.put(MASS_ST_SUCCESS, "发送成功");
67-
MASS_ST_2_DESC.put(MASS_ST_FAIL, "发送失败");
68-
MASS_ST_2_DESC.put(MASS_ST_涉嫌广告, "涉嫌广告");
69-
MASS_ST_2_DESC.put(MASS_ST_涉嫌政治, "涉嫌政治");
70-
MASS_ST_2_DESC.put(MASS_ST_涉嫌社会, "涉嫌社会");
71-
MASS_ST_2_DESC.put(MASS_ST_涉嫌色情, "涉嫌色情");
72-
MASS_ST_2_DESC.put(MASS_ST_涉嫌违法犯罪, "涉嫌违法犯罪");
73-
MASS_ST_2_DESC.put(MASS_ST_涉嫌欺诈, "涉嫌欺诈");
74-
MASS_ST_2_DESC.put(MASS_ST_涉嫌版权, "涉嫌版权");
75-
MASS_ST_2_DESC.put(MASS_ST_涉嫌互推_互相宣传, "涉嫌互推_互相宣传");
76-
MASS_ST_2_DESC.put(MASS_ST_涉嫌其他, "涉嫌其他");
77-
}
78-
7965
///////////////////////
8066
// 微信端推送过来的事件类型
8167
///////////////////////
@@ -103,11 +89,9 @@ public class WxConsts {
10389
public static final String EVT_USER_VIEW_CARD = "user_view_card";
10490
public static final String EVT_USER_ENTER_SESSION_FROM_CARD = "user_enter_session_from_card";
10591
public static final String EVT_CARD_SKU_REMIND = "card_sku_remind"; // 库存报警
106-
10792
public static final String EVT_KF_CREATE_SESSION = "kf_create_session"; // 客服接入会话
10893
public static final String EVT_KF_CLOSE_SESSION = "kf_close_session"; // 客服关闭会话
10994
public static final String EVT_KF_SWITCH_SESSION = "kf_switch_session"; // 客服转接会话
110-
11195
///////////////////////
11296
// 上传多媒体文件的类型
11397
///////////////////////
@@ -116,53 +100,89 @@ public class WxConsts {
116100
public static final String MEDIA_VIDEO = "video";
117101
public static final String MEDIA_THUMB = "thumb";
118102
public static final String MEDIA_FILE = "file";
119-
120103
///////////////////////
121104
// 文件类型
122105
///////////////////////
123106
public static final String FILE_JPG = "jpeg";
124107
public static final String FILE_MP3 = "mp3";
125108
public static final String FILE_AMR = "amr";
126109
public static final String FILE_MP4 = "mp4";
110+
/**
111+
* 点击推事件
112+
*/
113+
public static final String BUTTON_CLICK = "click";
127114

128115

129116
///////////////////////
130117
// 自定义菜单的按钮类型
131118
///////////////////////
132-
/** 点击推事件 */
133-
public static final String BUTTON_CLICK = "click";
134-
/** 跳转URL */
119+
/**
120+
* 跳转URL
121+
*/
135122
public static final String BUTTON_VIEW = "view";
136-
/** 扫码推事件 */
123+
/**
124+
* 扫码推事件
125+
*/
137126
public static final String BUTTON_SCANCODE_PUSH = "scancode_push";
138-
/** 扫码推事件且弹出“消息接收中”提示框 */
127+
/**
128+
* 扫码推事件且弹出“消息接收中”提示框
129+
*/
139130
public static final String BUTTON_SCANCODE_WAITMSG = "scancode_waitmsg";
140-
/** 弹出系统拍照发图 */
131+
/**
132+
* 弹出系统拍照发图
133+
*/
141134
public static final String BUTTON_PIC_SYSPHOTO = "pic_sysphoto";
142-
/** 弹出拍照或者相册发图 */
135+
/**
136+
* 弹出拍照或者相册发图
137+
*/
143138
public static final String BUTTON_PIC_PHOTO_OR_ALBUM = "pic_photo_or_album";
144-
/** 弹出微信相册发图器 */
139+
/**
140+
* 弹出微信相册发图器
141+
*/
145142
public static final String BUTTON_PIC_WEIXIN = "pic_weixin";
146-
/** 弹出地理位置选择器 */
143+
/**
144+
* 弹出地理位置选择器
145+
*/
147146
public static final String BUTTON_LOCATION_SELECT = "location_select";
148-
/** 下发消息(除文本消息) */
147+
/**
148+
* 下发消息(除文本消息)
149+
*/
149150
public static final String BUTTON_MEDIA_ID = "media_id";
150-
/** 跳转图文消息URL */
151+
/**
152+
* 跳转图文消息URL
153+
*/
151154
public static final String BUTTON_VIEW_LIMITED = "view_limited";
155+
/**
156+
* 不弹出授权页面,直接跳转,只能获取用户openid
157+
*/
158+
public static final String OAUTH2_SCOPE_BASE = "snsapi_base";
152159

153160
///////////////////////
154161
// oauth2网页授权的scope
155162
///////////////////////
156-
/** 不弹出授权页面,直接跳转,只能获取用户openid */
157-
public static final String OAUTH2_SCOPE_BASE = "snsapi_base";
158-
/** 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息 */
163+
/**
164+
* 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息
165+
*/
159166
public static final String OAUTH2_SCOPE_USER_INFO = "snsapi_userinfo";
160-
161167
///////////////////////
162168
// 永久素材类型
163169
///////////////////////
164170
public static final String MATERIAL_NEWS = "news";
165171
public static final String MATERIAL_VOICE = "voice";
166172
public static final String MATERIAL_IMAGE = "image";
167173
public static final String MATERIAL_VIDEO = "video";
174+
175+
static {
176+
MASS_ST_2_DESC.put(MASS_ST_SUCCESS, "发送成功");
177+
MASS_ST_2_DESC.put(MASS_ST_FAIL, "发送失败");
178+
MASS_ST_2_DESC.put(MASS_ST_涉嫌广告, "涉嫌广告");
179+
MASS_ST_2_DESC.put(MASS_ST_涉嫌政治, "涉嫌政治");
180+
MASS_ST_2_DESC.put(MASS_ST_涉嫌社会, "涉嫌社会");
181+
MASS_ST_2_DESC.put(MASS_ST_涉嫌色情, "涉嫌色情");
182+
MASS_ST_2_DESC.put(MASS_ST_涉嫌违法犯罪, "涉嫌违法犯罪");
183+
MASS_ST_2_DESC.put(MASS_ST_涉嫌欺诈, "涉嫌欺诈");
184+
MASS_ST_2_DESC.put(MASS_ST_涉嫌版权, "涉嫌版权");
185+
MASS_ST_2_DESC.put(MASS_ST_涉嫌互推_互相宣传, "涉嫌互推_互相宣传");
186+
MASS_ST_2_DESC.put(MASS_ST_涉嫌其他, "涉嫌其他");
187+
}
168188
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageDuplicateChecker.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ public interface WxMessageDuplicateChecker {
1010

1111
/**
1212
* <h2>公众号的排重方式</h2>
13-
*
13+
* <p>
1414
* <p>普通消息:关于重试的消息排重,推荐使用msgid排重。<a href="http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html">文档参考</a>。</p>
1515
* <p>事件消息:关于重试的消息排重,推荐使用FromUserName + CreateTime 排重。<a href="http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html">文档参考</a></p>
16-
*
16+
* <p>
1717
* <h2>企业号的排重方式</h2>
18-
*
18+
* <p>
1919
* 官方文档完全没有写,参照公众号的方式排重。
20-
*
20+
* <p>
2121
* <p>或者可以采取更简单的方式,如果有MsgId就用MsgId排重,如果没有就用FromUserName+CreateTime排重</p>
22+
*
2223
* @param messageId messageId需要根据上面讲的方式构造
2324
* @return 如果是重复消息,返回true,否则返回false
2425
*/

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public WxMessageInMemoryDuplicateChecker() {
4646

4747
/**
4848
* WxMsgIdInMemoryDuplicateChecker构造函数
49-
* @param timeToLive 一个消息ID在内存的过期时间:毫秒
49+
*
50+
* @param timeToLive 一个消息ID在内存的过期时间:毫秒
5051
* @param clearPeriod 每隔多少周期检查消息ID是否过期:毫秒
5152
*/
5253
public WxMessageInMemoryDuplicateChecker(Long timeToLive, Long clearPeriod) {

weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ public class WxAccessToken implements Serializable {
88
private static final long serialVersionUID = 8709719312922168909L;
99

1010
private String accessToken;
11-
11+
1212
private int expiresIn = -1;
1313

14+
public static WxAccessToken fromJson(String json) {
15+
return WxGsonBuilder.create().fromJson(json, WxAccessToken.class);
16+
}
17+
1418
public String getAccessToken() {
1519
return accessToken;
1620
}
@@ -27,8 +31,4 @@ public void setExpiresIn(int expiresIn) {
2731
this.expiresIn = expiresIn;
2832
}
2933

30-
public static WxAccessToken fromJson(String json) {
31-
return WxGsonBuilder.create().fromJson(json, WxAccessToken.class);
32-
}
33-
3434
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class WxJsapiSignature implements Serializable {
99
private static final long serialVersionUID = -1116808193154384804L;
1010

1111
private String appid;
12-
12+
1313
private String noncestr;
1414

1515
private long timestamp;
@@ -51,11 +51,11 @@ public void setUrl(String url) {
5151
}
5252

5353
public String getAppid() {
54-
return appid;
54+
return appid;
5555
}
5656

5757
public void setAppid(String appid) {
58-
this.appid = appid;
58+
this.appid = appid;
5959
}
6060

6161
}

0 commit comments

Comments
 (0)