Skip to content

wxtech/wxsdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

微信服务号 SDK for Java

###如何使用?

在maven工程的pom.xml,添加下面的引用。

<dependency>
    <groupId>com.kunbao.weixin</groupId>
    <artifactId>sdk</artifactId>
    <version>1.1</version>
</dependency>

==== ###初始化

推荐使用下面的单例模式进行初始化。

private WXApi wxApi;
public synchronized WXApi getWxApi() {
    if (wxApi == null) {
        wxApi = new WXApi(WXConstant.APP_ID, WXConstant.APP_SECRET, WXConstant.TOKEN, WXConstant.EncodingAESKey);
    }
    return wxApi;
}

==== ###方法介绍

所有的方法都通过wxApi进行调用,简单易用。
开发者不需要关心token,相关的刷新逻辑已经封装在代码中。

#####安全相关的接口(包含js认证)

  1. 验证服务器地址有效性
    boolean checkSignature(String signature, String timestamp, String nonce)

  2. 解密消息
    String decryptContent(String encryptType, String msgSignature, String timestamp, String nonce, String content) throws AesException

  3. 加密消息
    String encryptContent(String encryptType, String timestamp, String nonce, String content) throws AesException

  4. 获得微信服务器IP地址列表
    List<String> getCallbackIpList() throws WXException

  5. 获得js api config
    WXJsConfig constructWXJsConfig(String url) throws WXException

  6. 通过oauth code获取用户信息
    WXOAuthUserInfoGetResponse getAuthUserInfo(String appId, String appSecret, String authCode, String lang) throws WXException

#####消息相关的接口

  1. 解析接受的消息
    WXMessageBase consumeMessage(String messageStr) throws WXException

  2. 产生被动回复消息
    String produceText(String fromUser, String toUser, String content) throws WXException
    String produceImage(String fromUser, String toUser, String mediaId) throws WXException
    String produceVoice(String fromUser, String toUser, String mediaId) throws WXException
    String produceVideo(String fromUser, String toUser, WXSendVideoMedia videoMedia) throws WXException
    String produceMusic(String fromUser, String toUser, WXSendMusicMedia musicMedia) throws WXException
    String produceNews(String fromUser, String toUser, List<WXSendNewsItem> newsItems) throws WXException

  3. 发送客服消息
    boolean sendCustomText(String toUser, String content) throws WXException
    boolean sendCustomImage(String toUser, String mediaId) throws WXException
    boolean sendCustomVoice(String toUser, String mediaId) throws WXException
    boolean sendCustomVideo(String toUser, VideoContent videoContent) throws WXException
    boolean sendCustomMusic(String toUser, MusicContent musicContent) throws WXException
    boolean sendCustomNews(String toUser, List<NewsItemContent> articles) throws WXException

  4. 发送模板消息
    boolean setIndustryForTemplateMessage(Industry industry) throws WXException
    String getTemplateIdByShortId(String shortId) throws WXException
    String sendTemplateMessage(MessageInfo messageInfo) throws WXException

#####素材管理接口

  1. 新增临时素材,返回新增素材的url
    String uploadTempMedia(MediaType type, String filePath) throws WXException

  2. 新增永久图文素材
    String addNewsList(NewsList newsList) throws WXException

  3. 新增永久其它素材
    WXAddCommonMaterialResponse addCommonMaterial(String filePath) throws WXException

  4. 删除永久素材
    boolean deleteMaterial(String mediaId) throws WXException

  5. 修改永久图文素材
    boolean updateNewsItem(NewsUpdater newsUpdater) throws WXException

  6. 获取素材总数
    WXGetMaterialCountResponse getMaterialCount() throws WXException

  7. 获取素材列表
    WXGetCommonMaterialListResponse getCommonMaterialList(MaterialPageableRequest pageableRequest) throws WXException
    WXGetNewsMaterialListResponse getNewsMaterialList(MaterialPageableRequest pageableRequest) throws WXException

  8. 根据微信端素材id,获得素材url
    String getMaterialTempUrl(String mediaId) throws WXException

  9. 根据id读取素材,返回byte数组
    byte[] getMaterialBytes(String mediaId) throws WXException

