public interface WxCpService
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
checkSignature(String msgSignature,
String timestamp,
String nonce,
String data)
验证推送过来的消息的正确性
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
WxJsapiSignature |
createJsapiSignature(String url)
创建调用jsapi时所需要的签名
详情请见:http://qydev.weixin.qq.com/wiki/index.php?
|
Integer |
departCreate(WxCpDepart depart)
部门管理接口 - 创建部门
最多支持创建500个部门
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
void |
departDelete(Integer departId)
部门管理接口 - 删除部门
|
List<WxCpDepart> |
departGet()
部门管理接口 - 查询所有部门
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
List<WxCpUser> |
departGetUsers(Integer departId,
Boolean fetchChild,
Integer status)
获取部门成员
http://qydev.weixin.qq.com/wiki/index.php?
|
void |
departUpdate(WxCpDepart group)
部门管理接口 - 修改部门名
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
<T,E> T |
execute(RequestExecutor<T,E> executor,
String uri,
E data)
Service没有实现某个API的时候,可以用这个,
比
get(java.lang.String, java.lang.String)和post(java.lang.String, java.lang.String)方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。 |
String |
get(String url,
String queryParam)
当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
|
String |
getAccessToken()
获取access_token, 不强制刷新access_token
|
String |
getAccessToken(boolean forceRefresh)
获取access_token,本方法线程安全
且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
另:本service的所有方法都会在access_token过期是调用此方法
程序员在非必要情况下尽量不要主动调用此方法
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
String[] |
getCallbackIp()
获取微信服务器的ip段
http://qydev.weixin.qq.com/wiki/index.php?
|
String |
getJsapiTicket()
获得jsapi_ticket,不强制刷新jsapi_ticket
|
String |
getJsapiTicket(boolean forceRefresh)
获得jsapi_ticket
获得时会检查jsapiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
详情请见:http://qydev.weixin.qq.com/wiki/index.php?
|
WxSession |
getSession(String id)
获取某个sessionId对应的session,如果sessionId没有对应的session,则新建一个并返回。
|
WxSession |
getSession(String id,
boolean create)
获取某个sessionId对应的session,如果sessionId没有对应的session,若create为true则新建一个,否则返回null。
|
String |
getTaskResult(String joinId)
获取异步任务结果
|
int |
invite(String userId,
String inviteTips)
邀请成员关注
http://qydev.weixin.qq.com/wiki/index.php?
|
File |
mediaDownload(String media_id)
下载多媒体文件
根据微信文档,视频文件下载不了,会返回null
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
WxMediaUploadResult |
mediaUpload(String mediaType,
File file) |
WxMediaUploadResult |
mediaUpload(String mediaType,
String fileType,
InputStream inputStream)
上传多媒体文件
上传的多媒体文件有格式和大小限制,如下:
图片(image): 1M,支持JPG格式
语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
视频(video):10MB,支持MP4格式
缩略图(thumb):64KB,支持JPG格式
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
void |
menuCreate(String agentId,
WxMenu menu)
自定义菜单创建接口
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
void |
menuCreate(WxMenu menu)
自定义菜单创建接口
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
void |
menuDelete()
自定义菜单删除接口
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
void |
menuDelete(String agentId)
自定义菜单删除接口
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
WxMenu |
menuGet()
自定义菜单查询接口
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
WxMenu |
menuGet(String agentId)
自定义菜单查询接口
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
void |
messageSend(WxCpMessage message)
发送消息
详情请见: http://mp.weixin.qq.com/wiki/index.php?
|
String |
oauth2buildAuthorizationUrl(String redirectUri,
String state)
构造oauth2授权的url连接
详情请见: http://qydev.weixin.qq.com/wiki/index.php?
|
String[] |
oauth2getUserInfo(String code)
用oauth2获取用户信息
http://qydev.weixin.qq.com/wiki/index.php?
|
String[] |
oauth2getUserInfo(String agentId,
String code)
用oauth2获取用户信息
http://qydev.weixin.qq.com/wiki/index.php?
|
String |
post(String url,
String postData)
当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求
|
String |
replaceParty(String mediaId)
上传部门列表覆盖企业号上的部门信息
|
String |
replaceUser(String mediaId)
上传用户列表覆盖企业号上的用户信息
|
void |
setMaxRetryTimes(int maxRetryTimes)
设置当微信系统响应系统繁忙时,最大重试次数
默认:5次
|
void |
setRetrySleepMillis(int retrySleepMillis)
设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
默认:1000ms
|
void |
setSessionManager(WxSessionManager sessionManager)
设置WxSessionManager,只有当需要使用个性化的WxSessionManager的时候才需要调用此方法,
WxCpService默认使用的是
StandardSessionManager
|
void |
setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider)
注入
WxCpConfigStorage 的实现 |
void |
tagAddUsers(String tagId,
List<String> userIds,
List<String> partyIds)
增加标签成员
|
String |
tagCreate(String tagName)
创建标签
|
void |
tagDelete(String tagId)
删除标签
|
List<WxCpTag> |
tagGet()
获得标签列表
|
List<WxCpUser> |
tagGetUsers(String tagId)
获取标签成员
|
void |
tagRemoveUsers(String tagId,
List<String> userIds)
移除标签成员
|
void |
tagUpdate(String tagId,
String tagName)
更新标签
|
void |
userAuthenticated(String userId)
用在二次验证的时候
企业在员工验证成功后,调用本方法告诉企业号平台该员工关注成功。
|
void |
userCreate(WxCpUser user)
新建用户
|
void |
userDelete(String userid)
删除用户
|
void |
userDelete(String[] userids)
批量删除成员
http://qydev.weixin.qq.com/wiki/index.php?
|
WxCpUser |
userGet(String userid)
获取用户
|
List<WxCpUser> |
userList(Integer departId,
Boolean fetchChild,
Integer status)
获取部门成员(详情)
http://qydev.weixin.qq.com/wiki/index.php?
|
void |
userUpdate(WxCpUser user)
更新用户
|
boolean checkSignature(String msgSignature, String timestamp, String nonce, String data)
验证推送过来的消息的正确性 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=验证消息真实性
msgSignature - timestamp - nonce - data - 微信传输过来的数据,有可能是echoStr,有可能是xml消息void userAuthenticated(String userId) throws WxErrorException
用在二次验证的时候 企业在员工验证成功后,调用本方法告诉企业号平台该员工关注成功。
userId - WxErrorExceptionString getAccessToken() throws WxErrorException
WxErrorExceptiongetAccessToken(boolean)String getAccessToken(boolean forceRefresh) throws WxErrorException
获取access_token,本方法线程安全 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限 另:本service的所有方法都会在access_token过期是调用此方法 程序员在非必要情况下尽量不要主动调用此方法 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
forceRefresh - 强制刷新WxErrorExceptionString getJsapiTicket() throws WxErrorException
WxErrorExceptiongetJsapiTicket(boolean)String getJsapiTicket(boolean forceRefresh) throws WxErrorException
获得jsapi_ticket 获得时会检查jsapiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干 详情请见:http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
forceRefresh - 强制刷新WxErrorExceptionWxJsapiSignature createJsapiSignature(String url) throws WxErrorException
创建调用jsapi时所需要的签名 详情请见:http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
url - urlWxErrorExceptionWxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException
上传多媒体文件 上传的多媒体文件有格式和大小限制,如下: 图片(image): 1M,支持JPG格式 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式 视频(video):10MB,支持MP4格式 缩略图(thumb):64KB,支持JPG格式 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
mediaType - 媒体类型, 请看WxConstsfileType - 文件类型,请看WxConstsinputStream - 输入流WxErrorExceptionIOExceptionWxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException
mediaType - file - WxErrorExceptionmediaUpload(String, String, InputStream)File mediaDownload(String media_id) throws WxErrorException
下载多媒体文件 根据微信文档,视频文件下载不了,会返回null 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
WxErrorExceptionvoid messageSend(WxCpMessage message) throws WxErrorException
发送消息 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=发送消息
message - WxErrorExceptionvoid menuCreate(WxMenu menu) throws WxErrorException
自定义菜单创建接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口 注意: 这个方法使用WxCpConfigStorage里的agentId
menu - WxErrorExceptionmenuCreate(String, me.chanjar.weixin.common.bean.WxMenu)void menuCreate(String agentId, WxMenu menu) throws WxErrorException
自定义菜单创建接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
agentId - 企业号应用的idmenu - WxErrorExceptionmenuCreate(me.chanjar.weixin.common.bean.WxMenu)void menuDelete()
throws WxErrorException
自定义菜单删除接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口 注意: 这个方法使用WxCpConfigStorage里的agentId
WxErrorExceptionmenuDelete(String)void menuDelete(String agentId) throws WxErrorException
自定义菜单删除接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
agentId - 企业号应用的idWxErrorExceptionmenuDelete()WxMenu menuGet() throws WxErrorException
自定义菜单查询接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口 注意: 这个方法使用WxCpConfigStorage里的agentId
WxErrorExceptionmenuGet(String)WxMenu menuGet(String agentId) throws WxErrorException
自定义菜单查询接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
agentId - 企业号应用的idWxErrorExceptionmenuGet()Integer departCreate(WxCpDepart depart) throws WxErrorException
部门管理接口 - 创建部门 最多支持创建500个部门 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
depart - 部门WxErrorExceptionList<WxCpDepart> departGet() throws WxErrorException
部门管理接口 - 查询所有部门 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
WxErrorExceptionvoid departUpdate(WxCpDepart group) throws WxErrorException
部门管理接口 - 修改部门名 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口 如果id为0(未部门),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
group - 要更新的group,group的id,name必须设置WxErrorExceptionvoid departDelete(Integer departId) throws WxErrorException
部门管理接口 - 删除部门
departId - WxErrorExceptionList<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException
获取部门成员(详情) http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29
departId - 必填。部门idfetchChild - 非必填。1/0:是否递归获取子部门下面的成员status - 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加WxErrorExceptionList<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException
获取部门成员 http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98
departId - 必填。部门idfetchChild - 非必填。1/0:是否递归获取子部门下面的成员status - 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加WxErrorExceptionvoid userCreate(WxCpUser user) throws WxErrorException
user - WxErrorExceptionvoid userUpdate(WxCpUser user) throws WxErrorException
user - WxErrorExceptionvoid userDelete(String userid) throws WxErrorException
userid - WxErrorExceptionvoid userDelete(String[] userids) throws WxErrorException
批量删除成员 http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98
userids - 员工UserID列表。对应管理端的帐号WxErrorExceptionWxCpUser userGet(String userid) throws WxErrorException
userid - WxErrorExceptionString tagCreate(String tagName) throws WxErrorException
tagName - WxErrorExceptionvoid tagUpdate(String tagId, String tagName) throws WxErrorException
tagId - tagName - WxErrorExceptionvoid tagDelete(String tagId) throws WxErrorException
tagId - WxErrorExceptionList<WxCpTag> tagGet() throws WxErrorException
WxErrorExceptionList<WxCpUser> tagGetUsers(String tagId) throws WxErrorException
tagId - WxErrorExceptionvoid tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException
tagId - userIds - WxErrorExceptionString oauth2buildAuthorizationUrl(String redirectUri, String state)
构造oauth2授权的url连接 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=企业获取code
redirectUri - state - String[] oauth2getUserInfo(String code) throws WxErrorException
用oauth2获取用户信息 http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。 注意: 这个方法使用WxCpConfigStorage里的agentId
code - WxErrorExceptionoauth2getUserInfo(String, String)String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException
用oauth2获取用户信息 http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
agentId - 企业号应用的idcode - WxErrorExceptionoauth2getUserInfo(String)void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorException
tagId - userIds - WxErrorExceptionint invite(String userId, String inviteTips) throws WxErrorException
邀请成员关注 http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E9.82.80.E8.AF.B7.E6.88.90.E5.91.98.E5.85.B3.E6.B3.A8
userId - 用户的useridinviteTips - 推送到微信上的提示语(只有认证号可以使用)。当使用微信推送时,该字段默认为“请关注XXX企业号”,邮件邀请时,该字段无效。WxErrorExceptionString[] getCallbackIp() throws WxErrorException
获取微信服务器的ip段 http://qydev.weixin.qq.com/wiki/index.php?title=回调模式#.E8.8E.B7.E5.8F.96.E5.BE.AE.E4.BF.A1.E6.9C.8D.E5.8A.A1.E5.99.A8.E7.9A.84ip.E6.AE.B5
WxErrorExceptionString get(String url, String queryParam) throws WxErrorException
url - queryParam - WxErrorExceptionString post(String url, String postData) throws WxErrorException
url - postData - WxErrorException<T,E> T execute(RequestExecutor<T,E> executor, String uri, E data) throws WxErrorException
Service没有实现某个API的时候,可以用这个, 比get(java.lang.String, java.lang.String)和post(java.lang.String, java.lang.String)方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。 可以参考,MediaUploadRequestExecutor的实现方法
T - E - executor - uri - data - WxErrorExceptionvoid setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider)
WxCpConfigStorage 的实现wxConfigProvider - void setRetrySleepMillis(int retrySleepMillis)
设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试 默认:1000ms
retrySleepMillis - void setMaxRetryTimes(int maxRetryTimes)
设置当微信系统响应系统繁忙时,最大重试次数 默认:5次
maxRetryTimes - WxSession getSession(String id)
id - id可以为任意字符串,建议使用FromUserName作为idWxSession getSession(String id, boolean create)
id - id可以为任意字符串,建议使用FromUserName作为idcreate - void setSessionManager(WxSessionManager sessionManager)
设置WxSessionManager,只有当需要使用个性化的WxSessionManager的时候才需要调用此方法,
WxCpService默认使用的是StandardSessionManager
sessionManager - String replaceParty(String mediaId) throws WxErrorException
mediaId - WxErrorExceptionString replaceUser(String mediaId) throws WxErrorException
mediaId - WxErrorExceptionString getTaskResult(String joinId) throws WxErrorException
joinId - WxErrorExceptionCopyright © 2015. All rights reserved.