├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── alipay.png ├── circle.yml ├── pom.xml └── src ├── main └── java │ └── com │ └── github │ └── sd4324530 │ └── fastweixin │ ├── api │ ├── BaseAPI.java │ ├── CustomAPI.java │ ├── DataCubeAPI.java │ ├── JsAPI.java │ ├── MaterialAPI.java │ ├── MediaAPI.java │ ├── MenuAPI.java │ ├── MessageAPI.java │ ├── OauthAPI.java │ ├── QrcodeAPI.java │ ├── SystemAPI.java │ ├── TagAPI.java │ ├── TemplateMsgAPI.java │ ├── UserAPI.java │ ├── config │ │ ├── ApiConfig.java │ │ ├── ChangeType.java │ │ └── ConfigChangeNotice.java │ ├── entity │ │ ├── Article.java │ │ ├── ArticleSummary.java │ │ ├── ArticleTotal.java │ │ ├── ArticleTotalDetail.java │ │ ├── BaseDataCube.java │ │ ├── BaseModel.java │ │ ├── CustomAccount.java │ │ ├── Group.java │ │ ├── Industry.java │ │ ├── InterfaceSummary.java │ │ ├── InterfaceSummaryHour.java │ │ ├── Matchrule.java │ │ ├── Menu.java │ │ ├── MenuButton.java │ │ ├── Model.java │ │ ├── Tag.java │ │ ├── TemplateMsg.java │ │ ├── TemplateParam.java │ │ ├── UpstreamMsg.java │ │ ├── UpstreamMsgDist.java │ │ ├── UpstreamMsgDistMonth.java │ │ ├── UpstreamMsgDistWeek.java │ │ ├── UpstreamMsgHour.java │ │ ├── UpstreamMsgMonth.java │ │ ├── UpstreamMsgWeek.java │ │ ├── UserCumulate.java │ │ ├── UserInfo.java │ │ ├── UserRead.java │ │ ├── UserReadHour.java │ │ ├── UserShare.java │ │ ├── UserShareHour.java │ │ └── UserSummary.java │ ├── enums │ │ ├── MaterialType.java │ │ ├── MediaType.java │ │ ├── MenuType.java │ │ ├── OauthScope.java │ │ ├── QrcodeType.java │ │ └── ResultType.java │ ├── request │ │ └── BaseRequest.java │ └── response │ │ ├── AddTemplateResponse.java │ │ ├── BaseResponse.java │ │ ├── CreateGroupResponse.java │ │ ├── CreateTagResponse.java │ │ ├── DownloadMaterialResponse.java │ │ ├── DownloadMediaResponse.java │ │ ├── GetAllTagsResponse.java │ │ ├── GetArticleSummaryResponse.java │ │ ├── GetArticleTotalResponse.java │ │ ├── GetCustomAccountsResponse.java │ │ ├── GetGroupsResponse.java │ │ ├── GetInterfaceSummaryHourResponse.java │ │ ├── GetInterfaceSummaryResponse.java │ │ ├── GetJsApiTicketResponse.java │ │ ├── GetMaterialListResponse.java │ │ ├── GetMaterialTotalCountResponse.java │ │ ├── GetMenuResponse.java │ │ ├── GetSendMessageResponse.java │ │ ├── GetSignatureResponse.java │ │ ├── GetTokenResponse.java │ │ ├── GetUpstreamMsgDistMonthResponse.java │ │ ├── GetUpstreamMsgDistResponse.java │ │ ├── GetUpstreamMsgDistWeekResponse.java │ │ ├── GetUpstreamMsgHourResponse.java │ │ ├── GetUpstreamMsgMonthResponse.java │ │ ├── GetUpstreamMsgResponse.java │ │ ├── GetUpstreamMsgWeekResponse.java │ │ ├── GetUserCumulateResponse.java │ │ ├── GetUserInfoListResponse.java │ │ ├── GetUserInfoResponse.java │ │ ├── GetUserReadHourResponse.java │ │ ├── GetUserReadResponse.java │ │ ├── GetUserShareHourResponse.java │ │ ├── GetUserShareResponse.java │ │ ├── GetUserSummaryResponse.java │ │ ├── GetUsersResponse.java │ │ ├── OauthGetTokenResponse.java │ │ ├── PrivateTemplate.java │ │ ├── QrcodeResponse.java │ │ ├── SendTemplateResponse.java │ │ ├── UploadImgResponse.java │ │ ├── UploadMaterialResponse.java │ │ └── UploadMediaResponse.java │ ├── company │ ├── api │ │ ├── QYAgentAPI.java │ │ ├── QYBaseAPI.java │ │ ├── QYDepartmentAPI.java │ │ ├── QYMediaAPI.java │ │ ├── QYMenuAPI.java │ │ ├── QYMessageAPI.java │ │ ├── QYOauthAPI.java │ │ ├── QYTagAPI.java │ │ ├── QYUserAPI.java │ │ ├── config │ │ │ ├── QYAPIConfig.java │ │ │ └── QYConfigChangeNotice.java │ │ ├── entity │ │ │ ├── QYAgent.java │ │ │ ├── QYDepartment.java │ │ │ ├── QYMenu.java │ │ │ ├── QYMenuButton.java │ │ │ ├── QYTag.java │ │ │ └── QYUser.java │ │ ├── enums │ │ │ ├── QYMenuType.java │ │ │ └── QYResultType.java │ │ ├── handle │ │ │ └── AbstractQYApiConfigChangeHandle.java │ │ └── response │ │ │ ├── AddTagUsersResponse.java │ │ │ ├── CreateDepartmentResponse.java │ │ │ ├── CreateTagResponse.java │ │ │ ├── DelTagUsersResponse.java │ │ │ ├── DownloadMediaResponse.java │ │ │ ├── GetDepartmentListResponse.java │ │ │ ├── GetOauthUserInfoResponse.java │ │ │ ├── GetQYAgentInfoResponse.java │ │ │ ├── GetQYAgentListResponse.java │ │ │ ├── GetQYMenuResponse.java │ │ │ ├── GetQYSendMessageResponse.java │ │ │ ├── GetQYUserInfo4DepartmentResponse.java │ │ │ ├── GetQYUserInfoResponse.java │ │ │ ├── GetQYUserInviteResponse.java │ │ │ ├── GetTagInfoResponse.java │ │ │ ├── GetTagListResponse.java │ │ │ └── UploadMediaResponse.java │ ├── handle │ │ ├── QYEventHandle.java │ │ └── QYMessageHandle.java │ └── message │ │ ├── QYArticle.java │ │ ├── QYBaseMsg.java │ │ ├── QYFileMsg.java │ │ ├── QYImageMsg.java │ │ ├── QYMpArticle.java │ │ ├── QYMpNewsMsg.java │ │ ├── QYNewsMsg.java │ │ ├── QYTextMsg.java │ │ ├── QYVideoMsg.java │ │ ├── QYVoiceMsg.java │ │ ├── req │ │ ├── QYBaseEvent.java │ │ ├── QYBaseReq.java │ │ ├── QYBaseReqMsg.java │ │ ├── QYBatchJobEvent.java │ │ ├── QYBatchJobType.java │ │ ├── QYEnterAgentEvent.java │ │ ├── QYEventType.java │ │ ├── QYImageReqMsg.java │ │ ├── QYLocationEvent.java │ │ ├── QYLocationReqMsg.java │ │ ├── QYMenuEvent.java │ │ ├── QYReqType.java │ │ ├── QYScanCodeEvent.java │ │ ├── QYSendLocationEvent.java │ │ ├── QYSendPicInfoEvent.java │ │ ├── QYTextReqMsg.java │ │ ├── QYVideoReqMsg.java │ │ └── QYVoiceReqMsg.java │ │ └── resp │ │ ├── QYBaseRespMsg.java │ │ ├── QYImageRespMsg.java │ │ ├── QYNewsRespMsg.java │ │ ├── QYTextRespMsg.java │ │ ├── QYVideoRespMsg.java │ │ └── QYVoiceRespMsg.java │ ├── exception │ └── WeixinException.java │ ├── handle │ ├── AbstractApiConfigChangeHandle.java │ ├── ApiConfigChangeHandle.java │ ├── EventHandle.java │ └── MessageHandle.java │ ├── message │ ├── Article.java │ ├── BaseMsg.java │ ├── CustomMsg.java │ ├── ImageMsg.java │ ├── MpNewsMsg.java │ ├── MusicMsg.java │ ├── NewsMsg.java │ ├── RespType.java │ ├── TextMsg.java │ ├── VideoMsg.java │ ├── VoiceMsg.java │ ├── aes │ │ ├── AesException.java │ │ ├── ByteGroup.java │ │ ├── PKCS7Encoder.java │ │ ├── SHA1.java │ │ ├── WXBizMsgCrypt.java │ │ └── XMLParse.java │ ├── req │ │ ├── BaseEvent.java │ │ ├── BaseReq.java │ │ ├── BaseReqMsg.java │ │ ├── EventType.java │ │ ├── ImageReqMsg.java │ │ ├── LinkReqMsg.java │ │ ├── LocationEvent.java │ │ ├── LocationReqMsg.java │ │ ├── MenuEvent.java │ │ ├── QrCodeEvent.java │ │ ├── ReqType.java │ │ ├── ScanCodeEvent.java │ │ ├── SendMessageEvent.java │ │ ├── SendPicsInfoEvent.java │ │ ├── TemplateMsgEvent.java │ │ ├── TextReqMsg.java │ │ ├── VideoReqMsg.java │ │ └── VoiceReqMsg.java │ └── util │ │ └── MessageBuilder.java │ ├── servlet │ ├── QYWeixinControllerSupport.java │ ├── QYWeixinServletSupport.java │ ├── QYWeixinSupport.java │ ├── WeixinControllerSupport.java │ ├── WeixinServletSupport.java │ └── WeixinSupport.java │ └── util │ ├── BeanUtil.java │ ├── CollectionUtil.java │ ├── JSONUtil.java │ ├── JsApiUtil.java │ ├── MessageUtil.java │ ├── NetWorkCenter.java │ ├── SignUtil.java │ ├── StrUtil.java │ └── StreamUtil.java └── test ├── java └── com │ └── github │ └── sd4324530 │ └── fastweixin │ ├── DownloadTest.java │ ├── FastweixinTest.java │ ├── QYFastweixinTest.java │ └── TestConfigChangeHandle.java └── resources └── logback-test.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .tern-project 3 | 4 | # Package Files # 5 | *.jar 6 | *.war 7 | *.ear 8 | 9 | # Intellij project files 10 | *.iml 11 | *.ipr 12 | *.iws 13 | .idea/ 14 | 15 | # Eclipse project files 16 | /.settings/ 17 | .classpath 18 | .project 19 | 20 | #target files 21 | /target/ 22 | 23 | #mac file 24 | .DS_STORE -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | install: mvn install -DskipTests=true -Dgpg.skip=true 3 | jdk: 4 | - openjdk8 -------------------------------------------------------------------------------- /alipay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sd4324530/fastweixin/6bc0a7abfa23aad0dbad4c3123a47a7fb53f3447/alipay.png -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | java: 3 | version: oraclejdk7 -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/config/ChangeType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.config; 2 | 3 | /** 4 | * 变化类型枚举 5 | * @author peiyu 6 | */ 7 | public enum ChangeType { 8 | /** 9 | * 微信token 10 | */ 11 | ACCESS_TOKEN, 12 | 13 | /** 14 | * 微信js token 15 | */ 16 | JS_TOKEN 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/config/ConfigChangeNotice.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.config; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * 配置变化通知 9 | * 10 | * @author peiyu 11 | */ 12 | public final class ConfigChangeNotice extends BaseModel { 13 | 14 | private Date noticeTime; 15 | 16 | private String appid; 17 | 18 | private ChangeType type; 19 | 20 | private String value; 21 | 22 | public ConfigChangeNotice() { 23 | this.noticeTime = new Date(); 24 | } 25 | 26 | public ConfigChangeNotice(String appid, ChangeType type, String value) { 27 | this(); 28 | this.appid = appid; 29 | this.type = type; 30 | this.value = value; 31 | } 32 | 33 | public String getAppid() { 34 | return appid; 35 | } 36 | 37 | public void setAppid(String appid) { 38 | this.appid = appid; 39 | } 40 | 41 | public ChangeType getType() { 42 | return type; 43 | } 44 | 45 | public void setType(ChangeType type) { 46 | this.type = type; 47 | } 48 | 49 | public String getValue() { 50 | return value; 51 | } 52 | 53 | public void setValue(String value) { 54 | this.value = value; 55 | } 56 | 57 | public Date getNoticeTime() { 58 | return noticeTime; 59 | } 60 | 61 | public void setNoticeTime(Date noticeTime) { 62 | this.noticeTime = noticeTime; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "ConfigChangeNotice{" + 68 | "noticeTime=" + noticeTime + 69 | ", appid='" + appid + '\'' + 70 | ", type=" + type + 71 | ", value='" + value + '\'' + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/ArticleTotal.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 图文群发总数据 7 | * 8 | * @author peiyu 9 | */ 10 | public class ArticleTotal extends BaseDataCube { 11 | 12 | private String msgid; 13 | private String title; 14 | private List details; 15 | 16 | public String getMsgid() { 17 | return msgid; 18 | } 19 | 20 | public void setMsgid(String msgid) { 21 | this.msgid = msgid; 22 | } 23 | 24 | public String getTitle() { 25 | return title; 26 | } 27 | 28 | public void setTitle(String title) { 29 | this.title = title; 30 | } 31 | 32 | public List getDetails() { 33 | return details; 34 | } 35 | 36 | public void setDetails(List details) { 37 | this.details = details; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/BaseDataCube.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class BaseDataCube extends BaseModel { 11 | 12 | @JSONField(name = "ref_date", format = "yyyy-MM-dd") 13 | private Date refDate; 14 | 15 | public Date getRefDate() { 16 | return refDate; 17 | } 18 | 19 | public void setRefDate(Date refDate) { 20 | this.refDate = refDate; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/BaseModel.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.github.sd4324530.fastweixin.util.JSONUtil; 4 | 5 | /** 6 | * 抽象实体类 7 | * 8 | * @author peiyu 9 | */ 10 | public abstract class BaseModel implements Model { 11 | @Override 12 | public String toJsonString() { 13 | return JSONUtil.toJson(this); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/CustomAccount.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 客服帐号对象 7 | * 8 | * @author peiyu 9 | */ 10 | public class CustomAccount extends BaseModel { 11 | 12 | @JSONField(name = "kf_account") 13 | private String accountName; 14 | 15 | @JSONField(name = "kf_nick") 16 | private String nickName; 17 | 18 | private String password; 19 | 20 | @JSONField(name = "kf_id") 21 | private String id; 22 | 23 | @JSONField(name = "kf_headimg") 24 | private String headImg; 25 | 26 | public String getAccountName() { 27 | return accountName; 28 | } 29 | 30 | public void setAccountName(String accountName) { 31 | this.accountName = accountName; 32 | } 33 | 34 | public String getNickName() { 35 | return nickName; 36 | } 37 | 38 | public void setNickName(String nickName) { 39 | this.nickName = nickName; 40 | } 41 | 42 | public String getPassword() { 43 | return password; 44 | } 45 | 46 | public void setPassword(String password) { 47 | this.password = password; 48 | } 49 | 50 | public String getId() { 51 | return id; 52 | } 53 | 54 | public void setId(String id) { 55 | this.id = id; 56 | } 57 | 58 | public String getHeadImg() { 59 | return headImg; 60 | } 61 | 62 | public void setHeadImg(String headImg) { 63 | this.headImg = headImg; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/Group.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | /** 3 | * 分组信息 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * ==================================================================== 9 | */ 10 | public class Group extends BaseModel { 11 | 12 | private Integer id; 13 | private String name; 14 | private Integer count; 15 | 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public Integer getCount() { 33 | return count; 34 | } 35 | 36 | public void setCount(Integer count) { 37 | this.count = count; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/Industry.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 设置行业参数 7 | */ 8 | public class Industry extends BaseModel { 9 | /** 10 | * 行业1 11 | */ 12 | @JSONField(name = "industry_id1") 13 | private String industryId1; 14 | /** 15 | * 行业2 16 | */ 17 | @JSONField(name = "industry_id2") 18 | private String industryId2; 19 | 20 | public String getIndustryId1() { 21 | return industryId1; 22 | } 23 | 24 | public void setIndustryId1(String industryId1) { 25 | this.industryId1 = industryId1; 26 | } 27 | 28 | public String getIndustryId2() { 29 | return industryId2; 30 | } 31 | 32 | public void setIndustryId2(String industryId2) { 33 | this.industryId2 = industryId2; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/InterfaceSummary.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class InterfaceSummary extends BaseDataCube { 9 | 10 | @JSONField(name = "callback_count") 11 | private Integer callbackCount; 12 | @JSONField(name = "fail_count") 13 | private Integer failCount; 14 | @JSONField(name = "total_time_cost") 15 | private Integer totalTimeCost; 16 | @JSONField(name = "max_time_cost") 17 | private Integer maxTimeCost; 18 | 19 | public Integer getCallbackCount() { 20 | return callbackCount; 21 | } 22 | 23 | public void setCallbackCount(Integer callbackCount) { 24 | this.callbackCount = callbackCount; 25 | } 26 | 27 | public Integer getFailCount() { 28 | return failCount; 29 | } 30 | 31 | public void setFailCount(Integer failCount) { 32 | this.failCount = failCount; 33 | } 34 | 35 | public Integer getTotalTimeCost() { 36 | return totalTimeCost; 37 | } 38 | 39 | public void setTotalTimeCost(Integer totalTimeCost) { 40 | this.totalTimeCost = totalTimeCost; 41 | } 42 | 43 | public Integer getMaxTimeCost() { 44 | return maxTimeCost; 45 | } 46 | 47 | public void setMaxTimeCost(Integer maxTimeCost) { 48 | this.maxTimeCost = maxTimeCost; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/InterfaceSummaryHour.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class InterfaceSummaryHour extends InterfaceSummary { 9 | 10 | @JSONField(name = "ref_hour") 11 | private Integer refHour; 12 | 13 | public Integer getRefHour() { 14 | return refHour; 15 | } 16 | 17 | public void setRefHour(Integer refHour) { 18 | this.refHour = refHour; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/Matchrule.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | * @since 1.3.7 8 | */ 9 | public class Matchrule extends BaseModel { 10 | 11 | @JSONField(name = "tag_id") 12 | private String tagId; 13 | 14 | @Deprecated 15 | @JSONField(name = "group_id") 16 | private String groupId; 17 | 18 | private String sex; 19 | 20 | private String country; 21 | 22 | private String province; 23 | 24 | private String city; 25 | 26 | @JSONField(name = "client_platform_type") 27 | private String clientPlatformType; 28 | 29 | /** 30 | * @deprecated 微信官方不再建议使用群组,用标签代替 31 | * @return 群组ID 32 | */ 33 | @Deprecated 34 | public String getGroupId() { 35 | return groupId; 36 | } 37 | 38 | /** 39 | * @deprecated 微信官方不再建议使用群组,用标签代替 40 | * @param groupId 群组ID 41 | */ 42 | @Deprecated 43 | public void setGroupId(String groupId) { 44 | this.groupId = groupId; 45 | } 46 | 47 | public String getSex() { 48 | return sex; 49 | } 50 | 51 | public void setSex(String sex) { 52 | this.sex = sex; 53 | } 54 | 55 | public String getCountry() { 56 | return country; 57 | } 58 | 59 | public void setCountry(String country) { 60 | this.country = country; 61 | } 62 | 63 | public String getProvince() { 64 | return province; 65 | } 66 | 67 | public void setProvince(String province) { 68 | this.province = province; 69 | } 70 | 71 | public String getCity() { 72 | return city; 73 | } 74 | 75 | public void setCity(String city) { 76 | this.city = city; 77 | } 78 | 79 | public String getClientPlatformType() { 80 | return clientPlatformType; 81 | } 82 | 83 | public void setClientPlatformType(String clientPlatformType) { 84 | this.clientPlatformType = clientPlatformType; 85 | } 86 | 87 | public String getTagId() { 88 | return tagId; 89 | } 90 | 91 | public void setTagId(String tagId) { 92 | this.tagId = tagId; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.exception.WeixinException; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 菜单对象,包含所有菜单按钮 10 | * 11 | * @author peiyu 12 | */ 13 | public class Menu extends BaseModel { 14 | 15 | /** 16 | * 一级菜单列表,最多3个 17 | */ 18 | private List button; 19 | 20 | /** 21 | * 菜单匹配规则 22 | * 23 | * @since 1.3.7 24 | */ 25 | private Matchrule matchrule; 26 | 27 | /** 28 | * 菜单ID,查询时会返回,删除个性化菜单时会用到 29 | * 30 | * @since 1.3.7 31 | */ 32 | @JSONField(name = "menuid") 33 | private String menuId; 34 | 35 | public List getButton() { 36 | return button; 37 | } 38 | 39 | public void setButton(List button) { 40 | if (null == button || button.size() > 3) { 41 | throw new WeixinException("主菜单最多3个"); 42 | } 43 | this.button = button; 44 | } 45 | 46 | public Matchrule getMatchrule() { 47 | return matchrule; 48 | } 49 | 50 | public void setMatchrule(Matchrule matchrule) { 51 | this.matchrule = matchrule; 52 | } 53 | 54 | public String getMenuId() { 55 | return menuId; 56 | } 57 | 58 | public void setMenuId(String menuId) { 59 | this.menuId = menuId; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/MenuButton.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.enums.MenuType; 5 | import com.github.sd4324530.fastweixin.exception.WeixinException; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 菜单按钮对象 11 | * 12 | * @author peiyu 13 | */ 14 | public class MenuButton extends BaseModel { 15 | 16 | /** 17 | * 菜单类别 18 | */ 19 | private MenuType type; 20 | 21 | /** 22 | * 菜单上显示的文字 23 | */ 24 | private String name; 25 | 26 | /** 27 | * 菜单key,当MenuType值为CLICK时用于区别菜单 28 | */ 29 | private String key; 30 | 31 | /** 32 | * 菜单跳转的URL,当MenuType值为VIEW时用 33 | */ 34 | private String url; 35 | 36 | /** 37 | * 菜单显示的永久素材的MaterialID,当MenuType值为media_id和view_limited时必需 38 | */ 39 | @JSONField(name = "media_id") 40 | private String mediaId; 41 | 42 | /** 43 | * 二级菜单列表,每个一级菜单下最多5个 44 | */ 45 | @JSONField(name = "sub_button") 46 | private List subButton; 47 | 48 | public MenuType getType() { 49 | return type; 50 | } 51 | 52 | public void setType(MenuType type) { 53 | this.type = type; 54 | } 55 | 56 | public String getName() { 57 | return name; 58 | } 59 | 60 | public void setName(String name) { 61 | this.name = name; 62 | } 63 | 64 | public String getKey() { 65 | return key; 66 | } 67 | 68 | public void setKey(String key) { 69 | this.key = key; 70 | } 71 | 72 | public String getUrl() { 73 | return url; 74 | } 75 | 76 | public void setUrl(String url) { 77 | this.url = url; 78 | } 79 | 80 | public String getMediaId() { 81 | return mediaId; 82 | } 83 | 84 | public void setMediaId(String mediaId) { 85 | this.mediaId = mediaId; 86 | } 87 | 88 | public List getSubButton() { 89 | return subButton; 90 | } 91 | 92 | public void setSubButton(List subButton) { 93 | if (null == subButton || subButton.size() > 5) { 94 | throw new WeixinException("子菜单最多只有5个"); 95 | } 96 | this.subButton = subButton; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/Model.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 模型接口,所有需要传输的对象都需要实现,提供转json的方法 7 | * 8 | * @author peiyu 9 | */ 10 | public interface Model extends Serializable { 11 | 12 | /** 13 | * 将model转成json字符串 14 | * 15 | * @return json字符串 16 | */ 17 | String toJsonString(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/Tag.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | /** 4 | * 标签对象 5 | * @author peiyu 6 | * @since 1.3.9 7 | */ 8 | public class Tag extends BaseModel { 9 | 10 | private Integer id; 11 | 12 | private String name; 13 | 14 | private Integer count; 15 | 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public Integer getCount() { 33 | return count; 34 | } 35 | 36 | public void setCount(Integer count) { 37 | this.count = count; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/TemplateMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * 模版消息 9 | */ 10 | public class TemplateMsg extends BaseModel { 11 | private String touser; 12 | @JSONField(name = "template_id") 13 | private String templateId; 14 | private String url; 15 | @Deprecated 16 | private String topcolor; 17 | 18 | private Map data; 19 | 20 | public String getTouser() { 21 | return touser; 22 | } 23 | 24 | public void setTouser(String touser) { 25 | this.touser = touser; 26 | } 27 | 28 | public String getTemplateId() { 29 | return templateId; 30 | } 31 | 32 | public void setTemplateId(String templateId) { 33 | this.templateId = templateId; 34 | } 35 | 36 | public String getUrl() { 37 | return url; 38 | } 39 | 40 | public void setUrl(String url) { 41 | this.url = url; 42 | } 43 | 44 | @Deprecated 45 | public String getTopcolor() { 46 | return topcolor; 47 | } 48 | 49 | @Deprecated 50 | public void setTopcolor(String topcolor) { 51 | this.topcolor = topcolor; 52 | } 53 | 54 | public Map getData() { 55 | return data; 56 | } 57 | 58 | public void setData(Map data) { 59 | this.data = data; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/TemplateParam.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | /** 4 | * 模版参数 5 | */ 6 | public class TemplateParam extends BaseModel { 7 | 8 | /** 9 | * 值 10 | */ 11 | private String value; 12 | /** 13 | * 颜色 14 | */ 15 | private String color; 16 | 17 | public TemplateParam() { 18 | super(); 19 | } 20 | 21 | public TemplateParam(String value) { 22 | super(); 23 | this.value = value; 24 | } 25 | 26 | public TemplateParam(String value, String color) { 27 | super(); 28 | this.value = value; 29 | this.color = color; 30 | } 31 | 32 | public String getValue() { 33 | return value; 34 | } 35 | 36 | public void setValue(String value) { 37 | this.value = value; 38 | } 39 | 40 | public String getColor() { 41 | return color; 42 | } 43 | 44 | public void setColor(String color) { 45 | this.color = color; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UpstreamMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class UpstreamMsg extends BaseDataCube { 9 | 10 | @JSONField(name = "msg_type") 11 | private Integer msgType; 12 | @JSONField(name = "msg_user") 13 | private Integer msgUser; 14 | @JSONField(name = "msg_count") 15 | private Integer msgCount; 16 | 17 | public Integer getMsgType() { 18 | return msgType; 19 | } 20 | 21 | public void setMsgType(Integer msgType) { 22 | this.msgType = msgType; 23 | } 24 | 25 | public Integer getMsgUser() { 26 | return msgUser; 27 | } 28 | 29 | public void setMsgUser(Integer msgUser) { 30 | this.msgUser = msgUser; 31 | } 32 | 33 | public Integer getMsgCount() { 34 | return msgCount; 35 | } 36 | 37 | public void setMsgCount(Integer msgCount) { 38 | this.msgCount = msgCount; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UpstreamMsgDist.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class UpstreamMsgDist extends BaseDataCube { 9 | 10 | @JSONField(name = "count_interval") 11 | private Integer countInterval; 12 | @JSONField(name = "msg_user") 13 | private Integer msgUser; 14 | 15 | public Integer getCountInterval() { 16 | return countInterval; 17 | } 18 | 19 | public void setCountInterval(Integer countInterval) { 20 | this.countInterval = countInterval; 21 | } 22 | 23 | public Integer getMsgUser() { 24 | return msgUser; 25 | } 26 | 27 | public void setMsgUser(Integer msgUser) { 28 | this.msgUser = msgUser; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UpstreamMsgDistMonth.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public class UpstreamMsgDistMonth extends UpstreamMsgDist { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UpstreamMsgDistWeek.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public class UpstreamMsgDistWeek extends UpstreamMsgDist { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UpstreamMsgHour.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 消息分送分时数据 7 | * @author peiyu 8 | */ 9 | public class UpstreamMsgHour extends BaseDataCube { 10 | 11 | @JSONField(name = "ref_hour") 12 | private Integer refHour; 13 | @JSONField(name = "msg_type") 14 | private Integer msgType; 15 | @JSONField(name = "msg_user") 16 | private Integer msgUser; 17 | @JSONField(name = "msg_count") 18 | private Integer msgCount; 19 | 20 | public Integer getRefHour() { 21 | return refHour; 22 | } 23 | 24 | public void setRefHour(Integer refHour) { 25 | this.refHour = refHour; 26 | } 27 | 28 | public Integer getMsgType() { 29 | return msgType; 30 | } 31 | 32 | public void setMsgType(Integer msgType) { 33 | this.msgType = msgType; 34 | } 35 | 36 | public Integer getMsgUser() { 37 | return msgUser; 38 | } 39 | 40 | public void setMsgUser(Integer msgUser) { 41 | this.msgUser = msgUser; 42 | } 43 | 44 | public Integer getMsgCount() { 45 | return msgCount; 46 | } 47 | 48 | public void setMsgCount(Integer msgCount) { 49 | this.msgCount = msgCount; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UpstreamMsgMonth.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public class UpstreamMsgMonth extends UpstreamMsg { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UpstreamMsgWeek.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public class UpstreamMsgWeek extends UpstreamMsg { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UserCumulate.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 累计用户数据 7 | * 8 | * @author peiyu 9 | */ 10 | public class UserCumulate extends BaseDataCube { 11 | 12 | @JSONField(name = "cumulate_user") 13 | private Integer cumulateUser; 14 | 15 | public Integer getCumulateUser() { 16 | return cumulateUser; 17 | } 18 | 19 | public void setCumulateUser(Integer cumulateUser) { 20 | this.cumulateUser = cumulateUser; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | /** 4 | * @author Nottyjay 5 | */ 6 | public class UserInfo extends BaseModel{ 7 | private String openid; 8 | private String lang="zh_CN"; 9 | public UserInfo(){ 10 | 11 | } 12 | public UserInfo(String openid){ 13 | this.openid=openid; 14 | } 15 | public UserInfo(String openid, String lang){ 16 | this.openid=openid; 17 | this.lang=lang; 18 | } 19 | public String getOpenid() { 20 | return openid; 21 | } 22 | 23 | public void setOpenid(String openid) { 24 | this.openid = openid; 25 | } 26 | 27 | public String getLang() { 28 | return lang; 29 | } 30 | 31 | public void setLang(String lang) { 32 | this.lang = lang; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UserShare.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class UserShare extends BaseDataCube { 9 | 10 | @JSONField(name = "share_scene") 11 | private Integer shareScene; 12 | @JSONField(name = "share_count") 13 | private Integer shareCount; 14 | @JSONField(name = "share_user") 15 | private Integer shareUser; 16 | 17 | public Integer getShareScene() { 18 | return shareScene; 19 | } 20 | 21 | public void setShareScene(Integer shareScene) { 22 | this.shareScene = shareScene; 23 | } 24 | 25 | public Integer getShareCount() { 26 | return shareCount; 27 | } 28 | 29 | public void setShareCount(Integer shareCount) { 30 | this.shareCount = shareCount; 31 | } 32 | 33 | public Integer getShareUser() { 34 | return shareUser; 35 | } 36 | 37 | public void setShareUser(Integer shareUser) { 38 | this.shareUser = shareUser; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UserShareHour.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class UserShareHour extends BaseDataCube { 9 | 10 | @JSONField(name = "ref_hour") 11 | private Integer refHour; 12 | @JSONField(name = "share_scene") 13 | private Integer shareScene; 14 | @JSONField(name = "share_count") 15 | private Integer shareCount; 16 | @JSONField(name = "share_user") 17 | private Integer shareUser; 18 | 19 | public Integer getRefHour() { 20 | return refHour; 21 | } 22 | 23 | public void setRefHour(Integer refHour) { 24 | this.refHour = refHour; 25 | } 26 | 27 | public Integer getShareScene() { 28 | return shareScene; 29 | } 30 | 31 | public void setShareScene(Integer shareScene) { 32 | this.shareScene = shareScene; 33 | } 34 | 35 | public Integer getShareCount() { 36 | return shareCount; 37 | } 38 | 39 | public void setShareCount(Integer shareCount) { 40 | this.shareCount = shareCount; 41 | } 42 | 43 | public Integer getShareUser() { 44 | return shareUser; 45 | } 46 | 47 | public void setShareUser(Integer shareUser) { 48 | this.shareUser = shareUser; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/entity/UserSummary.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 用户增减数据 7 | * 8 | * @author peiyu 9 | */ 10 | public class UserSummary extends BaseDataCube { 11 | 12 | /** 13 | * 用户的渠道,数值代表的含义如下: 14 | * 0代表其他 30代表扫二维码 17代表名片分享 35代表搜号码(即微信添加朋友页的搜索) 39代表查询微信公众帐号 43代表图文页右上角菜单 15 | */ 16 | @JSONField(name = "user_source") 17 | private Integer userSource; 18 | /** 19 | * 新增的用户数量 20 | */ 21 | @JSONField(name = "new_user") 22 | private Integer newUser; 23 | /** 24 | * 取消关注的用户数量,new_user减去cancel_user即为净增用户数量 25 | */ 26 | @JSONField(name = "cancel_user") 27 | private Integer cancelUser; 28 | 29 | public Integer getUserSource() { 30 | return userSource; 31 | } 32 | 33 | public void setUserSource(Integer userSource) { 34 | this.userSource = userSource; 35 | } 36 | 37 | public Integer getNewUser() { 38 | return newUser; 39 | } 40 | 41 | public void setNewUser(Integer newUser) { 42 | this.newUser = newUser; 43 | } 44 | 45 | public Integer getCancelUser() { 46 | return cancelUser; 47 | } 48 | 49 | public void setCancelUser(Integer cancelUser) { 50 | this.cancelUser = cancelUser; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/enums/MaterialType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.enums; 2 | 3 | /** 4 | * @author jileilei 5 | */ 6 | public enum MaterialType { 7 | 8 | /** 9 | * 图片 10 | */ 11 | IMAGE("image"), 12 | 13 | /** 14 | * 语音 15 | */ 16 | VOICE("voice"), 17 | 18 | /** 19 | * 视频 20 | */ 21 | VIDEO("video"), 22 | 23 | /** 24 | * 图文消息 25 | */ 26 | NEWS("news"); 27 | 28 | String value; 29 | 30 | MaterialType(String value) { 31 | this.value = value; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return this.value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/enums/MediaType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.enums; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public enum MediaType { 7 | 8 | /** 9 | * 图片 10 | */ 11 | IMAGE("image"), 12 | 13 | /** 14 | * 语音 15 | */ 16 | VOICE("voice"), 17 | 18 | /** 19 | * 视频 20 | */ 21 | VIDEO("video"), 22 | 23 | /** 24 | * 缩略图 25 | */ 26 | THUMB("thumb"), 27 | 28 | /** 29 | * 图文消息 30 | */ 31 | NEWS("news"); 32 | 33 | String value; 34 | 35 | MediaType(String value) { 36 | this.value = value; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return this.value; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/enums/MenuType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.enums; 2 | 3 | /** 4 | * 微信菜单类型枚举 5 | * 6 | * @author peiyu 7 | * @since 1.2 8 | */ 9 | public enum MenuType { 10 | /** 11 | * 点击推事件 12 | */ 13 | CLICK("click"), 14 | 15 | /** 16 | * 跳转URL 17 | */ 18 | VIEW("view"), 19 | 20 | /*-------------------------以下仅支持微信iPhone5.4.1以上版本,和Android5.4以上版本的微信用户------------------------*/ 21 | 22 | /** 23 | * 扫码推事件 24 | */ 25 | SCANCODE_PUSH("scancode_push"), 26 | 27 | /** 28 | * 扫码推事件且弹出“消息接收中”提示框 29 | */ 30 | SCANCODE_WAITMSG("scancode_waitmsg"), 31 | 32 | /** 33 | * 弹出系统拍照发图 34 | */ 35 | PIC_SYSPHOTO("pic_sysphoto"), 36 | 37 | /** 38 | * 弹出拍照或者相册发图 39 | */ 40 | PIC_PHOTO_OR_ALBUM("pic_photo_or_album"), 41 | 42 | /** 43 | * 弹出微信相册发图器 44 | */ 45 | PIC_WEIXIN("pic_weixin"), 46 | 47 | /** 48 | * 弹出地理位置选择器 49 | */ 50 | LOCATION_SELECT("location_select"), 51 | 52 | 53 | /*-----------------------------以下专门给第三方平台旗下未微信认证(具体而言,是资质认证未通过)的订阅号准备的事件类型,它们是没有事件推送的,能力相对受限,其他类型的公众号不必使用--------------------------*/ 54 | 55 | /** 56 | * 下发消息(除文本消息) 57 | */ 58 | MEDIA_ID("media_id"), 59 | 60 | /** 61 | * 跳转图文消息URL 62 | */ 63 | VIEW_LIMITED("view_limited"); 64 | 65 | String value; 66 | 67 | MenuType(String value) { 68 | this.value = value; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return this.value; 74 | } 75 | 76 | } 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/enums/OauthScope.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.enums; 2 | 3 | /** 4 | * Oauth授权作用域枚举 5 | * 6 | * @author peiyu 7 | */ 8 | public enum OauthScope { 9 | 10 | /** 11 | * 仅仅获取用户openid 12 | */ 13 | SNSAPI_BASE("snsapi_base"), 14 | 15 | /** 16 | * 获取用户完整信息 17 | */ 18 | SNSAPI_USERINFO("snsapi_userinfo"); 19 | 20 | String value; 21 | 22 | OauthScope(String value) { 23 | this.value = value; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return this.value; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/enums/QrcodeType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.enums; 2 | 3 | /** 4 | * 二维码接口状态枚举 5 | * 6 | * @author peiyu 7 | * @since 1.2 8 | */ 9 | public enum QrcodeType { 10 | 11 | /** 12 | * 临时二维码 13 | */ 14 | QR_SCENE, 15 | 16 | /** 17 | * 永久二维码 18 | */ 19 | QR_LIMIT_SCENE, 20 | 21 | /** 22 | * 永久的字符串参数值 23 | */ 24 | QR_LIMIT_STR_SCENE 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/request/BaseRequest.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.request; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class BaseRequest extends BaseModel { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/AddTemplateResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 添加模版响应 7 | */ 8 | public class AddTemplateResponse extends BaseResponse { 9 | /** 10 | * 模版id 11 | */ 12 | @JSONField(name = "template_id") 13 | private String templateId; 14 | 15 | public String getTemplateId() { 16 | return templateId; 17 | } 18 | 19 | public void setTemplateId(String templateId) { 20 | this.templateId = templateId; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 4 | import com.github.sd4324530.fastweixin.api.enums.ResultType; 5 | import com.github.sd4324530.fastweixin.util.BeanUtil; 6 | import com.github.sd4324530.fastweixin.util.StrUtil; 7 | 8 | /** 9 | * 微信API响应报文对象基类 10 | * 11 | * @author peiyu 12 | */ 13 | public class BaseResponse extends BaseModel { 14 | 15 | private String errcode; 16 | private String errmsg; 17 | 18 | public String getErrcode() { 19 | return errcode; 20 | } 21 | 22 | public void setErrcode(String errcode) { 23 | this.errcode = errcode; 24 | } 25 | 26 | public String getErrmsg() { 27 | String result = this.errmsg; 28 | //将接口返回的错误信息转换成中文,方便提示用户出错原因 29 | if (StrUtil.isNotBlank(this.errcode) && !ResultType.SUCCESS.getCode().toString().equals(this.errcode)) { 30 | ResultType resultType = ResultType.get(this.errcode); 31 | if(BeanUtil.nonNull(resultType)) { 32 | result = resultType.getDescription(); 33 | } 34 | } 35 | return result; 36 | } 37 | 38 | public void setErrmsg(String errmsg) { 39 | this.errmsg = errmsg; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/CreateGroupResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.Group; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class CreateGroupResponse extends BaseResponse { 9 | 10 | // private String id; 11 | // private String name; 12 | // 13 | // public String getId() { 14 | // return id; 15 | // } 16 | // 17 | // public void setId(String id) { 18 | // this.id = id; 19 | // } 20 | // 21 | // public String getName() { 22 | // return name; 23 | // } 24 | // 25 | // public void setName(String name) { 26 | // this.name = name; 27 | // } 28 | 29 | private Group group; 30 | 31 | public Group getGroup() { 32 | return group; 33 | } 34 | 35 | public void setGroup(Group group) { 36 | this.group = group; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/CreateTagResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.Tag; 4 | 5 | /** 6 | * @author peiyu 7 | * @since 1.3.9 8 | */ 9 | public class CreateTagResponse extends BaseResponse { 10 | 11 | private Tag tag; 12 | 13 | public Tag getTag() { 14 | return tag; 15 | } 16 | 17 | public void setTag(Tag tag) { 18 | this.tag = tag; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/DownloadMediaResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.util.StreamUtil; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.OutputStream; 11 | 12 | /** 13 | * 下载多媒体资源响应对象 14 | * 15 | * @author peiyu 16 | */ 17 | public class DownloadMediaResponse extends BaseResponse { 18 | 19 | private static final Logger LOG = LoggerFactory.getLogger(DownloadMediaResponse.class); 20 | private String fileName; 21 | private byte[] content; 22 | 23 | public String getFileName() { 24 | return fileName; 25 | } 26 | 27 | public void setFileName(String fileName) { 28 | this.fileName = fileName; 29 | } 30 | 31 | public void setContent(InputStream content, Integer length) { 32 | ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); 33 | try { 34 | StreamUtil.copy(content, byteOutputStream); 35 | byte[] temp = byteOutputStream.toByteArray(); 36 | if (temp.length > length) { 37 | this.content = new byte[length]; 38 | System.arraycopy(temp, 0, this.content, 0, length); 39 | } else { 40 | this.content = temp; 41 | } 42 | } catch (IOException e) { 43 | LOG.error("异常", e); 44 | } 45 | } 46 | 47 | /** 48 | * 如果成功,则可以靠这个方法将数据输出 49 | * 50 | * @param out 调用者给的输出流 51 | * @throws IOException 写流出现异常 52 | */ 53 | public void writeTo(OutputStream out) throws IOException { 54 | out.write(this.content); 55 | out.flush(); 56 | out.close(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetAllTagsResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.Tag; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | * @since 1.3.9 10 | */ 11 | public class GetAllTagsResponse extends BaseResponse { 12 | 13 | private List tags; 14 | 15 | public List getTags() { 16 | return tags; 17 | } 18 | 19 | public void setTags(List tags) { 20 | this.tags = tags; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetArticleSummaryResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.ArticleSummary; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetArticleSummaryResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetArticleTotalResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.ArticleTotal; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetArticleTotalResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetCustomAccountsResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.entity.CustomAccount; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author peiyu 10 | */ 11 | public class GetCustomAccountsResponse extends BaseResponse { 12 | 13 | @JSONField(name = "kf_list") 14 | private List customAccountList; 15 | 16 | public List getCustomAccountList() { 17 | return customAccountList; 18 | } 19 | 20 | public void setCustomAccountList(List customAccountList) { 21 | this.customAccountList = customAccountList; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetGroupsResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.Group; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 新建实体类Group,将id,name,count属性移动到Group实体中。本实体采用List封装Groups信息 9 | * 10 | * @author peiyu, Nottyjay 11 | * 12 | */ 13 | public class GetGroupsResponse extends BaseResponse { 14 | 15 | // private Integer id; 16 | // private String name; 17 | // private Integer count; 18 | // 19 | // public Integer getId() { 20 | // return id; 21 | // } 22 | // 23 | // public void setId(Integer id) { 24 | // this.id = id; 25 | // } 26 | // 27 | // public String getName() { 28 | // return name; 29 | // } 30 | // 31 | // public void setName(String name) { 32 | // this.name = name; 33 | // } 34 | // 35 | // public Integer getCount() { 36 | // return count; 37 | // } 38 | // 39 | // public void setCount(Integer count) { 40 | // this.count = count; 41 | // } 42 | 43 | private List groups; 44 | 45 | public List getGroups() { 46 | return groups; 47 | } 48 | 49 | public void setGroups(List groups) { 50 | this.groups = groups; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetInterfaceSummaryHourResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.InterfaceSummaryHour; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetInterfaceSummaryHourResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetInterfaceSummaryResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.InterfaceSummary; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetInterfaceSummaryResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetJsApiTicketResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author daxiaoming 7 | */ 8 | public class GetJsApiTicketResponse extends BaseResponse { 9 | 10 | private String ticket; 11 | 12 | @JSONField(name = "expires_in") 13 | private Integer expiresIn; 14 | 15 | public String getTicket() { 16 | return ticket; 17 | } 18 | 19 | public void setTicket(String ticket) { 20 | this.ticket = ticket; 21 | } 22 | 23 | public Integer getExpiresIn() { 24 | return expiresIn; 25 | } 26 | 27 | public void setExpiresIn(Integer expiresIn) { 28 | this.expiresIn = expiresIn; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetMaterialListResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.message.Article; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * 13 | * ==================================================================== 14 | * 上海聚攒软件开发有限公司 15 | * -------------------------------------------------------------------- 16 | * @author Nottyjay 17 | * @version 1.0.beta 18 | * ==================================================================== 19 | */ 20 | public class GetMaterialListResponse extends BaseResponse { 21 | 22 | private static final Logger LOG = LoggerFactory.getLogger(GetMaterialListResponse.class); 23 | 24 | @JSONField(name="total_count") 25 | private int totalCount;// 该类型素材总数 26 | @JSONField(name="item_count") 27 | private int itemCount;// 本次获取的数量 28 | @JSONField(name="item") 29 | private List> items; 30 | 31 | public int getTotalCount() { 32 | return totalCount; 33 | } 34 | 35 | public void setTotalCount(int totalCount) { 36 | this.totalCount = totalCount; 37 | } 38 | 39 | public int getItemCount() { 40 | return itemCount; 41 | } 42 | 43 | public void setItemCount(int itemCount) { 44 | this.itemCount = itemCount; 45 | } 46 | 47 | public List> getItems() { 48 | return items; 49 | } 50 | 51 | public void setItems(List> items) { 52 | this.items = items; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetMaterialTotalCountResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * ==================================================================== 13 | */ 14 | public class GetMaterialTotalCountResponse extends BaseResponse { 15 | 16 | @JSONField(name="video_count") 17 | private int video; 18 | @JSONField(name="voice_count") 19 | private int voice; 20 | @JSONField(name="image_count") 21 | private int image; 22 | @JSONField(name="news_count") 23 | private int news; 24 | 25 | public int getVideo() { 26 | return video; 27 | } 28 | 29 | public void setVideo(int video) { 30 | this.video = video; 31 | } 32 | 33 | public int getVoice() { 34 | return voice; 35 | } 36 | 37 | public void setVoice(int voice) { 38 | this.voice = voice; 39 | } 40 | 41 | public int getImage() { 42 | return image; 43 | } 44 | 45 | public void setImage(int image) { 46 | this.image = image; 47 | } 48 | 49 | public int getNews() { 50 | return news; 51 | } 52 | 53 | public void setNews(int news) { 54 | this.news = news; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "GetMaterialTotalCountResponse{" + 60 | "video=" + video + 61 | ", voice=" + voice + 62 | ", image=" + image + 63 | ", news=" + news + 64 | '}'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetMenuResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.Menu; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class GetMenuResponse extends BaseResponse { 9 | 10 | private Menu menu; 11 | 12 | public Menu getMenu() { 13 | return menu; 14 | } 15 | 16 | public void setMenu(Menu menu) { 17 | this.menu = menu; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetSendMessageResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 获取群发消息结果 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * ==================================================================== 13 | */ 14 | public class GetSendMessageResponse extends BaseResponse { 15 | 16 | @JSONField(name="msg_id") 17 | private String msgId; 18 | 19 | public String getMsgId() { 20 | return msgId; 21 | } 22 | 23 | public void setMsgId(String msgId) { 24 | this.msgId = msgId; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetSignatureResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public class GetSignatureResponse extends BaseResponse { 7 | 8 | private String noncestr; 9 | private long timestamp; 10 | private String url; 11 | private String signature; 12 | 13 | public String getNoncestr() { 14 | return noncestr; 15 | } 16 | 17 | public void setNoncestr(String noncestr) { 18 | this.noncestr = noncestr; 19 | } 20 | 21 | public long getTimestamp() { 22 | return timestamp; 23 | } 24 | 25 | public void setTimestamp(long timestamp) { 26 | this.timestamp = timestamp; 27 | } 28 | 29 | public String getUrl() { 30 | return url; 31 | } 32 | 33 | public void setUrl(String url) { 34 | this.url = url; 35 | } 36 | 37 | public String getSignature() { 38 | return signature; 39 | } 40 | 41 | public void setSignature(String signature) { 42 | this.signature = signature; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetTokenResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class GetTokenResponse extends BaseResponse { 9 | 10 | @JSONField(name = "access_token") 11 | private String accessToken; 12 | @JSONField(name = "expires_in") 13 | private Integer expiresIn; 14 | 15 | public String getAccessToken() { 16 | return accessToken; 17 | } 18 | 19 | public void setAccessToken(String accessToken) { 20 | this.accessToken = accessToken; 21 | } 22 | 23 | public Integer getExpiresIn() { 24 | return expiresIn; 25 | } 26 | 27 | public void setExpiresIn(Integer expiresIn) { 28 | this.expiresIn = expiresIn; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUpstreamMsgDistMonthResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UpstreamMsgDistMonth; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUpstreamMsgDistMonthResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUpstreamMsgDistResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UpstreamMsgDist; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUpstreamMsgDistResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUpstreamMsgDistWeekResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UpstreamMsgDistWeek; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUpstreamMsgDistWeekResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUpstreamMsgHourResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UpstreamMsgHour; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUpstreamMsgHourResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUpstreamMsgMonthResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UpstreamMsgMonth; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUpstreamMsgMonthResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUpstreamMsgResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UpstreamMsg; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUpstreamMsgResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUpstreamMsgWeekResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UpstreamMsgWeek; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUpstreamMsgWeekResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUserCumulateResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UserCumulate; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUserCumulateResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUserInfoListResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author Nottyjay 7 | */ 8 | public class GetUserInfoListResponse extends BaseResponse{ 9 | private List user_info_list; 10 | 11 | public List getUser_info_list() { 12 | return user_info_list; 13 | } 14 | 15 | public void setUser_info_list(List user_info_list) { 16 | this.user_info_list = user_info_list; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUserReadHourResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UserReadHour; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUserReadHourResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUserReadResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UserRead; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUserReadResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUserShareHourResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UserShareHour; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUserShareHourResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUserShareResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UserShare; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUserShareResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUserSummaryResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.UserSummary; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUserSummaryResponse extends BaseResponse { 11 | 12 | private List list; 13 | 14 | public List getList() { 15 | return list; 16 | } 17 | 18 | public void setList(List list) { 19 | this.list = list; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/GetUsersResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class GetUsersResponse extends BaseResponse { 11 | 12 | private long total; 13 | private int count; 14 | private Openid data; 15 | @JSONField(name = "next_openid") 16 | private String nextOpenid; 17 | 18 | public long getTotal() { 19 | return total; 20 | } 21 | 22 | public void setTotal(long total) { 23 | this.total = total; 24 | } 25 | 26 | public int getCount() { 27 | return count; 28 | } 29 | 30 | public void setCount(int count) { 31 | this.count = count; 32 | } 33 | 34 | public Openid getData() { 35 | return data; 36 | } 37 | 38 | public void setData(Openid data) { 39 | this.data = data; 40 | } 41 | 42 | public String getNextOpenid() { 43 | return nextOpenid; 44 | } 45 | 46 | public void setNextOpenid(String nextOpenid) { 47 | this.nextOpenid = nextOpenid; 48 | } 49 | 50 | public class Openid implements Serializable { 51 | private String[] openid; 52 | 53 | public String[] getOpenid() { 54 | return openid; 55 | } 56 | 57 | public void setOpenid(String[] openid) { 58 | this.openid = openid; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/OauthGetTokenResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * Oauth授权获取token接口响应对象 7 | * @author peiyu 8 | */ 9 | public class OauthGetTokenResponse extends GetTokenResponse { 10 | 11 | @JSONField(name = "refresh_token") 12 | private String refreshToken; 13 | 14 | private String openid; 15 | 16 | private String scope; 17 | 18 | private String unionid; 19 | 20 | public String getRefreshToken() { 21 | return refreshToken; 22 | } 23 | 24 | public void setRefreshToken(String refreshToken) { 25 | this.refreshToken = refreshToken; 26 | } 27 | 28 | public String getOpenid() { 29 | return openid; 30 | } 31 | 32 | public void setOpenid(String openid) { 33 | this.openid = openid; 34 | } 35 | 36 | public String getScope() { 37 | return scope; 38 | } 39 | 40 | public void setScope(String scope) { 41 | this.scope = scope; 42 | } 43 | 44 | public String getUnionid() { 45 | return unionid; 46 | } 47 | 48 | public void setUnionid(String unionid) { 49 | this.unionid = unionid; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/PrivateTemplate.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 5 | 6 | /** 7 | * 获取已添加至帐号下所有模板 8 | * @author wuwentao 9 | */ 10 | public class PrivateTemplate extends BaseModel { 11 | 12 | /** 13 | * 模板ID 14 | */ 15 | @JSONField(name="template_id") 16 | private String templateId; 17 | 18 | /** 19 | * 模板标题 20 | */ 21 | private String title; 22 | 23 | /** 24 | * 模板所属行业的一级行业 25 | */ 26 | @JSONField(name="primary_industry") 27 | private String primaryIndustry; 28 | 29 | /** 30 | * 模板所属行业的二级行业 31 | */ 32 | @JSONField(name="deputy_industry") 33 | private String deputyIndustry; 34 | 35 | /** 36 | * 模板内容 37 | */ 38 | private String content; 39 | 40 | /** 41 | * 模板示例 42 | */ 43 | private String example; 44 | 45 | /** 46 | * 模板备注 47 | */ 48 | private String remark; 49 | 50 | public String getTemplateId() { 51 | return templateId; 52 | } 53 | 54 | public void setTemplateId(String templateId) { 55 | this.templateId = templateId; 56 | } 57 | 58 | public String getTitle() { 59 | return title; 60 | } 61 | 62 | public void setTitle(String title) { 63 | this.title = title; 64 | } 65 | 66 | public String getPrimaryIndustry() { 67 | return primaryIndustry; 68 | } 69 | 70 | public void setPrimaryIndustry(String primaryIndustry) { 71 | this.primaryIndustry = primaryIndustry; 72 | } 73 | 74 | public String getDeputyIndustry() { 75 | return deputyIndustry; 76 | } 77 | 78 | public void setDeputyIndustry(String deputyIndustry) { 79 | this.deputyIndustry = deputyIndustry; 80 | } 81 | 82 | public String getContent() { 83 | return content; 84 | } 85 | 86 | public void setContent(String content) { 87 | this.content = content; 88 | } 89 | 90 | public String getExample() { 91 | return example; 92 | } 93 | 94 | public void setExample(String example) { 95 | this.example = example; 96 | } 97 | 98 | public String getRemark() { 99 | return remark; 100 | } 101 | 102 | public void setRemark(String remark) { 103 | this.remark = remark; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/QrcodeResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class QrcodeResponse extends BaseResponse { 9 | 10 | private String ticket; 11 | @JSONField(name = "expire_seconds") 12 | private Integer expireSeconds; 13 | private String url; 14 | 15 | public String getTicket() { 16 | return ticket; 17 | } 18 | 19 | public void setTicket(String ticket) { 20 | this.ticket = ticket; 21 | } 22 | 23 | public Integer getExpireSeconds() { 24 | return expireSeconds; 25 | } 26 | 27 | public void setExpireSeconds(Integer expireSeconds) { 28 | this.expireSeconds = expireSeconds; 29 | } 30 | 31 | public String getUrl() { 32 | return url; 33 | } 34 | 35 | public void setUrl(String url) { 36 | this.url = url; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/SendTemplateResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 发送模版消息响应 7 | */ 8 | public class SendTemplateResponse extends BaseResponse { 9 | 10 | /** 11 | * 消息id 12 | */ 13 | @JSONField(name = "msgid") 14 | private String msgid; 15 | 16 | public String getMsgid() { 17 | return msgid; 18 | } 19 | 20 | public void setMsgid(String msgid) { 21 | this.msgid = msgid; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/UploadImgResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | /** 4 | * @author Nottyjay 5 | */ 6 | public class UploadImgResponse extends BaseResponse { 7 | private String url; 8 | 9 | public String getUrl() { 10 | return url; 11 | } 12 | 13 | public void setUrl(String url) { 14 | this.url = url; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/UploadMaterialResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | /** 6 | * 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * ==================================================================== 13 | */ 14 | public class UploadMaterialResponse extends BaseResponse { 15 | 16 | @JSONField(name = "media_id") 17 | private String mediaId; 18 | 19 | public String getMediaId() { 20 | return mediaId; 21 | } 22 | 23 | public void setMediaId(String mediaId) { 24 | this.mediaId = mediaId; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/api/response/UploadMediaResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @author peiyu 9 | */ 10 | public class UploadMediaResponse extends BaseResponse { 11 | 12 | private String type; 13 | @JSONField(name = "media_id") 14 | private String mediaId; 15 | @JSONField(name = "created_at") 16 | private Date createdAt; 17 | 18 | public String getType() { 19 | return type; 20 | } 21 | 22 | public void setType(String type) { 23 | this.type = type; 24 | } 25 | 26 | public String getMediaId() { 27 | return mediaId; 28 | } 29 | 30 | public void setMediaId(String mediaId) { 31 | this.mediaId = mediaId; 32 | } 33 | 34 | public Date getCreatedAt() { 35 | return createdAt; 36 | } 37 | 38 | public void setCreatedAt(Date createdAt) { 39 | this.createdAt = createdAt; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/QYMessageAPI.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api; 2 | 3 | import com.github.sd4324530.fastweixin.api.BaseAPI; 4 | import com.github.sd4324530.fastweixin.api.config.ApiConfig; 5 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 6 | import com.github.sd4324530.fastweixin.company.api.config.QYAPIConfig; 7 | import com.github.sd4324530.fastweixin.company.api.response.GetQYSendMessageResponse; 8 | import com.github.sd4324530.fastweixin.company.message.*; 9 | import com.github.sd4324530.fastweixin.util.JSONUtil; 10 | 11 | /** 12 | * ==================================================================== 13 | * 上海聚攒软件开发有限公司 14 | * -------------------------------------------------------------------- 15 | * 16 | * @author Nottyjay 17 | * @version 1.0.beta 18 | * ==================================================================== 19 | */ 20 | public class QYMessageAPI extends QYBaseAPI { 21 | 22 | 23 | /** 24 | * 构造方法,设置apiConfig 25 | * 26 | * @param config 微信API配置对象 27 | */ 28 | public QYMessageAPI(QYAPIConfig config) { 29 | super(config); 30 | } 31 | 32 | public GetQYSendMessageResponse send(QYBaseMsg message){ 33 | GetQYSendMessageResponse response; 34 | String url = BASE_API_URL + "cgi-bin/message/send?access_token=#"; 35 | BaseResponse r = executePost(url, message.toJsonString()); 36 | // if(message instanceof QYTextMsg){ 37 | // r = executePost(url, JSONUtil.toJson((QYTextMsg)message)); 38 | // }else if(message instanceof QYImageMsg){ 39 | // r = executePost(url, JSONUtil.toJson((QYImageMsg)message)); 40 | // }else if(message instanceof QYVoiceMsg){ 41 | // r = executePost(url, JSONUtil.toJson((QYVoiceMsg)message)); 42 | // }else if(message instanceof QYVideoMsg){ 43 | // r = executePost(url, JSONUtil.toJson((QYVideoMsg)message)); 44 | // }else if(message instanceof QYFileMsg){ 45 | // r = executePost(url, JSONUtil.toJson((QYFileMsg)message)); 46 | // }else if(message instanceof QYNewsMsg){ 47 | // r = executePost(url, JSONUtil.toJson((QYNewsMsg)message)); 48 | // } 49 | String jsonResult = isSuccess(r.getErrcode())? r.getErrmsg() :r.toJsonString(); 50 | response = JSONUtil.toBean(jsonResult, GetQYSendMessageResponse.class); 51 | return response; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/config/QYConfigChangeNotice.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.config; 2 | 3 | import com.github.sd4324530.fastweixin.api.config.ChangeType; 4 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * 10 | * ==================================================================== 11 | * 上海聚攒软件开发有限公司 12 | * -------------------------------------------------------------------- 13 | * @author Nottyjay 14 | * @version 1.0.beta 15 | * ==================================================================== 16 | */ 17 | public class QYConfigChangeNotice extends BaseModel { 18 | 19 | private Date noticeTime; 20 | private String corpID; 21 | private ChangeType type; 22 | private String value; 23 | 24 | public QYConfigChangeNotice() { 25 | this.noticeTime = new Date(); 26 | } 27 | 28 | public QYConfigChangeNotice(String corpID, ChangeType type, String value) { 29 | this(); 30 | this.corpID = corpID; 31 | this.type = type; 32 | this.value = value; 33 | } 34 | 35 | public Date getNoticeTime() { 36 | return noticeTime; 37 | } 38 | 39 | public void setNoticeTime(Date noticeTime) { 40 | this.noticeTime = noticeTime; 41 | } 42 | 43 | public String getCorpID() { 44 | return corpID; 45 | } 46 | 47 | public void setCorpID(String corpID) { 48 | this.corpID = corpID; 49 | } 50 | 51 | public ChangeType getType() { 52 | return type; 53 | } 54 | 55 | public void setType(ChangeType type) { 56 | this.type = type; 57 | } 58 | 59 | public String getValue() { 60 | return value; 61 | } 62 | 63 | public void setValue(String value) { 64 | this.value = value; 65 | } 66 | 67 | @Override 68 | public String toString(){ 69 | return "QYConfigChangeNotice{" + 70 | "noticeTime" + noticeTime + 71 | ", corpid='" + corpID + "'" + 72 | ", type=" + type + 73 | ", value='" + value + "'" + 74 | "}"; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/entity/QYMenu.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.entity; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 4 | import com.github.sd4324530.fastweixin.exception.WeixinException; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 微信完整菜单 11 | * ==================================================================== 12 | * 上海聚攒软件开发有限公司 13 | * -------------------------------------------------------------------- 14 | * @author Nottyjay 15 | * @version 1.0.beta 16 | * @since 1.3.6 17 | * ==================================================================== 18 | */ 19 | public class QYMenu extends BaseModel { 20 | 21 | private List button;// 一级菜单。总共3个 22 | 23 | public List getButton() { 24 | return button; 25 | } 26 | 27 | public void setButton(List button) { 28 | if(button.size() > 3){ 29 | throw new WeixinException("一级菜单最多3个"); 30 | } 31 | this.button = button; 32 | } 33 | 34 | public void addButton(QYMenuButton singleButton){ 35 | if(button == null){ 36 | button = new ArrayList(3); 37 | } 38 | if(button.size() == 3){ 39 | throw new WeixinException("一级菜单最多3个"); 40 | } 41 | 42 | this.button.add(singleButton); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/entity/QYMenuButton.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.entity; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 5 | import com.github.sd4324530.fastweixin.company.api.enums.QYMenuType; 6 | import com.github.sd4324530.fastweixin.exception.WeixinException; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * 菜单按钮对象 12 | * ==================================================================== 13 | * 上海聚攒软件开发有限公司 14 | * -------------------------------------------------------------------- 15 | * @author Nottyjay 16 | * @version 1.0.beta 17 | * @since 1.3.6 18 | * ==================================================================== 19 | */ 20 | public class QYMenuButton extends BaseModel { 21 | 22 | private QYMenuType type;// 菜单类型 23 | private String name;// 菜单显式的名称 24 | private String key;// 菜单类型不为view或为空时可用。代表事件名称 25 | private String url;// 菜单类型为view时可用。代表点击按钮后跳转的页面地址 26 | @JSONField(name = "sub_button") 27 | private List subButton; 28 | 29 | public QYMenuType getType() { 30 | return type; 31 | } 32 | 33 | public void setType(QYMenuType type) { 34 | this.type = type; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public String getKey() { 46 | return key; 47 | } 48 | 49 | public void setKey(String key) { 50 | this.key = key; 51 | } 52 | 53 | public String getUrl() { 54 | return url; 55 | } 56 | 57 | public void setUrl(String url) { 58 | this.url = url; 59 | } 60 | 61 | public List getSubButton() { 62 | return subButton; 63 | } 64 | 65 | public void setSubButton(List subButton) { 66 | if(subButton.size() > 5){ 67 | throw new WeixinException("二级菜单最多5个"); 68 | } 69 | this.subButton = subButton; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/entity/QYTag.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.entity; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 4 | 5 | /** 6 | * 企业通讯录-标签 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * @since 1.3.6 13 | * ==================================================================== 14 | */ 15 | public class QYTag extends BaseModel { 16 | 17 | private String tagname; 18 | private Integer tagid; 19 | 20 | public QYTag() { 21 | } 22 | 23 | public QYTag(String tagname) { 24 | this.tagname = tagname; 25 | } 26 | 27 | public QYTag(String tagname, Integer tagid) { 28 | this.tagname = tagname; 29 | this.tagid = tagid; 30 | } 31 | 32 | public String getTagname() { 33 | return tagname; 34 | } 35 | 36 | public void setTagname(String tagname) { 37 | this.tagname = tagname; 38 | } 39 | 40 | public Integer getTagid() { 41 | return tagid; 42 | } 43 | 44 | public void setTagid(Integer tagid) { 45 | this.tagid = tagid; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/enums/QYMenuType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.enums; 2 | 3 | /** 4 | * 微信企业号菜单类型枚举 5 | * ==================================================================== 6 | * 上海聚攒软件开发有限公司 7 | * -------------------------------------------------------------------- 8 | * @author Nottyjay 9 | * @version 1.0.beta 10 | * @since 1.3.6 11 | * ==================================================================== 12 | */ 13 | public enum QYMenuType { 14 | /** 15 | * 点击推事件 16 | */ 17 | CLICK("click"), 18 | 19 | /** 20 | * 跳转URL 21 | */ 22 | VIEW("view"), 23 | 24 | /*-------------------------以下仅支持微信iPhone5.4.1以上版本,和Android5.4以上版本的微信用户------------------------*/ 25 | 26 | /** 27 | * 扫码推事件 28 | */ 29 | SCANCODE_PUSH("scancode_push"), 30 | 31 | /** 32 | * 扫码推事件且弹出“消息接收中”提示框 33 | */ 34 | SCANCODE_WAITMSG("scancode_waitmsg"), 35 | 36 | /** 37 | * 弹出系统拍照发图 38 | */ 39 | PIC_SYSPHOTO("pic_sysphoto"), 40 | 41 | /** 42 | * 弹出拍照或者相册发图 43 | */ 44 | PIC_PHOTO_OR_ALBUM("pic_photo_or_album"), 45 | 46 | /** 47 | * 弹出微信相册发图器 48 | */ 49 | PIC_WEIXIN("pic_weixin"), 50 | 51 | /** 52 | * 弹出地理位置选择器 53 | */ 54 | LOCATION_SELECT("location_select"); 55 | 56 | String value; 57 | 58 | QYMenuType(String value){ 59 | this.value = value; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return this.value; 65 | } 66 | 67 | public static QYMenuType getType(String value){ 68 | for(QYMenuType qytype : QYMenuType.class.getEnumConstants()){ 69 | if(qytype.toString().equals(value)){ 70 | return qytype; 71 | } 72 | } 73 | return null; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/handle/AbstractQYApiConfigChangeHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.handle; 2 | 3 | import com.github.sd4324530.fastweixin.company.api.config.QYConfigChangeNotice; 4 | import com.github.sd4324530.fastweixin.handle.ApiConfigChangeHandle; 5 | import com.github.sd4324530.fastweixin.util.BeanUtil; 6 | 7 | import java.util.Observable; 8 | 9 | /** 10 | * 11 | * ==================================================================== 12 | * 上海聚攒软件开发有限公司 13 | * -------------------------------------------------------------------- 14 | * @author Nottyjay 15 | * @version 1.0.beta 16 | * ==================================================================== 17 | */ 18 | public abstract class AbstractQYApiConfigChangeHandle implements ApiConfigChangeHandle{ 19 | 20 | public void update(Observable o, Object arg){ 21 | if(BeanUtil.nonNull(arg) && arg instanceof QYConfigChangeNotice){ 22 | configChange((QYConfigChangeNotice) arg); 23 | } 24 | } 25 | 26 | /** 27 | * 子类实现,当配置变化时触发该方法 28 | * @param notice 消息 29 | */ 30 | public abstract void configChange(QYConfigChangeNotice notice); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/AddTagUsersResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Response -- 增加标签成员 9 | * ==================================================================== 10 | * 上海聚攒软件开发有限公司 11 | * -------------------------------------------------------------------- 12 | * @author Nottyjay 13 | * @version 1.0.beta 14 | * @since 1.3.6 15 | * ==================================================================== 16 | */ 17 | public class AddTagUsersResponse extends BaseResponse { 18 | 19 | private String invalidlist; 20 | private List invalidparty; 21 | 22 | public String getInvalidlist() { 23 | return invalidlist; 24 | } 25 | 26 | public void setInvalidlist(String invalidlist) { 27 | this.invalidlist = invalidlist; 28 | } 29 | 30 | public List getInvalidparty() { 31 | return invalidparty; 32 | } 33 | 34 | public void setInvalidparty(List invalidparty) { 35 | this.invalidparty = invalidparty; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/CreateDepartmentResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 4 | 5 | /** 6 | * 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * ==================================================================== 13 | */ 14 | public class CreateDepartmentResponse extends BaseResponse { 15 | private Integer id; 16 | 17 | public Integer getId() { 18 | return id; 19 | } 20 | 21 | public void setId(Integer id) { 22 | this.id = id; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "CreateDepartmentResponse{" + 28 | "id=" + id + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/CreateTagResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 4 | 5 | /** 6 | * Response -- 创建新标签 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * @since 1.3.6 13 | * ==================================================================== 14 | */ 15 | public class CreateTagResponse extends BaseResponse { 16 | 17 | private Integer tagid; 18 | 19 | public Integer getTagid() { 20 | return tagid; 21 | } 22 | 23 | public void setTagid(Integer tagid) { 24 | this.tagid = tagid; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/DelTagUsersResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Response -- 删除标签内成员 9 | * ==================================================================== 10 | * 上海聚攒软件开发有限公司 11 | * -------------------------------------------------------------------- 12 | * @author Nottyjay 13 | * @version 1.0.beta 14 | * @since 1.3.6 15 | * ==================================================================== 16 | */ 17 | public class DelTagUsersResponse extends BaseResponse { 18 | private String invalidlist; 19 | private List invalidparty; 20 | 21 | public String getInvalidlist() { 22 | return invalidlist; 23 | } 24 | 25 | public void setInvalidlist(String invalidlist) { 26 | this.invalidlist = invalidlist; 27 | } 28 | 29 | public List getInvalidparty() { 30 | return invalidparty; 31 | } 32 | 33 | public void setInvalidparty(List invalidparty) { 34 | this.invalidparty = invalidparty; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/DownloadMediaResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 4 | import com.github.sd4324530.fastweixin.util.StreamUtil; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.io.OutputStream; 12 | 13 | /** 14 | * 15 | * ==================================================================== 16 | * 上海聚攒软件开发有限公司 17 | * -------------------------------------------------------------------- 18 | * @author Nottyjay 19 | * @version 1.0.beta 20 | * ==================================================================== 21 | */ 22 | public class DownloadMediaResponse extends BaseResponse { 23 | private static final Logger LOG = LoggerFactory.getLogger(DownloadMediaResponse.class); 24 | 25 | private String fileName; 26 | private byte[] content; 27 | 28 | public String getFileName() { 29 | return fileName; 30 | } 31 | 32 | public void setFileName(String fileName) { 33 | this.fileName = fileName; 34 | } 35 | 36 | public void setContent(InputStream content, Integer length) { 37 | ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); 38 | try { 39 | StreamUtil.copy(content, byteOutputStream); 40 | byte[] temp = byteOutputStream.toByteArray(); 41 | if (temp.length > length) { 42 | this.content = new byte[length]; 43 | for (int i = 0; i < length; i++) { 44 | this.content[i] = temp[i]; 45 | } 46 | } else { 47 | this.content = temp; 48 | } 49 | } catch (IOException e) { 50 | LOG.error("异常", e); 51 | } 52 | } 53 | 54 | /** 55 | * 如果成功,则可以靠这个方法将数据输出 56 | * 57 | * @param out 调用者给的输出流 58 | * @throws IOException 写流出现异常 59 | */ 60 | public void writeTo(OutputStream out) throws IOException { 61 | out.write(this.content); 62 | out.flush(); 63 | out.close(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetDepartmentListResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 5 | import com.github.sd4324530.fastweixin.company.api.entity.QYDepartment; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 11 | * ==================================================================== 12 | * 上海聚攒软件开发有限公司 13 | * -------------------------------------------------------------------- 14 | * @author Nottyjay 15 | * @version 1.0.beta 16 | * ==================================================================== 17 | */ 18 | public class GetDepartmentListResponse extends BaseResponse { 19 | 20 | @JSONField(name = "department") 21 | private List departments; 22 | 23 | public List getDepartments() { 24 | return departments; 25 | } 26 | 27 | public void setDepartments(List departments) { 28 | this.departments = departments; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetOauthUserInfoResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 5 | 6 | /** 7 | * Response -- 从Oauth中获取的用户信息 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 1.3.6 14 | * ==================================================================== 15 | */ 16 | public class GetOauthUserInfoResponse extends BaseResponse{ 17 | 18 | @JSONField(name = "UserId") 19 | private String userid; 20 | @JSONField(name = "OpenId") 21 | private String openid; 22 | @JSONField(name = "DeviceId") 23 | private String deviceid; 24 | 25 | public String getUserid() { 26 | return userid; 27 | } 28 | 29 | public void setUserid(String userid) { 30 | this.userid = userid; 31 | } 32 | 33 | public String getOpenid() { 34 | return openid; 35 | } 36 | 37 | public void setOpenid(String openid) { 38 | this.openid = openid; 39 | } 40 | 41 | public String getDeviceid() { 42 | return deviceid; 43 | } 44 | 45 | public void setDeviceid(String deviceid) { 46 | this.deviceid = deviceid; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetQYAgentListResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 5 | import com.github.sd4324530.fastweixin.company.api.entity.QYAgent; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 11 | * ==================================================================== 12 | * 上海聚攒软件开发有限公司 13 | * -------------------------------------------------------------------- 14 | * @author Nottyjay 15 | * @version 1.0.beta 16 | * ==================================================================== 17 | */ 18 | public class GetQYAgentListResponse extends BaseResponse { 19 | 20 | @JSONField(name = "agentlist") 21 | public List agentList; 22 | 23 | public List getAgentList() { 24 | return agentList; 25 | } 26 | 27 | public void setAgentList(List agentList) { 28 | this.agentList = agentList; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetQYMenuResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 4 | import com.github.sd4324530.fastweixin.company.api.entity.QYMenu; 5 | 6 | /** 7 | * Response -- 获取菜单 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 1.3.6 14 | * ==================================================================== 15 | */ 16 | public class GetQYMenuResponse extends BaseResponse { 17 | 18 | private QYMenu menu; 19 | 20 | public QYMenu getMenu() { 21 | return menu; 22 | } 23 | 24 | public void setMenu(QYMenu menu) { 25 | this.menu = menu; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetQYSendMessageResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 7 | 8 | /** 9 | * ==================================================================== 10 | * 上海聚攒软件开发有限公司 11 | * -------------------------------------------------------------------- 12 | * 13 | * @author Nottyjay 14 | * @version 1.0.beta 15 | * ==================================================================== 16 | */ 17 | public class GetQYSendMessageResponse extends BaseResponse { 18 | 19 | @JSONField(name = "invaliduser") 20 | private String invalidUser; 21 | @JSONField(name = "invalidParty") 22 | private String invalidParty; 23 | @JSONField(name = "invalidtag") 24 | private String invalidTag; 25 | 26 | public String getInvalidUser() { 27 | return invalidUser; 28 | } 29 | 30 | public void setInvalidUser(String invalidUser) { 31 | this.invalidUser = invalidUser; 32 | } 33 | 34 | public String getInvalidParty() { 35 | return invalidParty; 36 | } 37 | 38 | public void setInvalidParty(String invalidParty) { 39 | this.invalidParty = invalidParty; 40 | } 41 | 42 | public String getInvalidTag() { 43 | return invalidTag; 44 | } 45 | 46 | public void setInvalidTag(String invalidTag) { 47 | this.invalidTag = invalidTag; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetQYUserInfo4DepartmentResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response;/** 2 | * Created by Nottyjay on 2015/6/11. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 7 | import com.github.sd4324530.fastweixin.company.api.entity.QYUser; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * ==================================================================== 13 | * 上海聚攒软件开发有限公司 14 | * -------------------------------------------------------------------- 15 | * 16 | * @author Nottyjay 17 | * @version 1.0.beta 18 | * ==================================================================== 19 | */ 20 | public class GetQYUserInfo4DepartmentResponse extends BaseResponse { 21 | 22 | @JSONField(name = "userlist") 23 | public List userList; 24 | 25 | public List getUserList() { 26 | return userList; 27 | } 28 | 29 | public void setUserList(List userList) { 30 | this.userList = userList; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetQYUserInviteResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response;/** 2 | * Created by Nottyjay on 2015/6/11. 3 | */ 4 | 5 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 6 | 7 | /** 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * 12 | * @author Nottyjay 13 | * @version 1.0.beta 14 | * ==================================================================== 15 | */ 16 | public class GetQYUserInviteResponse extends BaseResponse { 17 | private Integer type; 18 | 19 | public Integer getType() { 20 | return type; 21 | } 22 | 23 | public void setType(Integer type) { 24 | this.type = type; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetTagInfoResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * Response -- 标签信息 11 | * ==================================================================== 12 | * 上海聚攒软件开发有限公司 13 | * -------------------------------------------------------------------- 14 | * @author Nottyjay 15 | * @version 1.0.beta 16 | * @since 1.3.6 17 | * ==================================================================== 18 | */ 19 | public class GetTagInfoResponse extends BaseResponse { 20 | 21 | @JSONField(name = "userlist") 22 | private List> users; 23 | @JSONField(name = "partylist") 24 | private List partys; 25 | 26 | public List> getUsers() { 27 | return users; 28 | } 29 | 30 | public void setUsers(List> users) { 31 | this.users = users; 32 | } 33 | 34 | public List getPartys() { 35 | return partys; 36 | } 37 | 38 | public void setPartys(List partys) { 39 | this.partys = partys; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/GetTagListResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 5 | import com.github.sd4324530.fastweixin.company.api.entity.QYTag; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Response -- 获取标签列表 11 | * ==================================================================== 12 | * 上海聚攒软件开发有限公司 13 | * -------------------------------------------------------------------- 14 | * @author Nottyjay 15 | * @version 1.0.beta 16 | * @since 1.3.6 17 | * ==================================================================== 18 | */ 19 | public class GetTagListResponse extends BaseResponse { 20 | 21 | @JSONField(name = "taglist") 22 | private List tags; 23 | 24 | public List getTags() { 25 | return tags; 26 | } 27 | 28 | public void setTags(List tags) { 29 | this.tags = tags; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/api/response/UploadMediaResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.api.response; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.github.sd4324530.fastweixin.api.response.BaseResponse; 5 | 6 | /** 7 | * 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * ==================================================================== 14 | */ 15 | public class UploadMediaResponse extends BaseResponse { 16 | 17 | @JSONField(name = "type") 18 | private String type; 19 | @JSONField(name = "media_id") 20 | private String mediaId; 21 | @JSONField(name = "created_at") 22 | private String createTime; 23 | 24 | public String getType() { 25 | return type; 26 | } 27 | 28 | public void setType(String type) { 29 | this.type = type; 30 | } 31 | 32 | public String getMediaId() { 33 | return mediaId; 34 | } 35 | 36 | public void setMediaId(String mediaId) { 37 | this.mediaId = mediaId; 38 | } 39 | 40 | public String getCreateTime() { 41 | return createTime; 42 | } 43 | 44 | public void setCreateTime(String createTime) { 45 | this.createTime = createTime; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/handle/QYEventHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.handle; 2 | 3 | import com.github.sd4324530.fastweixin.company.message.req.QYBaseEvent; 4 | import com.github.sd4324530.fastweixin.company.message.resp.QYBaseRespMsg; 5 | 6 | /** 7 | * 微信企业号事件处理器接口 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 1.3.6 14 | * ==================================================================== 15 | */ 16 | public interface QYEventHandle{ 17 | 18 | /** 19 | * 处理微信事件 20 | * 21 | * @param event 微信事件 22 | * @return 回复用户的消息 23 | */ 24 | QYBaseRespMsg handle(E event); 25 | 26 | /** 27 | * 在处理之前,判断本事件是否符合处理的条件 28 | * 29 | * @param event 事件 30 | * @return 是否需要处理 31 | */ 32 | boolean beforeHandle(E event); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/handle/QYMessageHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.handle; 2 | 3 | import com.github.sd4324530.fastweixin.company.message.req.QYBaseReqMsg; 4 | import com.github.sd4324530.fastweixin.company.message.resp.QYBaseRespMsg; 5 | 6 | /** 7 | * 微信企业号消息处理器接口 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 1.3.6 14 | * ==================================================================== 15 | */ 16 | public interface QYMessageHandle { 17 | /** 18 | * 处理微信消息 19 | * 20 | * @param message 微信消息 21 | * @return 回复用户的消息 22 | */ 23 | QYBaseRespMsg handle(M message); 24 | 25 | /** 26 | * 在处理之前,判断本条消息是否符合处理的条件 27 | * 28 | * @param message 消息 29 | * @return 是否需要处理 30 | */ 31 | boolean beforeHandle(M message); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYArticle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message; 2 | 3 | import com.github.sd4324530.fastweixin.message.Article; 4 | 5 | /** 6 | * 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * ==================================================================== 13 | */ 14 | public class QYArticle extends Article { 15 | 16 | private String picurl; 17 | 18 | public QYArticle(String title, String description, String picUrl, String url) { 19 | super(title, description, null, url); 20 | this.picurl = picUrl; 21 | } 22 | 23 | public String getPicurl() { 24 | return picurl; 25 | } 26 | 27 | public void setPicurl(String picurl) { 28 | this.picurl = picurl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYBaseMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | import com.github.sd4324530.fastweixin.api.entity.BaseModel; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * ==================================================================== 12 | * 上海聚攒软件开发有限公司 13 | * -------------------------------------------------------------------- 14 | * 15 | * @author Nottyjay 16 | * @version 1.0.beta 17 | * ==================================================================== 18 | */ 19 | public class QYBaseMsg extends BaseModel implements Serializable { 20 | 21 | public static final class Safe { 22 | public static final String YES = "1";// 保密消息 23 | public static final String NO = "0";// 非保密消息 24 | } 25 | 26 | @JSONField(name = "touser") 27 | private String toUser; 28 | @JSONField(name = "toparty") 29 | private String toParty; 30 | @JSONField(name = "totag") 31 | private String toTag; 32 | @JSONField(name = "msgtype") 33 | private String msgType; 34 | @JSONField(name = "agentid") 35 | private String agentId; 36 | @JSONField(name = "safe") 37 | private String safe = Safe.NO; 38 | 39 | public String getToUser() { 40 | return toUser; 41 | } 42 | 43 | public void setToUser(String toUser) { 44 | this.toUser = toUser; 45 | } 46 | 47 | public String getToParty() { 48 | return toParty; 49 | } 50 | 51 | public void setToParty(String toParty) { 52 | this.toParty = toParty; 53 | } 54 | 55 | public String getToTag() { 56 | return toTag; 57 | } 58 | 59 | public void setToTag(String toTag) { 60 | this.toTag = toTag; 61 | } 62 | 63 | public String getMsgType() { 64 | return msgType; 65 | } 66 | 67 | public void setMsgType(String msgType) { 68 | this.msgType = msgType; 69 | } 70 | 71 | public String getAgentId() { 72 | return agentId; 73 | } 74 | 75 | public void setAgentId(String agentId) { 76 | this.agentId = agentId; 77 | } 78 | 79 | public String getSafe() { 80 | return safe; 81 | } 82 | 83 | public void setSafe(String safe) { 84 | this.safe = safe; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYFileMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | 7 | /** 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * 12 | * @author Nottyjay 13 | * @version 1.0.beta 14 | * ==================================================================== 15 | */ 16 | public class QYFileMsg extends QYBaseMsg { 17 | 18 | @JSONField(name = "file") 19 | private File file; 20 | 21 | public File getFile() { 22 | return file; 23 | } 24 | 25 | public void setFile(File file) { 26 | this.file = file; 27 | } 28 | 29 | public class File{ 30 | @JSONField(name = "media_id") 31 | private String mediaId; 32 | 33 | public String getMediaId() { 34 | return mediaId; 35 | } 36 | 37 | public void setMediaId(String mediaId) { 38 | this.mediaId = mediaId; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYImageMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | 7 | /** 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * 12 | * @author Nottyjay 13 | * @version 1.0.beta 14 | * ==================================================================== 15 | */ 16 | public class QYImageMsg extends QYBaseMsg{ 17 | 18 | @JSONField(name = "image") 19 | private Image image; 20 | 21 | public QYImageMsg() { this.setMsgType("image"); } 22 | 23 | public Image getImage() { 24 | return image; 25 | } 26 | 27 | public void setImage(Image image) { 28 | this.image = image; 29 | } 30 | 31 | public void setMediaId(String mediaId) { this.image = new Image(mediaId); } 32 | 33 | public class Image{ 34 | @JSONField(name = "media_id") 35 | private String mediaId; 36 | 37 | public Image(String mediaId) {this.mediaId = mediaId;} 38 | 39 | public String getMediaId() { 40 | return mediaId; 41 | } 42 | 43 | public void setMediaId(String mediaId) { 44 | this.mediaId = mediaId; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYMpArticle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message; 2 | 3 | import com.github.sd4324530.fastweixin.api.entity.Article; 4 | 5 | /** 6 | * 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * ==================================================================== 13 | */ 14 | public class QYMpArticle extends Article { 15 | 16 | public QYMpArticle(String thumbMediaId, String author, String title, String contentSourceUrl, String content, String digest, Integer showConverPic) { 17 | super(thumbMediaId, author, title, contentSourceUrl, content, digest, showConverPic); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYMpNewsMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * ==================================================================== 13 | * 上海聚攒软件开发有限公司 14 | * -------------------------------------------------------------------- 15 | * 16 | * @author wwj 17 | * @version 1.0.beta 18 | * ==================================================================== 19 | */ 20 | public class QYMpNewsMsg extends QYBaseMsg { 21 | 22 | private static final Integer MAX_ARTICLE_COUNT = 10; 23 | 24 | @JSONField(name = "mpnews") 25 | private Map news; 26 | 27 | public QYMpNewsMsg() { 28 | news = new HashMap(); 29 | } 30 | 31 | public Map getNews() { 32 | return news; 33 | } 34 | 35 | public void setNews(Map news) { 36 | this.news = news; 37 | } 38 | 39 | public void setMpArticles(List articles){ 40 | if(articles.size() > MAX_ARTICLE_COUNT){ 41 | articles = articles.subList(0, MAX_ARTICLE_COUNT); 42 | } 43 | news.put("articles", articles); 44 | } 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYNewsMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * ==================================================================== 13 | * 上海聚攒软件开发有限公司 14 | * -------------------------------------------------------------------- 15 | * 16 | * @author Nottyjay 17 | * @version 1.0.beta 18 | * ==================================================================== 19 | */ 20 | public class QYNewsMsg extends QYBaseMsg { 21 | 22 | private static final Integer MAX_ARTICLE_COUNT = 10; 23 | 24 | @JSONField(name = "news") 25 | private Map news; 26 | 27 | public QYNewsMsg() { 28 | news = new HashMap(); 29 | } 30 | 31 | public Map getNews() { 32 | return news; 33 | } 34 | 35 | public void setNews(Map news) { 36 | this.news = news; 37 | } 38 | 39 | public void setArticles(List articles){ 40 | if(articles.size() > MAX_ARTICLE_COUNT){ 41 | articles = articles.subList(0, MAX_ARTICLE_COUNT); 42 | } 43 | news.put("articles", articles); 44 | } 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYTextMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * ==================================================================== 11 | * 上海聚攒软件开发有限公司 12 | * -------------------------------------------------------------------- 13 | * 14 | * @author Nottyjay 15 | * @version 1.0.beta 16 | * ==================================================================== 17 | */ 18 | public class QYTextMsg extends QYBaseMsg { 19 | 20 | @JSONField(name = "text") 21 | private Text text; 22 | 23 | public QYTextMsg() { 24 | this.setMsgType("text"); 25 | } 26 | 27 | public QYTextMsg(String content) { 28 | this.text = new Text(content); 29 | } 30 | 31 | public Text getText() { 32 | return text; 33 | } 34 | 35 | public void setText(Text text) { 36 | this.text = text; 37 | } 38 | 39 | public void setConetnt(String content){ 40 | this.text = new Text(content); 41 | } 42 | 43 | public static class Text{ 44 | @JSONField(name = "content") 45 | private String content; 46 | 47 | public Text(String content) { 48 | this.content = content; 49 | } 50 | 51 | public String getContent() { 52 | return content; 53 | } 54 | 55 | public void setContent(String content) { 56 | this.content = content; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYVideoMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | 7 | /** 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * 12 | * @author Nottyjay 13 | * @version 1.0.beta 14 | * ==================================================================== 15 | */ 16 | public class QYVideoMsg extends QYBaseMsg { 17 | 18 | @JSONField(name = "video") 19 | private Video video; 20 | 21 | public Video getVideo() { 22 | return video; 23 | } 24 | 25 | public void setVideo(Video video) { 26 | this.video = video; 27 | } 28 | 29 | public class Video{ 30 | @JSONField(name = "media_id") 31 | private String mediaId; 32 | @JSONField(name = "title") 33 | private String title; 34 | @JSONField(name = "description") 35 | private String description; 36 | 37 | public String getMediaId() { 38 | return mediaId; 39 | } 40 | 41 | public void setMediaId(String mediaId) { 42 | this.mediaId = mediaId; 43 | } 44 | 45 | public String getTitle() { 46 | return title; 47 | } 48 | 49 | public void setTitle(String title) { 50 | this.title = title; 51 | } 52 | 53 | public String getDescription() { 54 | return description; 55 | } 56 | 57 | public void setDescription(String description) { 58 | this.description = description; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/QYVoiceMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message;/** 2 | * Created by Nottyjay on 2015/6/12. 3 | */ 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | 7 | /** 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * 12 | * @author Nottyjay 13 | * @version 1.0.beta 14 | * ==================================================================== 15 | */ 16 | public class QYVoiceMsg extends QYBaseMsg { 17 | 18 | @JSONField(name = "voice") 19 | private Voice voice; 20 | 21 | public Voice getVoice() { 22 | return voice; 23 | } 24 | 25 | public void setVoice(Voice voice) { 26 | this.voice = voice; 27 | } 28 | 29 | public class Voice{ 30 | @JSONField(name = "media_id") 31 | private String mediaId; 32 | 33 | public String getMediaId() { 34 | return mediaId; 35 | } 36 | 37 | public void setMediaId(String mediaId) { 38 | this.mediaId = mediaId; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYBaseEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号事件消息基类 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYBaseEvent extends QYBaseReq{ 13 | 14 | String event; 15 | 16 | public QYBaseEvent() { 17 | setMsgType(QYReqType.EVENT); 18 | } 19 | 20 | public String getEvent() { 21 | return event; 22 | } 23 | 24 | public void setEvent(String event) { 25 | this.event = event; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYBaseReq.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | 3 | /** 4 | * 企业号基础消息模型 5 | * ==================================================================== 6 | * 上海聚攒软件开发有限公司 7 | * -------------------------------------------------------------------- 8 | * @author Nottyjay 9 | * @version 1.0.beta 10 | * @since 1.3.6 11 | * ==================================================================== 12 | */ 13 | public class QYBaseReq { 14 | 15 | String toUserName; 16 | String fromUserName; 17 | long createTime; 18 | String msgType; 19 | String agentId;// 企业应用的ID 20 | 21 | public String getToUserName() { 22 | return toUserName; 23 | } 24 | 25 | public void setToUserName(String toUserName) { 26 | this.toUserName = toUserName; 27 | } 28 | 29 | public String getFromUserName() { 30 | return fromUserName; 31 | } 32 | 33 | public void setFromUserName(String fromUserName) { 34 | this.fromUserName = fromUserName; 35 | } 36 | 37 | public long getCreateTime() { 38 | return createTime; 39 | } 40 | 41 | public void setCreateTime(long createTime) { 42 | this.createTime = createTime; 43 | } 44 | 45 | public String getMsgType() { 46 | return msgType; 47 | } 48 | 49 | public void setMsgType(String msgType) { 50 | this.msgType = msgType; 51 | } 52 | 53 | public String getAgentId() { 54 | return agentId; 55 | } 56 | 57 | public void setAgentId(String agentId) { 58 | this.agentId = agentId; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYBaseReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号普通消息事件基类 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYBaseReqMsg extends QYBaseReq { 13 | 14 | String msgId; 15 | 16 | public String getMsgId() { 17 | return msgId; 18 | } 19 | 20 | public void setMsgId(String msgId) { 21 | this.msgId = msgId; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYBatchJobEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信公众号异步任务完成事件 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYBatchJobEvent extends QYBaseEvent{ 13 | 14 | private String jobId; 15 | private String jobType; 16 | private int errCode; 17 | private String errMsg; 18 | 19 | public QYBatchJobEvent(String jobId, String jobType, int errCode, String errMsg) { 20 | this.jobId = jobId; 21 | this.jobType = jobType; 22 | this.errCode = errCode; 23 | this.errMsg = errMsg; 24 | } 25 | 26 | public String getJobId() { 27 | return jobId; 28 | } 29 | 30 | public void setJobId(String jobId) { 31 | this.jobId = jobId; 32 | } 33 | 34 | public String getJobType() { 35 | return jobType; 36 | } 37 | 38 | public void setJobType(String jobType) { 39 | this.jobType = jobType; 40 | } 41 | 42 | public int getErrCode() { 43 | return errCode; 44 | } 45 | 46 | public void setErrCode(int errCode) { 47 | this.errCode = errCode; 48 | } 49 | 50 | public String getErrMsg() { 51 | return errMsg; 52 | } 53 | 54 | public void setErrMsg(String errMsg) { 55 | this.errMsg = errMsg; 56 | } 57 | 58 | @Override 59 | public String toString(){ 60 | return "QYMenuEvent [jobId=" + jobId + ", jobType=" + jobType + ", errCode=" + errCode + ", errMsg=" + errMsg 61 | + ", toUserName=" + toUserName + ", fromUserName=" 62 | + fromUserName + ", createTime=" + createTime + ", msgType=" 63 | + msgType + ", event=" + event + ", agentId=" + agentId + "]"; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYBatchJobType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号异步任务类型 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public final class QYBatchJobType { 13 | 14 | private String SYNCUSER = "sync_user";// 增量更新成员 15 | private String REPLACEUSER = "replace_user";// 全量覆盖成员 16 | private String INVITEUSER = "invite_user";// 邀请成员关注 17 | private String REPLACEPARTY = "replace_party";// 全量覆盖部门 18 | 19 | private QYBatchJobType() { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYEnterAgentEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号进入应用事件消息 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYEnterAgentEvent extends QYMenuEvent { 13 | 14 | public QYEnterAgentEvent() { 15 | super(""); 16 | } 17 | 18 | @Override 19 | public String toString(){ 20 | return "QYMenuEvent [eventKey=" + getEventKey() 21 | + ", toUserName=" + toUserName + ", fromUserName=" 22 | + fromUserName + ", createTime=" + createTime + ", msgType=" 23 | + msgType + ", event=" + event + ", agentId=" + agentId + "]"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYEventType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号事件消息类型 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public final class QYEventType { 13 | 14 | public static final String SUBSCRIBE = "subscribe"; 15 | public static final String UNSUBSCRIBE = "unsubscribe"; 16 | public static final String CLICK = "CLICK"; 17 | public static final String VIEW = "VIEW"; 18 | public static final String LOCATION = "LOCATION"; 19 | public static final String SCAN = "SCAN"; 20 | public static final String SCANCODEPUSH = "scancode_push"; 21 | public static final String SCANCODEWAITMSG = "scancode_waitmsg"; 22 | public static final String PICSYSPHOTO = "pic_sysphoto"; 23 | public static final String PICPHOTOORALBUM = "pic_photo_or_album"; 24 | public static final String PICWEIXIN = "pic_weixin"; 25 | public static final String LOCATIONSELECT = "location_select"; 26 | public static final String TEMPLATESENDJOBFINISH = "TEMPLATESENDJOBFINISH"; 27 | public static final String MASSSENDJOBFINISH="MASSSENDJOBFINISH"; 28 | public static final String ENTERAGENT = "enter_agent"; 29 | public static final String BATCHJOBRESULT = "batch_job_result"; 30 | 31 | private QYEventType() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYImageReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | 3 | /** 4 | * 微信企业号图片消息事件 5 | * ==================================================================== 6 | * 上海聚攒软件开发有限公司 7 | * -------------------------------------------------------------------- 8 | * @author Nottyjay 9 | * @version 1.0.beta 10 | * @since 1.3.6 11 | * ==================================================================== 12 | */ 13 | public class QYImageReqMsg extends QYBaseReqMsg { 14 | 15 | private String picUrl; 16 | private String mediaId; 17 | 18 | public QYImageReqMsg(String picUrl, String mediaId) { 19 | super(); 20 | this.picUrl = picUrl; 21 | this.mediaId = mediaId; 22 | setMsgType(QYReqType.IMAGE); 23 | } 24 | 25 | public String getPicUrl() { 26 | return picUrl; 27 | } 28 | 29 | public String getMediaId() { 30 | return mediaId; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "QYImageReqMsg [picUrl=" + picUrl + ", mediaId=" + mediaId 36 | + ", toUserName=" + toUserName + ", fromUserName=" 37 | + fromUserName + ", createTime=" + createTime + ", msgType=" 38 | + msgType + ", msgId=" + msgId + ", agentId=" + agentId + "]"; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYLocationEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号地理位置上报事件 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYLocationEvent extends QYBaseEvent { 13 | 14 | private double latitude; 15 | private double longitude; 16 | private double precision; 17 | 18 | public QYLocationEvent(double latitude, double longitude, double precision) { 19 | super(); 20 | this.latitude = latitude; 21 | this.longitude = longitude; 22 | this.precision = precision; 23 | setEvent(QYEventType.LOCATION); 24 | } 25 | 26 | public double getLatitude() { 27 | return latitude; 28 | } 29 | 30 | public void setLatitude(double latitude) { 31 | this.latitude = latitude; 32 | } 33 | 34 | public double getLongitude() { 35 | return longitude; 36 | } 37 | 38 | public void setLongitude(double longitude) { 39 | this.longitude = longitude; 40 | } 41 | 42 | public double getPrecision() { 43 | return precision; 44 | } 45 | 46 | public void setPrecision(double precision) { 47 | this.precision = precision; 48 | } 49 | 50 | @Override 51 | public String toString(){ 52 | return "QYLocationEvent [latitude=" + latitude + ", longitude" + longitude 53 | + ", precision=" + precision + ", toUserName=" + toUserName + ", fromUserName=" 54 | + fromUserName + ", createTime=" + createTime + ", msgType=" 55 | + msgType + ", event=" + event + ", agentId=" + agentId + "]"; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYLocationReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号位置消息事件 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYLocationReqMsg extends QYBaseReqMsg { 13 | 14 | private double locationX; 15 | private double locationY; 16 | private int scale; 17 | private String label; 18 | 19 | public QYLocationReqMsg(double locationX, double locationY, int scale, String label) { 20 | super(); 21 | this.locationX = locationX; 22 | this.locationY = locationY; 23 | this.scale = scale; 24 | this.label = label; 25 | setMsgType(QYReqType.LOCATION); 26 | } 27 | 28 | public double getLocationX() { 29 | return locationX; 30 | } 31 | 32 | public void setLocationX(double locationX) { 33 | this.locationX = locationX; 34 | } 35 | 36 | public double getLocationY() { 37 | return locationY; 38 | } 39 | 40 | public void setLocationY(double locationY) { 41 | this.locationY = locationY; 42 | } 43 | 44 | public int getScale() { 45 | return scale; 46 | } 47 | 48 | public void setScale(int scale) { 49 | this.scale = scale; 50 | } 51 | 52 | public String getLabel() { 53 | return label; 54 | } 55 | 56 | public void setLabel(String label) { 57 | this.label = label; 58 | } 59 | 60 | @Override 61 | public String toString(){ 62 | return "QYLocationReqMsg [location_x=" + locationX 63 | + ", location_y=" + locationY + ", scale=" + scale 64 | + ", label=" + label + ", toUserName=" + toUserName + ", fromUserName=" 65 | + fromUserName + ", createTime=" + createTime + ", msgType=" 66 | + msgType + ", msgId=" + msgId + ", agentId=" + agentId + "]"; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYMenuEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号菜单事件 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYMenuEvent extends QYBaseEvent { 13 | 14 | private String eventKey; 15 | 16 | public QYMenuEvent(String eventKey) { 17 | super(); 18 | this.eventKey = eventKey; 19 | } 20 | 21 | public String getEventKey() { 22 | return eventKey; 23 | } 24 | 25 | public void setEventKey(String eventKey) { 26 | this.eventKey = eventKey; 27 | } 28 | 29 | @Override 30 | public String toString(){ 31 | return "QYMenuEvent [eventKey=" + eventKey 32 | + ", toUserName=" + toUserName + ", fromUserName=" 33 | + fromUserName + ", createTime=" + createTime + ", msgType=" 34 | + msgType + ", event=" + event + ", agentId=" + agentId + "]"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYReqType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | 3 | import com.github.sd4324530.fastweixin.message.req.ReqType; 4 | 5 | /** 6 | * 微信企业号推送事件类别 7 | * ==================================================================== 8 | * 上海聚攒软件开发有限公司 9 | * -------------------------------------------------------------------- 10 | * @author Nottyjay 11 | * @version 1.0.beta 12 | * @since 1.3.6 13 | * ==================================================================== 14 | */ 15 | public final class QYReqType{ 16 | 17 | public static final String TEXT = "text"; 18 | public static final String IMAGE = "image"; 19 | public static final String LOCATION = "location"; 20 | public static final String VOICE = "voice"; 21 | public static final String VIDEO = "video"; 22 | public static final String SHORT_VIDEO = "shortvideo"; 23 | public static final String EVENT = "event"; 24 | 25 | private QYReqType() { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYScanCodeEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 微信企业号扫码事件 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYScanCodeEvent extends QYMenuEvent { 13 | 14 | private String scanType; 15 | private String scanResult; 16 | 17 | public QYScanCodeEvent(String eventKey, String scanType, String scanResult) { 18 | super(eventKey); 19 | this.scanType = scanType; 20 | this.scanResult = scanResult; 21 | } 22 | 23 | public String getScanType() { 24 | return scanType; 25 | } 26 | 27 | public void setScanType(String scanType) { 28 | this.scanType = scanType; 29 | } 30 | 31 | public String getScanResult() { 32 | return scanResult; 33 | } 34 | 35 | public void setScanResult(String scanResult) { 36 | this.scanResult = scanResult; 37 | } 38 | 39 | @Override 40 | public String toString(){ 41 | return "QYMenuEvent [scanType=" + scanType + ", scanResult=" + scanResult+ ", eventKey=" + getEventKey() 42 | + ", toUserName=" + toUserName + ", fromUserName=" 43 | + fromUserName + ", createTime=" + createTime + ", msgType=" 44 | + msgType + ", event=" + event + ", agentId=" + agentId + "]"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYSendPicInfoEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | /** 7 | * 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 14 | * ==================================================================== 15 | */ 16 | public class QYSendPicInfoEvent extends QYMenuEvent { 17 | 18 | private int count; 19 | private List picList; 20 | 21 | public QYSendPicInfoEvent(String eventKey, int count, List picList) { 22 | super(eventKey); 23 | this.count = count; 24 | this.picList = picList; 25 | } 26 | 27 | public int getCount() { 28 | return count; 29 | } 30 | 31 | public void setCount(int count) { 32 | this.count = count; 33 | } 34 | 35 | public List getPicList() { 36 | return picList; 37 | } 38 | 39 | public void setPicList(List picList) { 40 | this.picList = picList; 41 | } 42 | 43 | @Override 44 | public String toString(){ 45 | return "QYMenuEvent [count=" + count + ", picList=" + picList+ ", eventKey=" + getEventKey() 46 | + ", toUserName=" + toUserName + ", fromUserName=" 47 | + fromUserName + ", createTime=" + createTime + ", msgType=" 48 | + msgType + ", event=" + event + ", agentId=" + agentId + "]"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYTextReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | 3 | /** 4 | * 微信企业号文本消息事件 5 | * ==================================================================== 6 | * 上海聚攒软件开发有限公司 7 | * -------------------------------------------------------------------- 8 | * @author Nottyjay 9 | * @version 1.0.beta 10 | * @since 1.3.6 11 | * ==================================================================== 12 | */ 13 | public class QYTextReqMsg extends QYBaseReqMsg { 14 | 15 | private String content; 16 | 17 | public QYTextReqMsg(String content) { 18 | super(); 19 | this.content = content; 20 | setMsgType(QYReqType.TEXT); 21 | } 22 | 23 | public String getContent() { 24 | return content; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "QYTextReqMsg [content=" + content 30 | + ", toUserName=" + toUserName + ", fromUserName=" 31 | + fromUserName + ", createTime=" + createTime + ", msgType=" 32 | + msgType + ", msgId=" + msgId + ", agentId=" + agentId + "]"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYVideoReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | /** 3 | * 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * @since 1.3.6 10 | * ==================================================================== 11 | */ 12 | public class QYVideoReqMsg extends QYBaseReqMsg { 13 | 14 | private String mediaId; 15 | private String thumbMediaId; 16 | 17 | public QYVideoReqMsg(String mediaId, String thumbMediaId) { 18 | super(); 19 | this.mediaId = mediaId; 20 | this.thumbMediaId = thumbMediaId; 21 | setMsgType(QYReqType.VIDEO); 22 | } 23 | 24 | public String getMediaId() { 25 | return mediaId; 26 | } 27 | 28 | public void setMediaId(String mediaId) { 29 | this.mediaId = mediaId; 30 | } 31 | 32 | public String getThumbMediaId() { 33 | return thumbMediaId; 34 | } 35 | 36 | public void setThumbMediaId(String thumbMediaId) { 37 | this.thumbMediaId = thumbMediaId; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "QYVideoReqMsg [mediaId=" + mediaId + ", thumbMediaId=" + thumbMediaId 43 | + ", toUserName=" + toUserName + ", fromUserName=" 44 | + fromUserName + ", createTime=" + createTime + ", msgType=" 45 | + msgType + ", msgId=" + msgId + ", agentId=" + agentId + "]"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/req/QYVoiceReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.req; 2 | 3 | /** 4 | * 微信企业号语音消息事件 5 | * ==================================================================== 6 | * 上海聚攒软件开发有限公司 7 | * -------------------------------------------------------------------- 8 | * @author Nottyjay 9 | * @version 1.0.beta 10 | * @since 1.3.6 11 | * ==================================================================== 12 | */ 13 | public class QYVoiceReqMsg extends QYBaseReqMsg{ 14 | private String mediaId; 15 | private String format; 16 | 17 | public QYVoiceReqMsg(String mediaId, String format) { 18 | this.mediaId = mediaId; 19 | this.format = format; 20 | } 21 | 22 | public String getMediaId() { 23 | return mediaId; 24 | } 25 | 26 | public void setMediaId(String mediaId) { 27 | this.mediaId = mediaId; 28 | } 29 | 30 | public String getFormat() { 31 | return format; 32 | } 33 | 34 | public void setFormat(String format) { 35 | this.format = format; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "QYVoiceReqMsg [format=" + format + ", mediaId=" + mediaId 41 | + ", toUserName=" + toUserName + ", fromUserName=" 42 | + fromUserName + ", createTime=" + createTime + ", msgType=" 43 | + msgType + ", msgId=" + msgId + ", agentId=" + agentId + "]"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/resp/QYBaseRespMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.resp; 2 | 3 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 微信企业号被动响应消息基类 9 | * ==================================================================== 10 | * 上海聚攒软件开发有限公司 11 | * -------------------------------------------------------------------- 12 | * @author Nottyjay 13 | * @version 1.0.beta 14 | * @since 1.3.6 15 | * ==================================================================== 16 | */ 17 | public class QYBaseRespMsg implements Serializable { 18 | 19 | private String toUserName; 20 | private String fromUserName; 21 | private int createTime; 22 | private String msgType; 23 | 24 | public QYBaseRespMsg() { 25 | } 26 | 27 | public String getToUserName() { 28 | return toUserName; 29 | } 30 | 31 | public void setToUserName(String toUserName) { 32 | this.toUserName = toUserName; 33 | } 34 | 35 | public String getFromUserName() { 36 | return fromUserName; 37 | } 38 | 39 | public void setFromUserName(String fromUserName) { 40 | this.fromUserName = fromUserName; 41 | } 42 | 43 | public int getCreateTime() { 44 | return createTime; 45 | } 46 | 47 | public void setCreateTime(int createTime) { 48 | this.createTime = createTime; 49 | } 50 | 51 | public String getMsgType() { 52 | return msgType; 53 | } 54 | 55 | public void setMsgType(String msgType) { 56 | this.msgType = msgType; 57 | } 58 | 59 | public String toXml(){ 60 | // 159 = 106 + 28(ToUserName) + 15(FromUserName) + 10(CreateTime) 61 | MessageBuilder builder = new MessageBuilder(159); 62 | builder.addData("ToUserName", getToUserName()); 63 | builder.addData("FromUserName", getFromUserName()); 64 | builder.addData("CreateTime", String.valueOf(System.currentTimeMillis()/1000)); 65 | return builder.toString(); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return toXml(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/resp/QYImageRespMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.resp; 2 | 3 | import com.github.sd4324530.fastweixin.message.RespType; 4 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 5 | 6 | /** 7 | * 微信企业号被动响应图片消息 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 14 | * ==================================================================== 15 | */ 16 | public class QYImageRespMsg extends QYBaseRespMsg { 17 | 18 | private String mediaId; 19 | 20 | public QYImageRespMsg() { 21 | } 22 | 23 | public QYImageRespMsg(String mediaId) { 24 | this.mediaId = mediaId; 25 | } 26 | 27 | public String getMediaId() { 28 | return mediaId; 29 | } 30 | 31 | public void setMediaId(String mediaId) { 32 | this.mediaId = mediaId; 33 | } 34 | 35 | @Override 36 | public String toXml(){ 37 | MessageBuilder mb = new MessageBuilder(super.toXml()); 38 | mb.addData("MsgType", RespType.IMAGE); 39 | mb.append("\n"); 40 | mb.addData("MediaId", mediaId); 41 | mb.append("\n"); 42 | mb.surroundWith("xml"); 43 | return mb.toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/resp/QYTextRespMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.resp; 2 | 3 | import com.github.sd4324530.fastweixin.message.RespType; 4 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 5 | 6 | /** 7 | * 微信企业号被动响应文本消息 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 1.3.6 14 | * ==================================================================== 15 | */ 16 | public class QYTextRespMsg extends QYBaseRespMsg { 17 | 18 | private StringBuilder contentBuilder; 19 | 20 | public QYTextRespMsg() { 21 | contentBuilder = new StringBuilder(); 22 | } 23 | 24 | public QYTextRespMsg(String content){ 25 | setContentBuilder(content); 26 | } 27 | 28 | public StringBuilder getContentBuilder() { 29 | return contentBuilder; 30 | } 31 | 32 | public void setContentBuilder(String content) { 33 | this.contentBuilder = new StringBuilder(content); 34 | } 35 | 36 | public QYTextRespMsg add(String text){ 37 | contentBuilder.append(text); 38 | return this; 39 | } 40 | 41 | public QYTextRespMsg addln(){ 42 | return add("\n"); 43 | } 44 | 45 | public QYTextRespMsg addln(String text){ 46 | contentBuilder.append(text); 47 | return addln(); 48 | } 49 | 50 | public QYTextRespMsg addLink(String text, String url){ 51 | contentBuilder.append("").append(text).append(""); 52 | return this; 53 | } 54 | 55 | @Override 56 | public String toXml() { 57 | MessageBuilder mb = new MessageBuilder(super.toXml()); 58 | mb.addData("Content", contentBuilder.toString().trim()); 59 | mb.addData("MsgType", RespType.TEXT); 60 | mb.surroundWith("xml"); 61 | return mb.toString(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/resp/QYVideoRespMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.resp; 2 | 3 | import com.github.sd4324530.fastweixin.message.RespType; 4 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 5 | 6 | /** 7 | * 微信企业号被动响应事件视频消息 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 1.3.6 14 | * ==================================================================== 15 | */ 16 | public class QYVideoRespMsg extends QYBaseRespMsg { 17 | private String mediaId; 18 | private String title; 19 | private String description; 20 | 21 | public QYVideoRespMsg() { 22 | } 23 | 24 | public QYVideoRespMsg(String mediaId, String title, String description) { 25 | this.mediaId = mediaId; 26 | this.title = title; 27 | this.description = description; 28 | } 29 | 30 | public String getMediaId() { 31 | return mediaId; 32 | } 33 | 34 | public void setMediaId(String mediaId) { 35 | this.mediaId = mediaId; 36 | } 37 | 38 | public String getTitle() { 39 | return title; 40 | } 41 | 42 | public void setTitle(String title) { 43 | this.title = title; 44 | } 45 | 46 | public String getDescription() { 47 | return description; 48 | } 49 | 50 | public void setDescription(String description) { 51 | this.description = description; 52 | } 53 | 54 | @Override 55 | public String toXml() { 56 | MessageBuilder mb = new MessageBuilder(super.toXml()); 57 | mb.addData("MsgType", RespType.VIDEO); 58 | mb.append("\n"); 63 | mb.surroundWith("xml"); 64 | return mb.toString(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/company/message/resp/QYVoiceRespMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.company.message.resp; 2 | 3 | import com.github.sd4324530.fastweixin.message.RespType; 4 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 5 | 6 | /** 7 | * 微信企业号被动响应语音消息 8 | * ==================================================================== 9 | * 上海聚攒软件开发有限公司 10 | * -------------------------------------------------------------------- 11 | * @author Nottyjay 12 | * @version 1.0.beta 13 | * @since 1.3.6 14 | * ==================================================================== 15 | */ 16 | public class QYVoiceRespMsg extends QYBaseRespMsg { 17 | 18 | private String mediaId; 19 | 20 | public QYVoiceRespMsg() { 21 | } 22 | 23 | public QYVoiceRespMsg(String mediaId) { 24 | this.mediaId = mediaId; 25 | } 26 | 27 | public String getMediaId() { 28 | return mediaId; 29 | } 30 | 31 | public void setMediaId(String mediaId) { 32 | this.mediaId = mediaId; 33 | } 34 | 35 | @Override 36 | public String toXml(){ 37 | MessageBuilder mb = new MessageBuilder(super.toXml()); 38 | mb.addData("MsgType", RespType.VOICE); 39 | mb.append("\n"); 40 | mb.addData("MediaId", mediaId); 41 | mb.append("\n"); 42 | mb.surroundWith("xml"); 43 | return mb.toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/exception/WeixinException.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.exception; 2 | 3 | /** 4 | * 微信API处理异常 5 | * 6 | * @author peiyu 7 | */ 8 | public class WeixinException extends RuntimeException { 9 | 10 | public WeixinException() { 11 | super(); 12 | } 13 | 14 | public WeixinException(String message) { 15 | super(message); 16 | } 17 | 18 | public WeixinException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | public WeixinException(Throwable cause) { 23 | super(cause); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/handle/AbstractApiConfigChangeHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.handle; 2 | 3 | import com.github.sd4324530.fastweixin.api.config.ConfigChangeNotice; 4 | import com.github.sd4324530.fastweixin.util.BeanUtil; 5 | 6 | import java.util.Observable; 7 | 8 | /** 9 | * 配置变化监听器抽象类 10 | * 11 | * @author peiyu 12 | */ 13 | public abstract class AbstractApiConfigChangeHandle implements ApiConfigChangeHandle { 14 | 15 | @Override 16 | public void update(Observable o, Object arg) { 17 | if (BeanUtil.nonNull(arg) && arg instanceof ConfigChangeNotice) { 18 | configChange((ConfigChangeNotice) arg); 19 | } 20 | } 21 | 22 | /** 23 | * 子类实现,当配置变化时会触发该方法 24 | * 25 | * @param notice 通知对象 26 | */ 27 | public abstract void configChange(ConfigChangeNotice notice); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/handle/ApiConfigChangeHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.handle; 2 | 3 | import java.util.Observer; 4 | 5 | /** 6 | * ApiConfig变化监听器,基于jdk自带观察者模式实现 7 | * 8 | * @author Nottyjay, peiyu 9 | * @see AbstractApiConfigChangeHandle 10 | */ 11 | public interface ApiConfigChangeHandle extends Observer { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/handle/EventHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.handle; 2 | 3 | import com.github.sd4324530.fastweixin.message.BaseMsg; 4 | import com.github.sd4324530.fastweixin.message.req.BaseEvent; 5 | 6 | /** 7 | * 微信事件处理器接口 8 | * 9 | * @author peiyu 10 | * @since 1.1 11 | */ 12 | public interface EventHandle { 13 | /** 14 | * 处理微信事件 15 | * 16 | * @param event 微信事件 17 | * @return 回复用户的消息 18 | */ 19 | BaseMsg handle(E event); 20 | 21 | /** 22 | * 在处理之前,判断本事件是否符合处理的条件 23 | * 24 | * @param event 事件 25 | * @return 是否需要处理 26 | */ 27 | boolean beforeHandle(E event); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/handle/MessageHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.handle; 2 | 3 | import com.github.sd4324530.fastweixin.message.BaseMsg; 4 | import com.github.sd4324530.fastweixin.message.req.BaseReqMsg; 5 | 6 | /** 7 | * 微信消息处理器接口 8 | * 9 | * @author peiyu 10 | * @since 1.1 11 | */ 12 | public interface MessageHandle { 13 | /** 14 | * 处理微信消息 15 | * 16 | * @param message 微信消息 17 | * @return 回复用户的消息 18 | */ 19 | BaseMsg handle(M message); 20 | 21 | /** 22 | * 在处理之前,判断本条消息是否符合处理的条件 23 | * 24 | * @param message 消息 25 | * @return 是否需要处理 26 | */ 27 | boolean beforeHandle(M message); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/Article.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 4 | 5 | public class Article { 6 | 7 | private String title; 8 | private String description; 9 | private String picUrl; 10 | private String url; 11 | 12 | public Article() { 13 | 14 | } 15 | 16 | public Article(String title) { 17 | this.title = title; 18 | } 19 | 20 | public Article(String title, String url) { 21 | this.title = title; 22 | this.url = url; 23 | } 24 | 25 | public Article(String title, String description, String picUrl, String url) { 26 | this.title = title; 27 | this.description = description; 28 | this.picUrl = picUrl; 29 | this.url = url; 30 | } 31 | 32 | public String getTitle() { 33 | return title; 34 | } 35 | 36 | public void setTitle(String title) { 37 | this.title = title; 38 | } 39 | 40 | public String getDescription() { 41 | return description; 42 | } 43 | 44 | public void setDescription(String description) { 45 | this.description = description; 46 | } 47 | 48 | public String getPicUrl() { 49 | return picUrl; 50 | } 51 | 52 | public void setPicUrl(String picUrl) { 53 | this.picUrl = picUrl; 54 | } 55 | 56 | public String getUrl() { 57 | return url; 58 | } 59 | 60 | public void setUrl(String url) { 61 | this.url = url; 62 | } 63 | 64 | public String toXml() { 65 | MessageBuilder mb = new MessageBuilder(); 66 | mb.addData("Title", title); 67 | mb.addData("Description", description); 68 | mb.addData("PicUrl", picUrl); 69 | mb.addData("Url", url); 70 | mb.surroundWith("item"); 71 | return mb.toString(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/BaseMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 4 | 5 | import java.io.Serializable; 6 | 7 | public class BaseMsg implements Serializable{ 8 | 9 | private String toUserName; 10 | private String fromUserName; 11 | private long createTime; 12 | private String msgType; 13 | 14 | public BaseMsg() { 15 | } 16 | 17 | public String getToUserName() { 18 | return toUserName; 19 | } 20 | 21 | public void setToUserName(String toUserName) { 22 | this.toUserName = toUserName; 23 | } 24 | 25 | public String getFromUserName() { 26 | return fromUserName; 27 | } 28 | 29 | public void setFromUserName(String fromUserName) { 30 | this.fromUserName = fromUserName; 31 | } 32 | 33 | public long getCreateTime() { 34 | return createTime; 35 | } 36 | 37 | public void setCreateTime(long createTime) { 38 | this.createTime = createTime; 39 | } 40 | 41 | public String getMsgType() { 42 | return msgType; 43 | } 44 | 45 | public void setMsgType(String msgType) { 46 | this.msgType = msgType; 47 | } 48 | 49 | public String toXml() { 50 | // 159 = 106 + 28(ToUserName) + 15(FromUserName) + 10(CreateTime) 51 | MessageBuilder builder = new MessageBuilder(159); 52 | builder.addData("ToUserName", getToUserName()); 53 | builder.addData("FromUserName", getFromUserName()); 54 | builder.addTag("CreateTime", String.valueOf(System.currentTimeMillis()) 55 | .substring(0, 10)); 56 | return builder.toString(); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return toXml(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/CustomMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 4 | import com.github.sd4324530.fastweixin.util.StrUtil; 5 | 6 | public class CustomMsg extends BaseMsg { 7 | 8 | private String kfAccount; 9 | 10 | public CustomMsg(){ 11 | 12 | } 13 | 14 | public CustomMsg(String kfAccount) { 15 | this.kfAccount = kfAccount; 16 | } 17 | 18 | public String getKfAccount() { 19 | return kfAccount; 20 | } 21 | 22 | public void setKfAccount(String kfAccount) { 23 | this.kfAccount = kfAccount; 24 | } 25 | 26 | @Override 27 | public String toXml() { 28 | MessageBuilder mb = new MessageBuilder(super.toXml()); 29 | mb.addData("MsgType", RespType.KF); 30 | //可以不指定客服 31 | if(StrUtil.isNotBlank(kfAccount)) { 32 | mb.append("\n"); 33 | mb.addData("KfAccount", kfAccount); 34 | mb.append("\n"); 35 | } 36 | mb.surroundWith("xml"); 37 | return mb.toString(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/ImageMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | 4 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 5 | 6 | /** 7 | * @author peiyu 8 | */ 9 | public class ImageMsg extends BaseMsg { 10 | 11 | private String mediaId; 12 | 13 | public ImageMsg() { 14 | } 15 | 16 | public ImageMsg(String mediaId) { 17 | this.mediaId = mediaId; 18 | } 19 | 20 | public String getMediaId() { 21 | return mediaId; 22 | } 23 | 24 | public void setMediaId(String mediaId) { 25 | this.mediaId = mediaId; 26 | } 27 | 28 | @Override 29 | public String toXml() { 30 | MessageBuilder mb = new MessageBuilder(super.toXml()); 31 | mb.addData("MsgType", RespType.IMAGE); 32 | mb.append("\n"); 33 | mb.addData("MediaId", mediaId); 34 | mb.append("\n"); 35 | mb.surroundWith("xml"); 36 | return mb.toString(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/MpNewsMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | /** 3 | * 提交至微信的图文消息素材 4 | * ==================================================================== 5 | * 上海聚攒软件开发有限公司 6 | * -------------------------------------------------------------------- 7 | * @author Nottyjay 8 | * @version 1.0.beta 9 | * ==================================================================== 10 | */ 11 | public class MpNewsMsg extends BaseMsg { 12 | 13 | private String mediaId; 14 | 15 | public MpNewsMsg() { 16 | } 17 | 18 | public MpNewsMsg(String mediaId) { 19 | this.mediaId = mediaId; 20 | } 21 | 22 | public String getMediaId() { 23 | return mediaId; 24 | } 25 | 26 | public void setMediaId(String mediaId) { 27 | this.mediaId = mediaId; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/MusicMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 4 | 5 | public class MusicMsg extends BaseMsg { 6 | 7 | private String title; 8 | private String description; 9 | private String musicUrl; 10 | private String hqMusicUrl; 11 | private String thumbMediaId; 12 | 13 | public MusicMsg(String thumbMediaId) { 14 | this.thumbMediaId = thumbMediaId; 15 | } 16 | 17 | public MusicMsg(String thumbMediaId, String title, String description, 18 | String musicUrl, String hqMusicUrl) { 19 | this.title = title; 20 | this.description = description; 21 | this.musicUrl = musicUrl; 22 | this.hqMusicUrl = hqMusicUrl; 23 | this.thumbMediaId = thumbMediaId; 24 | } 25 | 26 | public String getTitle() { 27 | return title; 28 | } 29 | 30 | public void setTitle(String title) { 31 | this.title = title; 32 | } 33 | 34 | public String getDescription() { 35 | return description; 36 | } 37 | 38 | public void setDescription(String description) { 39 | this.description = description; 40 | } 41 | 42 | public String getMusicUrl() { 43 | return musicUrl; 44 | } 45 | 46 | public void setMusicUrl(String musicUrl) { 47 | this.musicUrl = musicUrl; 48 | } 49 | 50 | public String getHqMusicUrl() { 51 | return hqMusicUrl; 52 | } 53 | 54 | public void setHqMusicUrl(String hqMusicUrl) { 55 | this.hqMusicUrl = hqMusicUrl; 56 | } 57 | 58 | public String getThumbMediaId() { 59 | return thumbMediaId; 60 | } 61 | 62 | public void setThumbMediaId(String thumbMediaId) { 63 | this.thumbMediaId = thumbMediaId; 64 | } 65 | 66 | @Override 67 | public String toXml() { 68 | MessageBuilder mb = new MessageBuilder(super.toXml()); 69 | mb.addData("MsgType", RespType.MUSIC); 70 | mb.append("\n"); 71 | mb.addData("Title", title); 72 | mb.addData("Description", description); 73 | mb.addData("MusicUrl", musicUrl); 74 | mb.addData("HQMusicUrl", hqMusicUrl); 75 | mb.addData("ThumbMediaId", thumbMediaId); 76 | mb.append("\n"); 77 | mb.surroundWith("xml"); 78 | return mb.toString(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/RespType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | public class RespType { 4 | 5 | public static final String TEXT = "text"; 6 | 7 | public static final String IMAGE = "image"; 8 | 9 | public static final String VOICE = "voice"; 10 | 11 | public static final String VIDEO = "video"; 12 | 13 | public static final String MUSIC = "music"; 14 | 15 | public static final String NEWS = "news"; 16 | 17 | public static final String KF = "transfer_customer_service"; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/TextMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 4 | 5 | public final class TextMsg extends BaseMsg { 6 | 7 | private StringBuilder contentBuilder; 8 | 9 | public TextMsg() { 10 | contentBuilder = new StringBuilder(); 11 | } 12 | 13 | public TextMsg(String content) { 14 | setContent(content); 15 | } 16 | 17 | public String getContent() { 18 | return contentBuilder.toString(); 19 | } 20 | 21 | public void setContent(String content) { 22 | contentBuilder = new StringBuilder(content); 23 | } 24 | 25 | public TextMsg add(String text) { 26 | contentBuilder.append(text); 27 | return this; 28 | } 29 | 30 | public TextMsg addln() { 31 | return add("\n"); 32 | } 33 | 34 | public TextMsg addln(String text) { 35 | contentBuilder.append(text); 36 | return addln(); 37 | } 38 | 39 | public TextMsg addLink(String text, String url) { 40 | contentBuilder.append("") 41 | .append(text).append(""); 42 | return this; 43 | } 44 | 45 | @Override 46 | public String toXml() { 47 | MessageBuilder mb = new MessageBuilder(super.toXml()); 48 | mb.addData("Content", contentBuilder.toString().trim()); 49 | mb.addData("MsgType", RespType.TEXT); 50 | mb.surroundWith("xml"); 51 | return mb.toString(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/VideoMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 4 | 5 | public class VideoMsg extends BaseMsg { 6 | 7 | private String mediaId; 8 | private String title; 9 | private String description; 10 | 11 | public VideoMsg(String mediaId) { 12 | this.mediaId = mediaId; 13 | } 14 | 15 | public VideoMsg(String mediaId, String title, String description) { 16 | this.mediaId = mediaId; 17 | this.title = title; 18 | this.description = description; 19 | } 20 | 21 | public String getMediaId() { 22 | return mediaId; 23 | } 24 | 25 | public void setMediaId(String mediaId) { 26 | this.mediaId = mediaId; 27 | } 28 | 29 | public String getTitle() { 30 | return title; 31 | } 32 | 33 | public void setTitle(String title) { 34 | this.title = title; 35 | } 36 | 37 | public String getDescription() { 38 | return description; 39 | } 40 | 41 | public void setDescription(String description) { 42 | this.description = description; 43 | } 44 | 45 | @Override 46 | public String toXml() { 47 | MessageBuilder mb = new MessageBuilder(super.toXml()); 48 | mb.addData("MsgType", RespType.VIDEO); 49 | mb.append("\n"); 54 | mb.surroundWith("xml"); 55 | return mb.toString(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/VoiceMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message; 2 | 3 | import com.github.sd4324530.fastweixin.message.util.MessageBuilder; 4 | 5 | /** 6 | * @author peiyu 7 | */ 8 | public class VoiceMsg extends BaseMsg { 9 | 10 | private String mediaId; 11 | 12 | public VoiceMsg(String mediaId) { 13 | this.mediaId = mediaId; 14 | } 15 | 16 | public String getMediaId() { 17 | return mediaId; 18 | } 19 | 20 | public void setMediaId(String mediaId) { 21 | this.mediaId = mediaId; 22 | } 23 | 24 | @Override 25 | public String toXml() { 26 | MessageBuilder mb = new MessageBuilder(super.toXml()); 27 | mb.addData("MsgType", RespType.VOICE); 28 | mb.append("\n"); 29 | mb.addData("MediaId", mediaId); 30 | mb.append("\n"); 31 | mb.surroundWith("xml"); 32 | return mb.toString(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/aes/AesException.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.aes; 2 | 3 | @SuppressWarnings("serial") 4 | public class AesException extends Exception { 5 | 6 | public final static int OK = 0; 7 | public final static int ValidateSignatureError = -40001; 8 | public final static int ParseXmlError = -40002; 9 | public final static int ComputeSignatureError = -40003; 10 | public final static int IllegalAesKey = -40004; 11 | public final static int ValidateAppidError = -40005; 12 | public final static int EncryptAESError = -40006; 13 | public final static int DecryptAESError = -40007; 14 | public final static int IllegalBuffer = -40008; 15 | //public final static int EncodeBase64Error = -40009; 16 | //public final static int DecodeBase64Error = -40010; 17 | //public final static int GenReturnXmlError = -40011; 18 | 19 | private int code; 20 | 21 | AesException(int code) { 22 | super(getMessage(code)); 23 | this.code = code; 24 | } 25 | 26 | private static String getMessage(int code) { 27 | switch (code) { 28 | case ValidateSignatureError: 29 | return "签名验证错误"; 30 | case ParseXmlError: 31 | return "xml解析失败"; 32 | case ComputeSignatureError: 33 | return "sha加密生成签名失败"; 34 | case IllegalAesKey: 35 | return "SymmetricKey非法"; 36 | case ValidateAppidError: 37 | return "appid校验失败"; 38 | case EncryptAESError: 39 | return "aes加密失败"; 40 | case DecryptAESError: 41 | return "aes解密失败"; 42 | case IllegalBuffer: 43 | return "解密后得到的buffer非法"; 44 | // case EncodeBase64Error: 45 | // return "base64加密错误"; 46 | // case DecodeBase64Error: 47 | // return "base64解密错误"; 48 | // case GenReturnXmlError: 49 | // return "xml生成失败"; 50 | default: 51 | return null; // cannot be 52 | } 53 | } 54 | 55 | public int getCode() { 56 | return code; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/aes/ByteGroup.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.aes; 2 | 3 | import java.util.ArrayList; 4 | 5 | class ByteGroup { 6 | ArrayList byteContainer = new ArrayList(); 7 | 8 | public byte[] toBytes() { 9 | byte[] bytes = new byte[byteContainer.size()]; 10 | for (int i = 0; i < byteContainer.size(); i++) { 11 | bytes[i] = byteContainer.get(i); 12 | } 13 | return bytes; 14 | } 15 | 16 | public ByteGroup addBytes(byte[] bytes) { 17 | for (byte b : bytes) { 18 | byteContainer.add(b); 19 | } 20 | return this; 21 | } 22 | 23 | public int size() { 24 | return byteContainer.size(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/aes/PKCS7Encoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 对公众平台发送给公众账号的消息加解密示例代码. 3 | * 4 | * @copyright Copyright (c) 1998-2014 Tencent Inc. 5 | */ 6 | 7 | // ------------------------------------------------------------------------ 8 | 9 | package com.github.sd4324530.fastweixin.message.aes; 10 | 11 | import java.nio.charset.Charset; 12 | import java.util.Arrays; 13 | 14 | /** 15 | * 提供基于PKCS7算法的加解密接口. 16 | */ 17 | class PKCS7Encoder { 18 | static Charset CHARSET = Charset.forName("utf-8"); 19 | static int BLOCK_SIZE = 32; 20 | 21 | /** 22 | * 获得对明文进行补位填充的字节. 23 | * 24 | * @param count 需要进行填充补位操作的明文字节个数 25 | * @return 补齐用的字节数组 26 | */ 27 | static byte[] encode(int count) { 28 | // 计算需要填充的位数 29 | int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); 30 | if (amountToPad == 0) { 31 | amountToPad = BLOCK_SIZE; 32 | } 33 | // 获得补位所用的字符 34 | char padChr = chr(amountToPad); 35 | String tmp = new String(); 36 | for (int index = 0; index < amountToPad; index++) { 37 | tmp += padChr; 38 | } 39 | return tmp.getBytes(CHARSET); 40 | } 41 | 42 | /** 43 | * 删除解密后明文的补位字符 44 | * 45 | * @param decrypted 解密后的明文 46 | * @return 删除补位字符后的明文 47 | */ 48 | static byte[] decode(byte[] decrypted) { 49 | int pad = (int) decrypted[decrypted.length - 1]; 50 | if (pad < 1 || pad > 32) { 51 | pad = 0; 52 | } 53 | return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); 54 | } 55 | 56 | /** 57 | * 将数字转化成ASCII码对应的字符,用于对明文进行补码 58 | * 59 | * @param a 需要转化的数字 60 | * @return 转化得到的字符 61 | */ 62 | static char chr(int a) { 63 | byte target = (byte) (a & 0xFF); 64 | return (char) target; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/aes/SHA1.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 对公众平台发送给公众账号的消息加解密示例代码. 3 | * 4 | * @copyright Copyright (c) 1998-2014 Tencent Inc. 5 | */ 6 | 7 | // ------------------------------------------------------------------------ 8 | 9 | package com.github.sd4324530.fastweixin.message.aes; 10 | 11 | import java.security.MessageDigest; 12 | import java.util.Arrays; 13 | 14 | /** 15 | * SHA1 class 16 | * 计算公众平台的消息签名接口. 17 | */ 18 | public class SHA1 { 19 | 20 | /** 21 | * 用SHA1算法生成安全签名 22 | * 23 | * @param token 票据 24 | * @param timestamp 时间戳 25 | * @param nonce 随机字符串 26 | * @param encrypt 密文 27 | * @return 安全签名 28 | * @throws AesException AES算法异常 29 | */ 30 | public static String getSHA1(String token, String timestamp, String nonce, String encrypt) throws AesException { 31 | try { 32 | String[] array = new String[]{token, timestamp, nonce, encrypt}; 33 | StringBuffer sb = new StringBuffer(); 34 | // 字符串排序 35 | Arrays.sort(array); 36 | for (int i = 0; i < 4; i++) { 37 | sb.append(array[i]); 38 | } 39 | String str = sb.toString(); 40 | 41 | return getSHA1HexString(str); 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | throw new AesException(AesException.ComputeSignatureError); 45 | } 46 | } 47 | 48 | public static String getSHA1HexString(String str) throws Exception { 49 | // SHA1签名生成 50 | MessageDigest md = MessageDigest.getInstance("SHA-1"); 51 | md.update(str.getBytes()); 52 | byte[] digest = md.digest(); 53 | 54 | StringBuffer hexstr = new StringBuffer(); 55 | String shaHex = ""; 56 | for (int i = 0; i < digest.length; i++) { 57 | shaHex = Integer.toHexString(digest[i] & 0xFF); 58 | if (shaHex.length() < 2) { 59 | hexstr.append(0); 60 | } 61 | hexstr.append(shaHex); 62 | } 63 | return hexstr.toString(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/BaseEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public class BaseEvent extends BaseReq { 4 | 5 | private String event; 6 | 7 | public BaseEvent() { 8 | setMsgType(ReqType.EVENT); 9 | } 10 | 11 | public String getEvent() { 12 | return event; 13 | } 14 | 15 | public void setEvent(String event) { 16 | this.event = event; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/BaseReq.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public class BaseReq { 4 | 5 | String toUserName; 6 | String fromUserName; 7 | long createTime; 8 | String msgType; 9 | 10 | public String getToUserName() { 11 | return toUserName; 12 | } 13 | 14 | public void setToUserName(String toUserName) { 15 | this.toUserName = toUserName; 16 | } 17 | 18 | public String getFromUserName() { 19 | return fromUserName; 20 | } 21 | 22 | public void setFromUserName(String fromUserName) { 23 | this.fromUserName = fromUserName; 24 | } 25 | 26 | public long getCreateTime() { 27 | return createTime; 28 | } 29 | 30 | public void setCreateTime(long createTime) { 31 | this.createTime = createTime; 32 | } 33 | 34 | public String getMsgType() { 35 | return msgType; 36 | } 37 | 38 | public void setMsgType(String msgType) { 39 | this.msgType = msgType; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/BaseReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public class BaseReqMsg extends BaseReq { 4 | 5 | String msgId; 6 | 7 | public String getMsgId() { 8 | return msgId; 9 | } 10 | 11 | public void setMsgId(String msgId) { 12 | this.msgId = msgId; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/EventType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class EventType { 4 | 5 | public static final String SUBSCRIBE = "subscribe"; 6 | public static final String UNSUBSCRIBE = "unsubscribe"; 7 | public static final String CLICK = "CLICK"; 8 | public static final String VIEW = "VIEW"; 9 | public static final String LOCATION = "LOCATION"; 10 | public static final String SCAN = "SCAN"; 11 | public static final String SCANCODEPUSH = "scancode_push"; 12 | public static final String SCANCODEWAITMSG = "scancode_waitmsg"; 13 | public static final String PICSYSPHOTO = "pic_sysphoto"; 14 | public static final String PICPHOTOORALBUM = "pic_photo_or_album"; 15 | public static final String PICWEIXIN = "pic_weixin"; 16 | public static final String LOCATIONSELECT = "location_select"; 17 | public static final String TEMPLATESENDJOBFINISH = "TEMPLATESENDJOBFINISH"; 18 | public static final String MASSSENDJOBFINISH="MASSSENDJOBFINISH"; 19 | 20 | private EventType() { 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/ImageReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public final class ImageReqMsg extends BaseReqMsg { 7 | 8 | private String picUrl; 9 | private String mediaId; 10 | 11 | public ImageReqMsg(String picUrl, String mediaId) { 12 | super(); 13 | this.picUrl = picUrl; 14 | this.mediaId = mediaId; 15 | setMsgType(ReqType.IMAGE); 16 | } 17 | 18 | public String getPicUrl() { 19 | return picUrl; 20 | } 21 | 22 | public String getMediaId() { 23 | return mediaId; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "ImageReqMsg [picUrl=" + picUrl + ", mediaId=" + mediaId 29 | + ", toUserName=" + toUserName + ", fromUserName=" 30 | + fromUserName + ", createTime=" + createTime + ", msgType=" 31 | + msgType + ", msgId=" + msgId + "]"; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/LinkReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class LinkReqMsg extends BaseReqMsg { 4 | 5 | private String title; 6 | private String description; 7 | private String url; 8 | 9 | public LinkReqMsg(String title, String description, String url) { 10 | super(); 11 | this.title = title; 12 | this.description = description; 13 | this.url = url; 14 | setMsgType(ReqType.EVENT); 15 | } 16 | 17 | public String getTitle() { 18 | return title; 19 | } 20 | 21 | public String getDescription() { 22 | return description; 23 | } 24 | 25 | public String getUrl() { 26 | return url; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "LinkReqMsg [title=" + title + ", description=" + description 32 | + ", url=" + url + ", toUserName=" + toUserName 33 | + ", fromUserName=" + fromUserName + ", createTime=" 34 | + createTime + ", msgType=" + msgType + ", msgId=" + msgId 35 | + "]"; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/LocationEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class LocationEvent extends BaseEvent { 4 | 5 | private double latitude; 6 | private double longitude; 7 | private double precision; 8 | 9 | public LocationEvent(double latitude, double longitude, double precision) { 10 | super(); 11 | this.latitude = latitude; 12 | this.longitude = longitude; 13 | this.precision = precision; 14 | } 15 | 16 | public double getLatitude() { 17 | return latitude; 18 | } 19 | 20 | public double getLongitude() { 21 | return longitude; 22 | } 23 | 24 | public double getPrecision() { 25 | return precision; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "LocationEvent [latitude=" + latitude + ", longitude=" 31 | + longitude + ", precision=" + precision + ", toUserName=" 32 | + toUserName + ", fromUserName=" + fromUserName 33 | + ", createTime=" + createTime + ", msgType=" + msgType + "]"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/LocationReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class LocationReqMsg extends BaseReqMsg { 4 | 5 | private double locationX; 6 | private double locationY; 7 | private int scale; 8 | private String label; 9 | 10 | public LocationReqMsg(double locationX, double locationY, int scale, 11 | String label) { 12 | super(); 13 | this.locationX = locationX; 14 | this.locationY = locationY; 15 | this.scale = scale; 16 | this.label = label; 17 | setMsgType(ReqType.LOCATION); 18 | } 19 | 20 | public double getLocationX() { 21 | return locationX; 22 | } 23 | 24 | public double getLocationY() { 25 | return locationY; 26 | } 27 | 28 | public int getScale() { 29 | return scale; 30 | } 31 | 32 | public String getLabel() { 33 | return label; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "LocationReqMsg [locationX=" + locationX + ", locationY=" 39 | + locationY + ", scale=" + scale + ", label=" + label 40 | + ", toUserName=" + toUserName + ", fromUserName=" 41 | + fromUserName + ", createTime=" + createTime + ", msgType=" 42 | + msgType + ", msgId=" + msgId + "]"; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/MenuEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class MenuEvent extends BaseEvent { 4 | 5 | private String eventKey; 6 | 7 | public MenuEvent(String eventKey) { 8 | super(); 9 | this.eventKey = eventKey; 10 | } 11 | 12 | public String getEventKey() { 13 | return eventKey; 14 | } 15 | 16 | @Override 17 | public String getEvent() { 18 | return super.getEvent(); 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "MenuEvent [eventKey=" + eventKey + ", toUserName=" + toUserName 24 | + ", fromUserName=" + fromUserName + ", createTime=" 25 | + createTime + ", msgType=" + msgType + "]"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/QrCodeEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class QrCodeEvent extends BaseEvent { 4 | 5 | private String eventKey; 6 | private String ticket; 7 | 8 | public QrCodeEvent(String eventKey, String ticket) { 9 | super(); 10 | this.eventKey = eventKey; 11 | this.ticket = ticket; 12 | } 13 | 14 | public String getEventKey() { 15 | return eventKey; 16 | } 17 | 18 | public String getTicket() { 19 | return ticket; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "QrCodeEvent [eventKey=" + eventKey + ", ticket=" + ticket 25 | + ", toUserName=" + toUserName + ", fromUserName=" 26 | + fromUserName + ", createTime=" + createTime + ", msgType=" 27 | + msgType + "]"; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/ReqType.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class ReqType { 4 | 5 | public static final String TEXT = "text"; 6 | public static final String IMAGE = "image"; 7 | public static final String LINK = "link"; 8 | public static final String LOCATION = "location"; 9 | public static final String VOICE = "voice"; 10 | public static final String VIDEO = "video"; 11 | public static final String SHORT_VIDEO = "shortvideo"; 12 | public static final String EVENT = "event"; 13 | 14 | private ReqType() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/ScanCodeEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class ScanCodeEvent extends BaseEvent { 4 | 5 | private String eventKey; 6 | private String scanType; 7 | private String scanResult; 8 | 9 | public ScanCodeEvent(String eventKey, String scanType, String scanResult) { 10 | super(); 11 | this.eventKey = eventKey; 12 | this.scanType = scanType; 13 | this.scanResult = scanResult; 14 | } 15 | 16 | public String getEventKey() { 17 | return eventKey; 18 | } 19 | 20 | public void setEventKey(String eventKey) { 21 | this.eventKey = eventKey; 22 | } 23 | 24 | public String getScanType() { 25 | return scanType; 26 | } 27 | 28 | public void setScanType(String scanType) { 29 | this.scanType = scanType; 30 | } 31 | 32 | public String getScanResult() { 33 | return scanResult; 34 | } 35 | 36 | public void setScanResult(String scanResult) { 37 | this.scanResult = scanResult; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "ScanCodeEvent [eventKey=" + eventKey + ", scanType=" + scanType + ", scanResult=" + scanResult + ", toUserName=" + toUserName 43 | + ", fromUserName=" + fromUserName + ", createTime=" 44 | + createTime + ", msgType=" + msgType + "]"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/SendMessageEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | /** 4 | * Created by jileilei on 15/8/10. 5 | */ 6 | public class SendMessageEvent extends BaseEvent{ 7 | private String msgId;//群发的消息ID 8 | private String status;//群发消息状态 9 | private Integer totalCount;//发送总数 10 | private Integer filterCount;//过滤后的数量 11 | private Integer sentCount;//发送成功数量 12 | private Integer errorCount;//发送失败数量 13 | 14 | public SendMessageEvent() { 15 | super(); 16 | } 17 | 18 | public SendMessageEvent(String msgId, String status, Integer totalCount, Integer filterCount, Integer sentCount, Integer errorCount){ 19 | super(); 20 | this.msgId=msgId; 21 | this.status=status; 22 | this.totalCount=totalCount; 23 | this.filterCount=filterCount; 24 | this.sentCount=sentCount; 25 | this.errorCount=errorCount; 26 | } 27 | 28 | public String getMsgId() { 29 | return msgId; 30 | } 31 | 32 | public void setMsgId(String msgId) { 33 | this.msgId = msgId; 34 | } 35 | 36 | public String getStatus() { 37 | return status; 38 | } 39 | 40 | public void setStatus(String status) { 41 | this.status = status; 42 | } 43 | public Integer getTotalCount() { 44 | return totalCount; 45 | } 46 | 47 | public void setTotalCount(Integer totalCount) { 48 | this.totalCount = totalCount; 49 | } 50 | 51 | public Integer getFilterCount() { 52 | return filterCount; 53 | } 54 | 55 | public void setFilterCount(Integer filterCount) { 56 | this.filterCount = filterCount; 57 | } 58 | 59 | public Integer getSentCount() { 60 | return sentCount; 61 | } 62 | 63 | public void setSentCount(Integer sentCount) { 64 | this.sentCount = sentCount; 65 | } 66 | 67 | public Integer getErrorCount() { 68 | return errorCount; 69 | } 70 | 71 | public void setErrorCount(Integer errorCount) { 72 | this.errorCount = errorCount; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/SendPicsInfoEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class SendPicsInfoEvent extends BaseEvent { 7 | 8 | private String eventKey; 9 | private Integer count; 10 | private List picList; 11 | 12 | public SendPicsInfoEvent(String eventKey, Integer count, List picList) { 13 | super(); 14 | this.eventKey = eventKey; 15 | this.count = count; 16 | this.picList = picList; 17 | } 18 | 19 | public String getEventKey() { 20 | return eventKey; 21 | } 22 | 23 | public void setEventKey(String eventKey) { 24 | this.eventKey = eventKey; 25 | } 26 | 27 | public Integer getCount() { 28 | return count; 29 | } 30 | 31 | public void setCount(Integer count) { 32 | this.count = count; 33 | } 34 | 35 | public List getPicList() { 36 | return picList; 37 | } 38 | 39 | public void setPicList(List picList) { 40 | this.picList = picList; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "SendPicsInfoEvent{" + 46 | "eventKey='" + eventKey + '\'' + 47 | ", count=" + count + 48 | ", picList=" + picList + 49 | '}'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/TemplateMsgEvent.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | /** 4 | * Created by Ben on 2015/6/24. 5 | */ 6 | public class TemplateMsgEvent extends BaseEvent { 7 | private String msgId; 8 | private String status; 9 | 10 | public TemplateMsgEvent() { 11 | } 12 | 13 | public TemplateMsgEvent(String msgId, String status) { 14 | this.msgId = msgId; 15 | this.status = status; 16 | } 17 | 18 | public String getMsgId() { 19 | return msgId; 20 | } 21 | 22 | public void setMsgId(String msgId) { 23 | this.msgId = msgId; 24 | } 25 | 26 | public String getStatus() { 27 | return status; 28 | } 29 | 30 | public void setStatus(String status) { 31 | this.status = status; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/TextReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class TextReqMsg extends BaseReqMsg { 4 | 5 | private String content; 6 | 7 | public TextReqMsg(String content) { 8 | super(); 9 | this.content = content; 10 | setMsgType(ReqType.TEXT); 11 | } 12 | 13 | public String getContent() { 14 | return content; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return "TextReqMsg [content=" + content + ", toUserName=" + toUserName 20 | + ", fromUserName=" + fromUserName + ", createTime=" 21 | + createTime + ", msgType=" + msgType + ", msgId=" + msgId 22 | + "]"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/VideoReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | public final class VideoReqMsg extends BaseReqMsg { 4 | 5 | private String mediaId; 6 | private String thumbMediaId; 7 | 8 | public VideoReqMsg(String mediaId, String thumbMediaId) { 9 | super(); 10 | this.mediaId = mediaId; 11 | this.thumbMediaId = thumbMediaId; 12 | setMsgType(ReqType.VIDEO); 13 | } 14 | 15 | public String getMediaId() { 16 | return mediaId; 17 | } 18 | 19 | public String getThumbMediaId() { 20 | return thumbMediaId; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "VideoReqMsg [mediaId=" + mediaId + ", thumbMediaId=" 26 | + thumbMediaId + ", toUserName=" + toUserName 27 | + ", fromUserName=" + fromUserName + ", createTime=" 28 | + createTime + ", msgType=" + msgType + ", msgId=" + msgId 29 | + "]"; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/req/VoiceReqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.req; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public final class VoiceReqMsg extends BaseReqMsg { 7 | 8 | private String mediaId; 9 | private String format; 10 | private String recognition; 11 | 12 | public VoiceReqMsg(String mediaId, String format, String recognition) { 13 | super(); 14 | this.mediaId = mediaId; 15 | this.format = format; 16 | this.recognition = recognition; 17 | setMsgType(ReqType.VOICE); 18 | } 19 | 20 | public String getMediaId() { 21 | return mediaId; 22 | } 23 | 24 | public String getFormat() { 25 | return format; 26 | } 27 | 28 | public String getRecognition() { 29 | return recognition; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "VoiceReqMsg [mediaId=" + mediaId + ", format=" + format 35 | + ", recognition=" + recognition + ", msgId=" + msgId 36 | + ", toUserName=" + toUserName + ", fromUserName=" 37 | + fromUserName + ", createTime=" + createTime + ", msgType=" 38 | + msgType + "]"; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/message/util/MessageBuilder.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.message.util; 2 | 3 | /** 4 | * @author peiyu 5 | */ 6 | public class MessageBuilder { 7 | 8 | private StringBuilder builder; 9 | 10 | public MessageBuilder() { 11 | builder = new StringBuilder(); 12 | } 13 | 14 | public MessageBuilder(int capacity) { 15 | builder = new StringBuilder(capacity); 16 | } 17 | 18 | public MessageBuilder(String str) { 19 | builder = new StringBuilder(str); 20 | } 21 | 22 | public void append(String str) { 23 | builder.append(str); 24 | } 25 | 26 | public void insert(String str) { 27 | builder.insert(0, str); 28 | } 29 | 30 | public void surroundWith(String tag) { 31 | StringBuilder sb = new StringBuilder(builder.capacity() + tag.length() 32 | * 2 + 5); 33 | sb.append("<").append(tag).append(">\n").append(builder).append("\n"); 35 | builder = sb; 36 | } 37 | 38 | public void addTag(String tagName, String text) { 39 | if (text == null) { 40 | return; 41 | } 42 | builder.append("<").append(tagName).append(">").append(text) 43 | .append("\n"); 44 | } 45 | 46 | public void addData(String tagName, String data) { 47 | if (data == null) { 48 | return; 49 | } 50 | builder.append("<").append(tagName).append(">\n"); 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return builder.toString(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/servlet/WeixinControllerSupport.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.servlet; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.io.PrintWriter; 13 | 14 | /** 15 | * 微信公众平台交互操作基类,提供几乎所有微信公众平台交互方式 16 | * 基于springmvc框架,方便使用此框架的项目集成 17 | * 18 | * @author peiyu 19 | */ 20 | @Controller 21 | public abstract class WeixinControllerSupport extends WeixinSupport { 22 | 23 | /** 24 | * 绑定微信服务器 25 | * 26 | * @param request 请求 27 | * @return 响应内容 28 | */ 29 | @RequestMapping(method = RequestMethod.GET) 30 | @ResponseBody 31 | protected final String bind(HttpServletRequest request) { 32 | if (isLegal(request)) { 33 | //绑定微信服务器成功 34 | return request.getParameter("echostr"); 35 | } else { 36 | //绑定微信服务器失败 37 | return ""; 38 | } 39 | } 40 | 41 | /** 42 | * 微信消息交互处理 43 | * 44 | * @param request http 请求对象 45 | * @param response http 响应对象 46 | * @throws ServletException 异常 47 | * @throws IOException IO异常 48 | */ 49 | @RequestMapping(method = RequestMethod.POST) 50 | protected final void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 51 | if (isLegal(request)) { 52 | String result = processRequest(request); 53 | //设置正确的 content-type 以防止中文乱码 54 | response.setContentType("text/xml;charset=UTF-8"); 55 | PrintWriter writer = response.getWriter(); 56 | writer.write(result); 57 | writer.close(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/servlet/WeixinServletSupport.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.servlet; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.io.PrintWriter; 12 | 13 | /** 14 | * 微信公众平台交互操作基类,提供几乎所有微信公众平台交互方式 15 | * 基于javaee servlet框架,方便使用此框架的项目集成 16 | * 17 | * @author peiyu 18 | * @since 1.1 19 | */ 20 | public abstract class WeixinServletSupport extends HttpServlet { 21 | 22 | private static final Logger LOG = LoggerFactory.getLogger(WeixinServletSupport.class); 23 | private final WeixinSupport support = getWeixinSupport(); 24 | 25 | /** 26 | * 强制要求servlet框架开发者自行实现weixinSupport类 27 | * 28 | * @return 用户自行实现的weixinSupport对象 29 | */ 30 | protected abstract WeixinSupport getWeixinSupport(); 31 | 32 | /** 33 | * 重写servlet中的get方法,用于处理微信服务器绑定,置为final方法,用户已经无需重写这个方法啦 34 | * 35 | * @param request http请求对象 36 | * @param response http响应对象 37 | * @throws ServletException servlet异常 38 | * @throws IOException IO异常 39 | */ 40 | @Override 41 | protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 42 | support.bindServer(request, response); 43 | } 44 | 45 | /** 46 | * 重写servlet中的post方法,用于接收微信服务器发来的消息,置为final方法,用户已经无需重写这个方法啦 47 | * 48 | * @param request http请求对象 49 | * @param response http响应对象 50 | * @throws ServletException servlet异常 51 | * @throws IOException IO异常 52 | */ 53 | @Override 54 | protected final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 55 | if (!support.isLegal(request)) { 56 | return; 57 | } 58 | //设置响应编码格式 59 | response.setCharacterEncoding("UTF-8"); 60 | String resp = support.processRequest(request); 61 | PrintWriter pw = response.getWriter(); 62 | pw.write(resp); 63 | pw.flush(); 64 | pw.close(); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/util/BeanUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.util; 2 | 3 | /** 4 | * 对象常用方法工具类 5 | * 6 | * @author peiyu 7 | */ 8 | public final class BeanUtil { 9 | 10 | /** 11 | * 此类不需要实例化 12 | */ 13 | private BeanUtil() { 14 | } 15 | 16 | /** 17 | * 判断对象是否为null 18 | * 19 | * @param object 需要判断的对象 20 | * @return 是否为null 21 | */ 22 | public static boolean isNull(Object object) { 23 | return null == object; 24 | } 25 | 26 | /** 27 | * 判断对象是否不为null 28 | * 29 | * @param object 需要判断的对象 30 | * @return 是否不为null 31 | */ 32 | public static boolean nonNull(Object object) { 33 | return null != object; 34 | } 35 | 36 | /** 37 | * 判断对象是否为空,如果为空,直接抛出异常 38 | * 39 | * @param object 需要检查的对象 40 | * @param errorMessage 异常信息 41 | * @return 非空的对象 42 | */ 43 | public static Object requireNonNull(Object object, String errorMessage) { 44 | if (null == object) { 45 | throw new NullPointerException(errorMessage); 46 | } 47 | return object; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/util/CollectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.Collections; 6 | 7 | /** 8 | * 集合常用方法工具类 9 | * 10 | * @author peiyu 11 | */ 12 | public final class CollectionUtil { 13 | 14 | /** 15 | * 此类不需要实例化 16 | */ 17 | private CollectionUtil() { 18 | } 19 | 20 | /** 21 | * 判断一个集合是否为空 22 | * null或者空集合都会返回true 23 | * 24 | * @param collection 需要判断的集合 25 | * @return 是否有值,null或者空集合都是返回true 26 | */ 27 | public static boolean isEmpty(Collection collection) { 28 | return null == collection || collection.isEmpty(); 29 | } 30 | 31 | /** 32 | * 判断一个集合是否不为空 33 | * 34 | * @param collection 需要判断的集合 35 | * @return 是否不为空 36 | */ 37 | public static boolean isNotEmpty(Collection collection) { 38 | return null != collection && !collection.isEmpty(); 39 | } 40 | 41 | /** 42 | * 创建一个空集合 43 | * 44 | * @param 泛型 45 | * @return 集合对象 46 | */ 47 | public static ArrayList newArrayList() { 48 | return new ArrayList(); 49 | } 50 | 51 | /** 52 | * 创建一个指定大小的集合 53 | * 54 | * @param initialCapacity 集合大小 55 | * @param 泛型 56 | * @return 集合对象 57 | */ 58 | public static ArrayList newArrayList(int initialCapacity) { 59 | return new ArrayList(initialCapacity); 60 | } 61 | 62 | /** 63 | * 创建一个有默认内容的集合 64 | * 65 | * @param 泛型 66 | * @param ele 内容 67 | * @return 集合对象 68 | */ 69 | public static ArrayList newArrayList(T... ele) { 70 | ArrayList list = null; 71 | if (null != ele && 0 != ele.length) { 72 | list = newArrayList(ele.length); 73 | Collections.addAll(list, ele); 74 | } 75 | return list; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/util/JsApiUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.util; 2 | 3 | import com.github.sd4324530.fastweixin.message.aes.SHA1; 4 | 5 | import java.util.Map; 6 | import java.util.TreeMap; 7 | 8 | /** 9 | * @author daxiaoming 10 | */ 11 | public class JsApiUtil { 12 | /** 13 | * 计算 wx.config() 中需要使用的签名。每个页面都需要进行计算 14 | * 15 | * @param jsApiTicket 微信 js-sdk提供的ticket 16 | * @param nonceStr 随机字符串 17 | * @param timestame 时间戳 18 | * @param url 当前网页的URL,不包含#及其后面部分 19 | * @return 合法的签名 20 | * @throws Exception 获取签名异常 21 | */ 22 | public static String sign(String jsApiTicket, String nonceStr, long timestame, String url) throws Exception { 23 | Map paramMap = new TreeMap(); 24 | paramMap.put("jsapi_ticket", jsApiTicket); 25 | paramMap.put("noncestr", nonceStr); 26 | paramMap.put("timestamp", Long.toString(timestame)); 27 | paramMap.put("url", url); 28 | 29 | StringBuilder sb = new StringBuilder(); 30 | for (Map.Entry entry : paramMap.entrySet()) { 31 | sb.append("&").append(entry.toString()); 32 | } 33 | return SHA1.getSHA1HexString(sb.substring(1)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/util/StrUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.util; 2 | 3 | /** 4 | * 字符串常用方法工具类 5 | * 6 | * @author peiyu 7 | */ 8 | public final class StrUtil { 9 | 10 | /** 11 | * 此类不需要实例化 12 | */ 13 | private StrUtil() { 14 | } 15 | 16 | /** 17 | * 判断一个字符串是否为空,null也会返回true 18 | * 19 | * @param str 需要判断的字符串 20 | * @return 是否为空,null也会返回true 21 | */ 22 | public static boolean isBlank(String str) { 23 | return null == str || "".equals(str.trim()); 24 | } 25 | 26 | /** 27 | * 判断一个字符串是否不为空 28 | * 29 | * @param str 需要判断的字符串 30 | * @return 是否为空 31 | */ 32 | public static boolean isNotBlank(String str) { 33 | return !isBlank(str); 34 | } 35 | 36 | /** 37 | * 判断一组字符串是否有空值 38 | * 39 | * @param strs 需要判断的一组字符串 40 | * @return 判断结果,只要其中一个字符串为null或者为空,就返回true 41 | */ 42 | public static boolean hasBlank(String... strs) { 43 | if (null == strs || 0 == strs.length) { 44 | return true; 45 | } else { 46 | //这种代码如果用java8就会很优雅了 47 | for (String str : strs) { 48 | if (isBlank(str)) { 49 | return true; 50 | } 51 | } 52 | } 53 | return false; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/com/github/sd4324530/fastweixin/util/StreamUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin.util; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.Closeable; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.OutputStream; 10 | 11 | /** 12 | * 套接字工具类 13 | * 14 | * @author peiyu 15 | */ 16 | public final class StreamUtil { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(StreamUtil.class); 19 | 20 | private StreamUtil() { 21 | } 22 | 23 | /** 24 | * 将输入流的内容复制到输出流里 25 | * 26 | * @param in 输入流 27 | * @param out 输出流 28 | * @return 复制的数据字节数 29 | * @throws IOException IO异常 30 | */ 31 | public static int copy(InputStream in, OutputStream out) throws IOException { 32 | BeanUtil.requireNonNull(in, "No InputStream specified"); 33 | BeanUtil.requireNonNull(out, "No OutputStream specified"); 34 | int byteCount = 0; 35 | byte[] buffer = new byte[4096]; 36 | int bytesRead1; 37 | for (; (bytesRead1 = in.read(buffer)) != -1; byteCount += bytesRead1) { 38 | out.write(buffer, 0, bytesRead1); 39 | } 40 | out.flush(); 41 | return byteCount; 42 | } 43 | 44 | /** 45 | * 关闭需要关闭的对象,如果关闭出错,给出警告 46 | * 47 | * @param closeable 需要关闭的对象 48 | */ 49 | public static void closeWithWarn(Closeable closeable) { 50 | if (BeanUtil.nonNull(closeable)) { 51 | try { 52 | closeable.close(); 53 | } catch (IOException e) { 54 | LOG.warn("关闭流出错......", e); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/github/sd4324530/fastweixin/TestConfigChangeHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.sd4324530.fastweixin; 2 | 3 | import com.github.sd4324530.fastweixin.api.config.ConfigChangeNotice; 4 | import com.github.sd4324530.fastweixin.handle.AbstractApiConfigChangeHandle; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | /** 9 | * @author peiyu 10 | */ 11 | public class TestConfigChangeHandle extends AbstractApiConfigChangeHandle { 12 | 13 | private static final Logger LOG = LoggerFactory.getLogger(TestConfigChangeHandle.class); 14 | 15 | @Override 16 | public void configChange(ConfigChangeNotice notice) { 17 | LOG.debug("收到通知....."); 18 | LOG.debug(notice.toJsonString()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 11 | 12 | 13 | 14 | 15 | ${LOG_HOME}/${PROJECT_NAME}.log 16 | 17 | 18 | ${LOG_HOME}/${PROJECT_NAME}.log.%d{yyyy-MM-dd}.%i.log 19 | 20 | 30 21 | 22 | 23 | 50MB 24 | 25 | 26 | 27 | 28 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 29 | UTF-8 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | --------------------------------------------------------------------------------