public class WxCpServiceImpl extends Object implements WxCpService
| 限定符和类型 | 字段和说明 |
|---|---|
protected Object |
globalAccessTokenRefreshLock
全局的是否正在刷新access token的锁
|
protected Object |
globalJsapiTicketRefreshLock
全局的是否正在刷新jsapi_ticket的锁
|
protected org.apache.http.impl.client.CloseableHttpClient |
httpClient |
protected org.apache.http.HttpHost |
httpProxy |
protected org.slf4j.Logger |
log |
protected WxSessionManager |
sessionManager |
protected File |
tmpDirFile
临时文件目录
|
protected WxCpConfigStorage |
wxCpConfigStorage |
| 构造器和说明 |
|---|
WxCpServiceImpl() |
| 限定符和类型 | 方法和说明 |
|---|---|
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)
向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
|
protected <T,E> T |
executeInternal(RequestExecutor<T,E> executor,
String uri,
E data) |
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?
|
protected org.apache.http.impl.client.CloseableHttpClient |
getHttpclient() |
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)
获取异步任务结果
|
File |
getTmpDirFile() |
int |
invite(String userId,
String inviteTips)
邀请成员关注
http://qydev.weixin.qq.com/wiki/index.php?
|
static void |
main(String[] args) |
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 |
setTmpDirFile(File tmpDirFile) |
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)
更新用户
|
protected final org.slf4j.Logger log
protected final Object globalAccessTokenRefreshLock
protected final Object globalJsapiTicketRefreshLock
protected WxCpConfigStorage wxCpConfigStorage
protected org.apache.http.impl.client.CloseableHttpClient httpClient
protected org.apache.http.HttpHost httpProxy
protected WxSessionManager sessionManager
protected File tmpDirFile
public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data)
WxCpService验证推送过来的消息的正确性 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=验证消息真实性
checkSignature 在接口中 WxCpServicedata - 微信传输过来的数据,有可能是echoStr,有可能是xml消息public void userAuthenticated(String userId) throws WxErrorException
WxCpService用在二次验证的时候 企业在员工验证成功后,调用本方法告诉企业号平台该员工关注成功。
userAuthenticated 在接口中 WxCpServiceWxErrorExceptionpublic String getAccessToken() throws WxErrorException
WxCpServicegetAccessToken 在接口中 WxCpServiceWxErrorExceptionWxCpService.getAccessToken(boolean)public String getAccessToken(boolean forceRefresh) throws WxErrorException
WxCpService获取access_token,本方法线程安全 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限 另:本service的所有方法都会在access_token过期是调用此方法 程序员在非必要情况下尽量不要主动调用此方法 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
getAccessToken 在接口中 WxCpServiceforceRefresh - 强制刷新WxErrorExceptionpublic String getJsapiTicket() throws WxErrorException
WxCpServicegetJsapiTicket 在接口中 WxCpServiceWxErrorExceptionWxCpService.getJsapiTicket(boolean)public String getJsapiTicket(boolean forceRefresh) throws WxErrorException
WxCpService获得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
getJsapiTicket 在接口中 WxCpServiceforceRefresh - 强制刷新WxErrorExceptionpublic WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
WxCpService创建调用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
createJsapiSignature 在接口中 WxCpServiceurl - urlWxErrorExceptionpublic void messageSend(WxCpMessage message) throws WxErrorException
WxCpService发送消息 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=发送消息
messageSend 在接口中 WxCpServiceWxErrorExceptionpublic void menuCreate(WxMenu menu) throws WxErrorException
WxCpService自定义菜单创建接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口 注意: 这个方法使用WxCpConfigStorage里的agentId
public void menuCreate(String agentId, WxMenu menu) throws WxErrorException
WxCpService自定义菜单创建接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
menuCreate 在接口中 WxCpServiceagentId - 企业号应用的idWxErrorExceptionWxCpService.menuCreate(me.chanjar.weixin.common.bean.WxMenu)public void menuDelete()
throws WxErrorException
WxCpService自定义菜单删除接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口 注意: 这个方法使用WxCpConfigStorage里的agentId
menuDelete 在接口中 WxCpServiceWxErrorExceptionWxCpService.menuDelete(String)public void menuDelete(String agentId) throws WxErrorException
WxCpService自定义菜单删除接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
menuDelete 在接口中 WxCpServiceagentId - 企业号应用的idWxErrorExceptionWxCpService.menuDelete()public WxMenu menuGet() throws WxErrorException
WxCpService自定义菜单查询接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口 注意: 这个方法使用WxCpConfigStorage里的agentId
menuGet 在接口中 WxCpServiceWxErrorExceptionWxCpService.menuGet(String)public WxMenu menuGet(String agentId) throws WxErrorException
WxCpService自定义菜单查询接口 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
menuGet 在接口中 WxCpServiceagentId - 企业号应用的idWxErrorExceptionWxCpService.menuGet()public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException
WxCpService上传多媒体文件 上传的多媒体文件有格式和大小限制,如下: 图片(image): 1M,支持JPG格式 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式 视频(video):10MB,支持MP4格式 缩略图(thumb):64KB,支持JPG格式 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
mediaUpload 在接口中 WxCpServicemediaType - 媒体类型, 请看WxConstsfileType - 文件类型,请看WxConstsinputStream - 输入流WxErrorExceptionIOExceptionpublic WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException
public File mediaDownload(String media_id) throws WxErrorException
WxCpService下载多媒体文件 根据微信文档,视频文件下载不了,会返回null 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
mediaDownload 在接口中 WxCpServiceWxErrorExceptionpublic Integer departCreate(WxCpDepart depart) throws WxErrorException
WxCpService部门管理接口 - 创建部门 最多支持创建500个部门 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
departCreate 在接口中 WxCpServicedepart - 部门WxErrorExceptionpublic void departUpdate(WxCpDepart group) throws WxErrorException
WxCpService部门管理接口 - 修改部门名 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口 如果id为0(未部门),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
departUpdate 在接口中 WxCpServicegroup - 要更新的group,group的id,name必须设置WxErrorExceptionpublic void departDelete(Integer departId) throws WxErrorException
WxCpService部门管理接口 - 删除部门
departDelete 在接口中 WxCpServiceWxErrorExceptionpublic List<WxCpDepart> departGet() throws WxErrorException
WxCpService部门管理接口 - 查询所有部门 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
departGet 在接口中 WxCpServiceWxErrorExceptionpublic void userCreate(WxCpUser user) throws WxErrorException
WxCpServiceuserCreate 在接口中 WxCpServiceWxErrorExceptionpublic void userUpdate(WxCpUser user) throws WxErrorException
WxCpServiceuserUpdate 在接口中 WxCpServiceWxErrorExceptionpublic void userDelete(String userid) throws WxErrorException
WxCpServiceuserDelete 在接口中 WxCpServiceWxErrorExceptionpublic void userDelete(String[] userids) throws WxErrorException
WxCpService批量删除成员 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
userDelete 在接口中 WxCpServiceuserids - 员工UserID列表。对应管理端的帐号WxErrorExceptionpublic WxCpUser userGet(String userid) throws WxErrorException
WxCpServiceuserGet 在接口中 WxCpServiceWxErrorExceptionpublic List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException
WxCpService获取部门成员(详情) 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
userList 在接口中 WxCpServicedepartId - 必填。部门idfetchChild - 非必填。1/0:是否递归获取子部门下面的成员status - 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加WxErrorExceptionpublic List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException
WxCpService获取部门成员 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
departGetUsers 在接口中 WxCpServicedepartId - 必填。部门idfetchChild - 非必填。1/0:是否递归获取子部门下面的成员status - 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加WxErrorExceptionpublic String tagCreate(String tagName) throws WxErrorException
WxCpServicetagCreate 在接口中 WxCpServiceWxErrorExceptionpublic void tagUpdate(String tagId, String tagName) throws WxErrorException
WxCpServicetagUpdate 在接口中 WxCpServiceWxErrorExceptionpublic void tagDelete(String tagId) throws WxErrorException
WxCpServicetagDelete 在接口中 WxCpServiceWxErrorExceptionpublic List<WxCpTag> tagGet() throws WxErrorException
WxCpServicetagGet 在接口中 WxCpServiceWxErrorExceptionpublic List<WxCpUser> tagGetUsers(String tagId) throws WxErrorException
WxCpServicetagGetUsers 在接口中 WxCpServiceWxErrorExceptionpublic void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException
WxCpServicetagAddUsers 在接口中 WxCpServiceWxErrorExceptionpublic void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorException
WxCpServicetagRemoveUsers 在接口中 WxCpServiceWxErrorExceptionpublic String oauth2buildAuthorizationUrl(String redirectUri, String state)
WxCpService构造oauth2授权的url连接 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=企业获取code
oauth2buildAuthorizationUrl 在接口中 WxCpServicepublic String[] oauth2getUserInfo(String code) throws WxErrorException
WxCpService用oauth2获取用户信息 http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。 注意: 这个方法使用WxCpConfigStorage里的agentId
oauth2getUserInfo 在接口中 WxCpServiceWxErrorExceptionWxCpService.oauth2getUserInfo(String, String)public String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException
WxCpService用oauth2获取用户信息 http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
oauth2getUserInfo 在接口中 WxCpServiceagentId - 企业号应用的idWxErrorExceptionWxCpService.oauth2getUserInfo(String)public int invite(String userId, String inviteTips) throws WxErrorException
WxCpService邀请成员关注 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
invite 在接口中 WxCpServiceuserId - 用户的useridinviteTips - 推送到微信上的提示语(只有认证号可以使用)。当使用微信推送时,该字段默认为“请关注XXX企业号”,邮件邀请时,该字段无效。WxErrorExceptionpublic String[] getCallbackIp() throws WxErrorException
WxCpService获取微信服务器的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
getCallbackIp 在接口中 WxCpServiceWxErrorExceptionpublic String get(String url, String queryParam) throws WxErrorException
WxCpServiceget 在接口中 WxCpServiceWxErrorExceptionpublic String post(String url, String postData) throws WxErrorException
WxCpServicepost 在接口中 WxCpServiceWxErrorExceptionpublic <T,E> T execute(RequestExecutor<T,E> executor, String uri, E data) throws WxErrorException
execute 在接口中 WxCpServiceexecutor - uri - data - WxErrorExceptionprotected <T,E> T executeInternal(RequestExecutor<T,E> executor, String uri, E data) throws WxErrorException
WxErrorExceptionprotected org.apache.http.impl.client.CloseableHttpClient getHttpclient()
public void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider)
WxCpServiceWxCpConfigStorage 的实现setWxCpConfigStorage 在接口中 WxCpServicepublic void setRetrySleepMillis(int retrySleepMillis)
WxCpService设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试 默认:1000ms
setRetrySleepMillis 在接口中 WxCpServicepublic void setMaxRetryTimes(int maxRetryTimes)
WxCpService设置当微信系统响应系统繁忙时,最大重试次数 默认:5次
setMaxRetryTimes 在接口中 WxCpServicepublic WxSession getSession(String id)
WxCpServicegetSession 在接口中 WxCpServiceid - id可以为任意字符串,建议使用FromUserName作为idpublic WxSession getSession(String id, boolean create)
WxCpServicegetSession 在接口中 WxCpServiceid - id可以为任意字符串,建议使用FromUserName作为idpublic void setSessionManager(WxSessionManager sessionManager)
WxCpService
设置WxSessionManager,只有当需要使用个性化的WxSessionManager的时候才需要调用此方法,
WxCpService默认使用的是StandardSessionManager
setSessionManager 在接口中 WxCpServicepublic String replaceParty(String mediaId) throws WxErrorException
WxCpServicereplaceParty 在接口中 WxCpServiceWxErrorExceptionpublic String replaceUser(String mediaId) throws WxErrorException
WxCpServicereplaceUser 在接口中 WxCpServiceWxErrorExceptionpublic String getTaskResult(String joinId) throws WxErrorException
WxCpServicegetTaskResult 在接口中 WxCpServiceWxErrorExceptionpublic File getTmpDirFile()
public void setTmpDirFile(File tmpDirFile)
public static void main(String[] args)
Copyright © 2015. All rights reserved.