Skip to content

Commit

Permalink
优化重构企业号相关代码,修复了升级企业微信后出现的菜单问题和用户管理的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Jun 25, 2017
1 parent 0f0f7bb commit 9f4a7a7
Show file tree
Hide file tree
Showing 29 changed files with 1,022 additions and 513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationCon
* 操蛋的微信
* 创建菜单时是 { button : ... }
* 查询菜单时是 { menu : { button : ... } }
* 现在企业号升级为企业微信后,没有此问题,因此需要单独处理
*/
WxMenu menu = new WxMenu();
JsonArray buttonsJson = json.getAsJsonObject().get("menu").getAsJsonObject().get("button").getAsJsonArray();
return this.buildMenuFromJson(buttonsJson);
}

protected WxMenu buildMenuFromJson(JsonArray buttonsJson) {
WxMenu menu = new WxMenu();
for (int i = 0; i < buttonsJson.size(); i++) {
JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
WxMenuButton button = convertFromJson(buttonJson);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
* <pre>
* 媒体管理接口
* Created by BinaryWang on 2017/6/24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpMediaService {

/**
* <pre>
* 上传多媒体文件
* 上传的多媒体文件有格式和大小限制,如下:
* 图片(image): 1M,支持JPG格式
* 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
* 视频(video):10MB,支持MP4格式
* 缩略图(thumb):64KB,支持JPG格式
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
* </pre>
*
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param inputStream 输入流
*/
WxMediaUploadResult upload(String mediaType, String fileType, InputStream inputStream)
throws WxErrorException, IOException;

/**
* @param mediaType 媒体类型
* @param file 文件对象
* @see #upload(String, String, InputStream)
*/
WxMediaUploadResult upload(String mediaType, File file) throws WxErrorException;

/**
* <pre>
* 下载多媒体文件
* 根据微信文档,视频文件下载不了,会返回null
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
* </pre>
*
* @param mediaId 媒体id
* @return 保存到本地的临时文件
*/
File download(String mediaId) throws WxErrorException;

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,91 @@
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.exception.WxErrorException;

/**
* <pre>
* 菜单管理相关接口
* Created by BinaryWang on 2017/6/24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpMenuService {
/**
* <pre>
* 自定义菜单创建接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
*
* 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre>
*
* @param menu 菜单对象
* @see #create(Integer, WxMenu)
*/
void create(WxMenu menu) throws WxErrorException;

/**
* <pre>
* 自定义菜单创建接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
*
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
* </pre>
*
* @param agentId 企业号应用的id
* @param menu 菜单对象
* @see #create(me.chanjar.weixin.common.bean.menu.WxMenu)
*/
void create(Integer agentId, WxMenu menu) throws WxErrorException;

/**
* <pre>
* 自定义菜单删除接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
*
* 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre>
*
* @see #delete(Integer)
*/
void delete() throws WxErrorException;

/**
* <pre>
* 自定义菜单删除接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
*
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
* </pre>
*
* @param agentId 企业号应用的id
* @see #delete()
*/
void delete(Integer agentId) throws WxErrorException;

/**
* <pre>
* 自定义菜单查询接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
*
* 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre>
*
* @see #get(Integer)
*/
WxMenu get() throws WxErrorException;

/**
* <pre>
* 自定义菜单查询接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
*
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
* </pre>
*
* @param agentId 企业号应用的id
* @see #get()
*/
WxMenu get(Integer agentId) throws WxErrorException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.common.exception.WxErrorException;

/**
* <pre>
* OAuth2相关管理接口
* Created by BinaryWang on 2017/6/24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpOAuth2Service {
/**
* <pre>
* 构造oauth2授权的url连接
* </pre>
*
* @param state 状态码
* @return url
*/
String buildAuthorizationUrl(String state);

/**
* <pre>
* 构造oauth2授权的url连接
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=企业获取code
* </pre>
*
* @param redirectUri 跳转链接地址
* @param state 状态码
* @return url
*/
String buildAuthorizationUrl(String redirectUri, String state);

/**
* <pre>
* 用oauth2获取用户信息
* http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息
* 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。
*
* 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre>
*
* @param code 微信oauth授权返回的代码
* @return [userid, deviceid]
* @see #getUserInfo(Integer, String)
*/
String[] getUserInfo(String code) throws WxErrorException;

/**
* <pre>
* 用oauth2获取用户信息
* http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息
* 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。
*
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
* </pre>
*
* @param agentId 企业号应用的id
* @param code 微信oauth授权返回的代码
* @return [userid, deviceid]
* @see #getUserInfo(String)
*/
String[] getUserInfo(Integer agentId, String code) throws WxErrorException;

}

This file was deleted.

Loading

0 comments on commit 9f4a7a7

Please sign in to comment.