Skip to content

Commit 9f4a7a7

Browse files
committed
优化重构企业号相关代码,修复了升级企业微信后出现的菜单问题和用户管理的问题
1 parent 0f0f7bb commit 9f4a7a7

29 files changed

+1022
-513
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,14 @@ public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationCon
9090
* 操蛋的微信
9191
* 创建菜单时是 { button : ... }
9292
* 查询菜单时是 { menu : { button : ... } }
93+
* 现在企业号升级为企业微信后,没有此问题,因此需要单独处理
9394
*/
94-
WxMenu menu = new WxMenu();
9595
JsonArray buttonsJson = json.getAsJsonObject().get("menu").getAsJsonObject().get("button").getAsJsonArray();
96+
return this.buildMenuFromJson(buttonsJson);
97+
}
98+
99+
protected WxMenu buildMenuFromJson(JsonArray buttonsJson) {
100+
WxMenu menu = new WxMenu();
96101
for (int i = 0; i < buttonsJson.size(); i++) {
97102
JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
98103
WxMenuButton button = convertFromJson(buttonJson);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,57 @@
11
package me.chanjar.weixin.cp.api;
22

3+
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
4+
import me.chanjar.weixin.common.exception.WxErrorException;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
310
/**
411
* <pre>
12+
* 媒体管理接口
513
* Created by BinaryWang on 2017/6/24.
614
* </pre>
715
*
816
* @author <a href="https://github.com/binarywang">Binary Wang</a>
917
*/
1018
public interface WxCpMediaService {
19+
20+
/**
21+
* <pre>
22+
* 上传多媒体文件
23+
* 上传的多媒体文件有格式和大小限制,如下:
24+
* 图片(image): 1M,支持JPG格式
25+
* 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
26+
* 视频(video):10MB,支持MP4格式
27+
* 缩略图(thumb):64KB,支持JPG格式
28+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
29+
* </pre>
30+
*
31+
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
32+
* @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts}
33+
* @param inputStream 输入流
34+
*/
35+
WxMediaUploadResult upload(String mediaType, String fileType, InputStream inputStream)
36+
throws WxErrorException, IOException;
37+
38+
/**
39+
* @param mediaType 媒体类型
40+
* @param file 文件对象
41+
* @see #upload(String, String, InputStream)
42+
*/
43+
WxMediaUploadResult upload(String mediaType, File file) throws WxErrorException;
44+
45+
/**
46+
* <pre>
47+
* 下载多媒体文件
48+
* 根据微信文档,视频文件下载不了,会返回null
49+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
50+
* </pre>
51+
*
52+
* @param mediaId 媒体id
53+
* @return 保存到本地的临时文件
54+
*/
55+
File download(String mediaId) throws WxErrorException;
56+
1157
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,91 @@
11
package me.chanjar.weixin.cp.api;
22

3+
import me.chanjar.weixin.common.bean.menu.WxMenu;
4+
import me.chanjar.weixin.common.exception.WxErrorException;
5+
36
/**
47
* <pre>
8+
* 菜单管理相关接口
59
* Created by BinaryWang on 2017/6/24.
610
* </pre>
711
*
812
* @author <a href="https://github.com/binarywang">Binary Wang</a>
913
*/
1014
public interface WxCpMenuService {
15+
/**
16+
* <pre>
17+
* 自定义菜单创建接口
18+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
19+
*
20+
* 注意: 这个方法使用WxCpConfigStorage里的agentId
21+
* </pre>
22+
*
23+
* @param menu 菜单对象
24+
* @see #create(Integer, WxMenu)
25+
*/
26+
void create(WxMenu menu) throws WxErrorException;
27+
28+
/**
29+
* <pre>
30+
* 自定义菜单创建接口
31+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
32+
*
33+
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
34+
* </pre>
35+
*
36+
* @param agentId 企业号应用的id
37+
* @param menu 菜单对象
38+
* @see #create(me.chanjar.weixin.common.bean.menu.WxMenu)
39+
*/
40+
void create(Integer agentId, WxMenu menu) throws WxErrorException;
41+
42+
/**
43+
* <pre>
44+
* 自定义菜单删除接口
45+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
46+
*
47+
* 注意: 这个方法使用WxCpConfigStorage里的agentId
48+
* </pre>
49+
*
50+
* @see #delete(Integer)
51+
*/
52+
void delete() throws WxErrorException;
53+
54+
/**
55+
* <pre>
56+
* 自定义菜单删除接口
57+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
58+
*
59+
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
60+
* </pre>
61+
*
62+
* @param agentId 企业号应用的id
63+
* @see #delete()
64+
*/
65+
void delete(Integer agentId) throws WxErrorException;
66+
67+
/**
68+
* <pre>
69+
* 自定义菜单查询接口
70+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
71+
*
72+
* 注意: 这个方法使用WxCpConfigStorage里的agentId
73+
* </pre>
74+
*
75+
* @see #get(Integer)
76+
*/
77+
WxMenu get() throws WxErrorException;
78+
79+
/**
80+
* <pre>
81+
* 自定义菜单查询接口
82+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
83+
*
84+
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
85+
* </pre>
86+
*
87+
* @param agentId 企业号应用的id
88+
* @see #get()
89+
*/
90+
WxMenu get(Integer agentId) throws WxErrorException;
1191
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import me.chanjar.weixin.common.exception.WxErrorException;
4+
5+
/**
6+
* <pre>
7+
* OAuth2相关管理接口
8+
* Created by BinaryWang on 2017/6/24.
9+
* </pre>
10+
*
11+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
12+
*/
13+
public interface WxCpOAuth2Service {
14+
/**
15+
* <pre>
16+
* 构造oauth2授权的url连接
17+
* </pre>
18+
*
19+
* @param state 状态码
20+
* @return url
21+
*/
22+
String buildAuthorizationUrl(String state);
23+
24+
/**
25+
* <pre>
26+
* 构造oauth2授权的url连接
27+
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=企业获取code
28+
* </pre>
29+
*
30+
* @param redirectUri 跳转链接地址
31+
* @param state 状态码
32+
* @return url
33+
*/
34+
String buildAuthorizationUrl(String redirectUri, String state);
35+
36+
/**
37+
* <pre>
38+
* 用oauth2获取用户信息
39+
* http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息
40+
* 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。
41+
*
42+
* 注意: 这个方法使用WxCpConfigStorage里的agentId
43+
* </pre>
44+
*
45+
* @param code 微信oauth授权返回的代码
46+
* @return [userid, deviceid]
47+
* @see #getUserInfo(Integer, String)
48+
*/
49+
String[] getUserInfo(String code) throws WxErrorException;
50+
51+
/**
52+
* <pre>
53+
* 用oauth2获取用户信息
54+
* http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息
55+
* 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。
56+
*
57+
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
58+
* </pre>
59+
*
60+
* @param agentId 企业号应用的id
61+
* @param code 微信oauth授权返回的代码
62+
* @return [userid, deviceid]
63+
* @see #getUserInfo(String)
64+
*/
65+
String[] getUserInfo(Integer agentId, String code) throws WxErrorException;
66+
67+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOauth2Service.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)