#####用户管理接口

  1. 用户分组管理
    WXUserGroup createUserGroup(String groupName) throws WXException
    List<WXUserGroup> getUserGroup() throws WXException
    int getUserInGroupId(String openId) throws WXException
    boolean updateUserGroup(int groupId, String groupName) throws WXException
    boolean moveUserToGroup(String openId, int groupId) throws WXException
    boolean moveBatchUserToGroup(List<String> openIdList, int groupId) throws WXException
    boolean deleteUseGroup(int groupId) throws WXException

  2. 设置用户备注名
    boolean remarkUser(String openId, String remark) throws WXException

  3. 获取用户基本信息
    WXUserInfoResponse getUserInfo(String openId, WXLang lang) throws WXException
    WXUserInfoListResponse getBatchUserInfo(WXUserList userList) throws WXException

  4. 获取用户列表
    WXUserGetResponse getUserList(String nextOpenId) throws WXException

#####自定义菜单接口

  1. 自定义菜单创建接口
    boolean createMenu(Menu menu) throws WXException

  2. 自定义菜单查询接口
    WXMenuGetResponse getMenu() throws WXException

  3. 自定义菜单删除接口
    boolean deleteMenu() throws WXException

  4. 获取自定义菜单配置接口
    WXSelfMenuGetResponse getSelfMenu() throws WXException

#####账号管理接口

  1. 生成带参数的二维码
    String createTempQrcode(long expireSeconds, int scenceId) throws WXException
    String createLimitSceneQrCode(int scenceId) throws WXException
    String createLimitStrSceneQrCode(String scenceStr) throws WXException

  2. 长链接转短链接
    String long2ShortUrl(String longUrl) throws WXException

#####数据统计接口

  1. 用户分析数据接口
    List<UserSummaryItem> getUserSummaryDataCube(Date start, Date end) throws WXException
    List<UserCumulateItem> getUserCumulateDateCube(Date start, Date end) throws WXException

  2. 图文分析数据接口
    List<ArticleData> getArticleSummaryDataCube(Date start, Date end) throws WXException
    List<ArticleTotalData> getArticleTotalDataCube(Date start, Date end) throws WXException
    List<UserReadData> getArticleUserReadDataCube(Date start, Date end) throws WXException
    List<UserReadHourData> getArticleUserReadHourDataCube(Date start, Date end) throws WXException
    List<ArticleShareData> getArticleShareDataCube(Date start, Date end) throws WXException
    List<ArticleShareHourData> getArticleShareHourDataCube(Date start, Date end) throws WXException

  3. 消息分析数据接口
    List<UpstreamMsgData> getUpstreamMsgDataCube(Date start, Date end) throws WXException
    List<UpstreamMsgHourData> getUpstreamMsgHourDataCube(Date start, Date end) throws WXException
    List<UpstreamMsgData> getUpstreamMsgWeekDataCube(Date start, Date end) throws WXException
    List<UpstreamMsgData> getUpstreamMsgMonthDataCube(Date start, Date end) throws WXException
    List<UpstreamMsgDistData> getUpstreamMsgDistDataCube(Date start, Date end) throws WXException
    List<UpstreamMsgDistData> getUpstreamMsgDistWeekDataCube(Date start, Date end) throws WXException
    List<UpstreamMsgDistData> getUpstreamMsgDistMonthDataCube(Date start, Date end) throws WXException

  4. 接口分析数据接口
    List<InterfaceData> getInterfaceSummaryDataCube(Date start, Date end) throws WXException
    List<InterfaceHourData> getInterfaceHourSummaryDataCube(Date start, Date end) throws WXException

#####未实现的接口(持续实现中...)

  1. 客服账号管理
  2. 群发接口
  3. 获取自动回复规则接口

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%