├── example ├── weixin4j-example-web │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yml │ │ │ ├── weixin4j.properties │ │ │ └── package.xml │ │ │ └── java │ │ │ └── com │ │ │ └── ansitech │ │ │ └── weixin4j │ │ │ └── example │ │ │ ├── Application.java │ │ │ ├── handler │ │ │ └── AtsNormalMessageHandler.java │ │ │ └── controller │ │ │ └── WeixinJieruController.java │ └── pom.xml ├── weixin4j-example │ ├── pom.xml │ └── src │ │ └── main │ │ └── resources │ │ └── weixin4j.properties └── weixin4j-0.0.9.2微信支付案例 │ └── pay_notify.jsp ├── src └── main │ └── java │ └── org │ └── weixin4j │ ├── misc │ ├── CEStreamExhausted.java │ ├── CEFormatException.java │ ├── BASE64Encoder.java │ └── BASE64Decoder.java │ ├── factory │ ├── WeixinFactory.java │ └── defaults │ │ └── DefaultWeixinFactory.java │ ├── model │ ├── message │ │ ├── event │ │ │ ├── SubscribeEventMessage.java │ │ │ ├── UnSubscribeEventMessage.java │ │ │ ├── ClickEventMessage.java │ │ │ ├── ViewEventMessage.java │ │ │ ├── QrsceneScanEventMessage.java │ │ │ ├── QrsceneSubscribeEventMessage.java │ │ │ ├── PicSysPhotoEventMessage.java │ │ │ ├── PicWeixinEventMessage.java │ │ │ ├── ScanCodePushEventMessage.java │ │ │ ├── PicPhotoOrAlbumEventMessage.java │ │ │ ├── ScanCodeWaitMsgEventMessage.java │ │ │ ├── LocationSelectEventMessage.java │ │ │ ├── LocationEventMessage.java │ │ │ └── EventMessage.java │ │ ├── PicList.java │ │ ├── Voice.java │ │ ├── Image.java │ │ ├── normal │ │ │ ├── TextInputMessage.java │ │ │ ├── ImageInputMessage.java │ │ │ ├── VideoInputMessage.java │ │ │ ├── ShortVideoInputMessage.java │ │ │ ├── LinkInputMessage.java │ │ │ ├── VoiceInputMessage.java │ │ │ ├── LocationInputMessage.java │ │ │ └── NormalMessage.java │ │ ├── ScanCodeInfo.java │ │ ├── SendPicsInfo.java │ │ ├── template │ │ │ ├── Miniprogram.java │ │ │ ├── TemplateData.java │ │ │ └── TemplateMessage.java │ │ ├── MsgType.java │ │ ├── MediaType.java │ │ ├── EventType.java │ │ ├── Video.java │ │ ├── Music.java │ │ ├── OutputMessage.java │ │ ├── SendLocationInfo.java │ │ ├── output │ │ │ ├── MusicOutputMessage.java │ │ │ ├── TextOutputMessage.java │ │ │ ├── VoiceOutputMessage.java │ │ │ ├── ImageOutputMessage.java │ │ │ └── VideoOutputMessage.java │ │ └── Articles.java │ ├── user │ │ ├── Data.java │ │ └── Followers.java │ ├── js │ │ ├── TicketType.java │ │ ├── WxConfig.java │ │ └── Ticket.java │ ├── menu │ │ ├── BaseButton.java │ │ ├── MediaIdButton.java │ │ ├── SingleButton.java │ │ ├── ViewLimitedButton.java │ │ ├── PicWeixinButton.java │ │ ├── PicSysPhotoButton.java │ │ ├── ScancodePushButton.java │ │ ├── LocationSelectButton.java │ │ ├── ClickButton.java │ │ ├── ScancodeWaitMsgButton.java │ │ ├── PicPhotoOrAlbumButton.java │ │ ├── ViewButton.java │ │ ├── ButtonType.java │ │ └── MiniprogramButton.java │ ├── tags │ │ └── Tag.java │ ├── qrcode │ │ ├── Qrcode.java │ │ └── QrcodeType.java │ ├── material │ │ └── Media.java │ ├── groups │ │ └── Group.java │ ├── pay │ │ └── WCPay.java │ ├── sns │ │ └── SnsUser.java │ └── media │ │ └── Article.java │ ├── WeixinException.java │ ├── loader │ ├── ITokenLoader.java │ ├── ITicketLoader.java │ ├── DefaultTicketLoader.java │ └── DefaultTokenLoader.java │ ├── component │ ├── AbstractComponent.java │ └── MaterialComponent.java │ ├── http │ └── MyX509TrustManager.java │ ├── spi │ ├── IMessageHandler.java │ ├── DefaultNormalMessageHandler.java │ └── INormalMessageHandler.java │ ├── util │ ├── MD5.java │ ├── XStreamFactory.java │ ├── SHA1.java │ ├── TokenUtil.java │ ├── PayUtil.java │ └── SignUtil.java │ ├── WeixinConfig.java │ └── WeixinPayConfig.java ├── .gitignore └── README.md /example/weixin4j-example-web/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/misc/CEStreamExhausted.java: -------------------------------------------------------------------------------- 1 | package org.weixin4j.misc; 2 | 3 | import java.io.IOException; 4 | 5 | public class CEStreamExhausted extends IOException { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/misc/CEFormatException.java: -------------------------------------------------------------------------------- 1 | package org.weixin4j.misc; 2 | 3 | import java.io.IOException; 4 | 5 | public class CEFormatException extends IOException { 6 | 7 | public CEFormatException(String s) { 8 | super(s); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.s[a-w][a-z] 2 | *.un~ 3 | Session.vim 4 | .netrwhist 5 | *~ 6 | 7 | ### Default ### 8 | *.log 9 | .mvn/ 10 | mvnw.cmd 11 | mvnw 12 | target/ 13 | data/ 14 | 15 | ### STS ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | 23 | ### IntelliJ IDEA ### 24 | .idea 25 | *.iws 26 | *.iml 27 | *.ipr 28 | 29 | ### NetBeans ### 30 | nbproject/ 31 | nbproject/private/ 32 | build/ 33 | nbbuild/ 34 | dist/ 35 | nbdist/ 36 | .nb-gradle/ 37 | nbactions.xml 38 | nb-configuration.xml -------------------------------------------------------------------------------- /example/weixin4j-example-web/src/main/java/com/ansitech/weixin4j/example/Application.java: -------------------------------------------------------------------------------- 1 | package com.ansitech.weixin4j.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | /** 8 | * 程序入口 9 | * 10 | * @author yangqisheng 11 | */ 12 | @SpringBootApplication 13 | @ComponentScan 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(Application.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example/weixin4j-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.ansitech 6 | weixin4j-example 7 | 1.0.0 8 | jar 9 | 10 | 11 | org.weixin4j 12 | weixin4j 13 | 0.1.5 14 | 15 | 16 | 17 | UTF-8 18 | 1.6 19 | 1.6 20 | 21 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/factory/WeixinFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.factory; 21 | 22 | import org.weixin4j.Weixin; 23 | 24 | /** 25 | * 创建一个微信操作工厂类 26 | * 27 | * @author yangqisheng 28 | * @since 1.0.0 29 | */ 30 | public interface WeixinFactory { 31 | 32 | Weixin getWeixin(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/SubscribeEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | 24 | /** 25 | * 关注事件 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class SubscribeEventMessage extends EventMessage { 31 | 32 | @Override 33 | public String getEvent() { 34 | return EventType.Subscribe.toString(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/UnSubscribeEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | 24 | /** 25 | * 取消关注事件 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class UnSubscribeEventMessage extends EventMessage { 31 | 32 | @Override 33 | public String getEvent() { 34 | return EventType.Unsubscribe.toString(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/user/Data.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.user; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * 微信平台关注者openid数据对象 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class Data { 31 | 32 | private List openid; //列表数据,OPENID的列表 33 | 34 | public List getOpenid() { 35 | return openid; 36 | } 37 | 38 | public void setOpenid(List openid) { 39 | this.openid = openid; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/WeixinException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j; 21 | 22 | /** 23 | * 24 | * 微信操作全局异常 25 | * 26 | * @author yangqisheng 27 | * @since 0.0.1 28 | */ 29 | public class WeixinException extends Exception { 30 | 31 | public WeixinException(String msg) { 32 | super(msg); 33 | } 34 | 35 | public WeixinException(Exception cause) { 36 | super(cause); 37 | } 38 | 39 | public WeixinException(String msg, Exception cause) { 40 | super(msg, cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/loader/ITokenLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.loader; 21 | 22 | import org.weixin4j.model.base.Token; 23 | 24 | /** 25 | * AccessToken加载接口 26 | * 27 | * @author yangqisheng 28 | * @since 0.1.0 29 | */ 30 | public interface ITokenLoader { 31 | 32 | /** 33 | * 获取access_token 34 | * 35 | * @return 包含access_token数据的对象 36 | */ 37 | public Token get(); 38 | 39 | /** 40 | * 刷新access_token 41 | * 42 | * @param accessToken 包含access_token数据的对象 43 | */ 44 | public void refresh(Token accessToken); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/component/AbstractComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.component; 21 | 22 | import org.weixin4j.Weixin; 23 | import org.weixin4j.WeixinSupport; 24 | 25 | /** 26 | * 微信组件基础类 27 | * 28 | * @author yangqisheng 29 | * @since 0.1.0 30 | */ 31 | public abstract class AbstractComponent extends WeixinSupport{ 32 | 33 | protected Weixin weixin; 34 | 35 | public AbstractComponent(Weixin weixin) { 36 | if (weixin == null) { 37 | throw new IllegalArgumentException("weixin can not be null"); 38 | } 39 | this.weixin = weixin; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/js/TicketType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.js; 21 | 22 | /** 23 | * 临时票据类型 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public enum TicketType { 29 | 30 | /** 31 | * 用于调用微信JSSDK的临时票据 32 | */ 33 | JSAPI("jsapi"), 34 | /** 35 | * 用于调用微信卡券相关接口的临时票据 36 | */ 37 | WX_CARD("wx_card"); 38 | 39 | private String value = ""; 40 | 41 | TicketType(String value) { 42 | this.value = value; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return value; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/factory/defaults/DefaultWeixinFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.factory.defaults; 21 | 22 | import org.weixin4j.Weixin; 23 | import org.weixin4j.factory.WeixinFactory; 24 | 25 | /** 26 | * DefaultWeixinFactory 27 | * 28 | * @author yangqisheng 29 | * @since 1.0.0 30 | */ 31 | public class DefaultWeixinFactory implements WeixinFactory { 32 | 33 | private Weixin weixin; 34 | 35 | public void setWeixin(Weixin weixin) { 36 | this.weixin = weixin; 37 | } 38 | 39 | @Override 40 | public Weixin getWeixin() { 41 | return weixin; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/BaseButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 自定义菜单按钮 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class BaseButton { 29 | 30 | /** 31 | * 菜单标题,不超过16个字节,子菜单不超过40个字节 32 | */ 33 | private final String name; 34 | 35 | /** 36 | * 基础按钮 37 | * 38 | * @param name 菜单标题 39 | */ 40 | public BaseButton(String name) { 41 | this.name = name; 42 | } 43 | 44 | /** 45 | * 获取 菜单标题 46 | * 47 | * @return 菜单标题 48 | */ 49 | public String getName() { 50 | return name; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/PicList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | import javax.xml.bind.annotation.XmlElement; 23 | import javax.xml.bind.annotation.XmlRootElement; 24 | 25 | /** 26 | * 图片 27 | * 28 | * @author yangqisheng 29 | * @since 0.0.1 30 | */ 31 | @XmlRootElement(name = "item") 32 | public class PicList { 33 | 34 | //图片的MD5值,开发者若需要,可用于验证接收到图片 35 | private String PicMd5Sum; 36 | 37 | public String getPicMd5Sum() { 38 | return PicMd5Sum; 39 | } 40 | 41 | @XmlElement(name = "PicMd5Sum") 42 | public void setPicMd5Sum(String PicMd5Sum) { 43 | this.PicMd5Sum = PicMd5Sum; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /example/weixin4j-example-web/src/main/resources/weixin4j.properties: -------------------------------------------------------------------------------- 1 | #微信SDK配置文件 2 | #读取规则:优先读取System.getProperty() 3 | #再从weixin4j.properties读取,key 4 | #如果System.getProperty()与weixin4j.properties都没设置,则默认未NULL 5 | 6 | #开发者调试设置 7 | weixin4j.debug=true 8 | #公众号Token 9 | weixin4j.token=weixin4j 10 | 11 | #公众号原始ID 12 | weixin4j.oauth.originalid= 13 | #开发者第三方用户唯一凭证 14 | weixin4j.oauth.appid= 15 | #开发者第三方用户唯一凭证密钥 16 | weixin4j.oauth.secret= 17 | #消息加密方式 0:明文模式(默认), 1:兼容模式, 2:安全模式(推荐) 18 | weixin4j.oauth.encodingtype=0 19 | #消息加密密钥(43位字符组成A-Za-z0-9) 20 | weixin4j.oauth.encodingaeskey=0123456789abcedfghijklmnopqrstuvwxyzZXCVBNM 21 | #网页授权URL 22 | weixin4j.oauth.url= 23 | 24 | #公众平台接口域名 25 | #通用域名(api.weixin.qq.com),使用该域名将访问官方指定就近的接入点; 26 | #上海域名(sh.api.weixin.qq.com),使用该域名将访问上海的接入点; 27 | #深圳域名(sz.api.weixin.qq.com),使用该域名将访问深圳的接入点; 28 | #香港域名(hk.api.weixin.qq.com),使用该域名将访问香港的接入点。 29 | weixin4j.api.domain=api.weixin.qq.com 30 | 31 | #微信支付_商户ID 32 | weixin4j.pay.partner.id= 33 | #微信支付_商户密钥 34 | weixin4j.pay.partner.key= 35 | #微信支付_通知URL 36 | weixin4j.pay.notify_url= 37 | 38 | #连接超时设置 39 | weixin4j.http.connectionTimeout=25000 40 | #请求超时设置 41 | weixin4j.http.readTimeout=25000 42 | #证书路径 43 | weixin4j.http.cert.path= 44 | weixin4j.http.cert.secret= 45 | 46 | #默认消息处理函数 47 | weixin4j.handler=org.weixin4j.spi.DefaultMessageHandler 48 | weixin4j.message.handler.normal=org.weixin4j.demo.jieru.AtsNormalMessageHandler 49 | weixin4j.message.handler.event=org.weixin4j.demo.jieru.AtsEventMessageHandler 50 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/loader/ITicketLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.loader; 21 | 22 | import org.weixin4j.model.js.Ticket; 23 | import org.weixin4j.model.js.TicketType; 24 | 25 | /** 26 | * JsApiTicket加载接口 27 | * 28 | * @author yangqisheng 29 | * @since 0.1.0 30 | */ 31 | public interface ITicketLoader { 32 | 33 | /** 34 | * 获取Ticket 35 | * 36 | * @param ticketType 临时凭证类型 37 | * @see org.weixin4j.model.js.TicketType 38 | * @return 有效的ticket,若返回""或null,则触发重新从微信请求Ticket的方法refresh 39 | */ 40 | Ticket get(TicketType ticketType); 41 | 42 | /** 43 | * 刷新Ticket 44 | * 45 | * @param ticket 包含ticket数据的对象 46 | */ 47 | void refresh(Ticket ticket); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/ClickEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | 24 | /** 25 | * 自定义菜单事件 26 | * 27 | * 点击菜单拉取消息时的事件推送 28 | * 29 | * @author yangqisheng 30 | * @since 0.0.1 31 | */ 32 | public class ClickEventMessage extends EventMessage { 33 | 34 | //事件KEY值,与自定义菜单接口中KEY值对应 35 | private String EventKey; 36 | 37 | @Override 38 | public String getEvent() { 39 | return EventType.Click.toString(); 40 | } 41 | 42 | public String getEventKey() { 43 | return EventKey; 44 | } 45 | 46 | public void setEventKey(String EventKey) { 47 | this.EventKey = EventKey; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/Voice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 回复语音消息中的语音对象 24 | * 25 | *

提供了获取语音IdgetMediaId()等主要方法.

26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class Voice implements java.io.Serializable { 31 | 32 | private String MediaId; //通过上传多媒体文件,得到的id 33 | 34 | /** 35 | * 获取 通过上传多媒体文件,得到的id 36 | * 37 | * @return 通过上传多媒体文件,得到的id 38 | */ 39 | public String getMediaId() { 40 | return MediaId; 41 | } 42 | 43 | /** 44 | * 设置 通过上传多媒体文件,得到的id 45 | * 46 | * @param mediaId 通过上传多媒体文件,得到的id 47 | */ 48 | public void setMediaId(String mediaId) { 49 | this.MediaId = mediaId; 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/Image.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 回复图片消息中的图片对象 24 | * 25 | *

26 | * 提供了获取图片IdgetMediaId()等主要方法.

27 | * 28 | * @author yangqisheng 29 | * @since 0.0.1 30 | */ 31 | public class Image implements java.io.Serializable { 32 | 33 | private String MediaId; //通过上传多媒体文件,得到的id 34 | 35 | /** 36 | * 获取 通过上传多媒体文件,得到的id 37 | * 38 | * @return 通过上传多媒体文件,得到的id 39 | */ 40 | public String getMediaId() { 41 | return MediaId; 42 | } 43 | 44 | /** 45 | * 设置 通过上传多媒体文件,得到的id 46 | * 47 | * @param mediaId 通过上传多媒体文件,得到的id 48 | */ 49 | public void setMediaId(String mediaId) { 50 | this.MediaId = mediaId; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/normal/TextInputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.normal; 21 | 22 | import org.weixin4j.model.message.MsgType; 23 | 24 | /** 25 | * 文本消息 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class TextInputMessage extends NormalMessage { 31 | 32 | //文本消息内容 33 | private String Content; 34 | 35 | public TextInputMessage(String Content) { 36 | this.Content = Content; 37 | } 38 | 39 | @Override 40 | public String getMsgType() { 41 | return MsgType.Text.toString(); 42 | } 43 | 44 | public String getContent() { 45 | return Content; 46 | } 47 | 48 | public void setContent(String Content) { 49 | this.Content = Content; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /example/weixin4j-example-web/src/main/resources/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | package 5 | 6 | 7 | zip 8 | 9 | true 10 | 11 | 12 | 13 | src/main/bin 14 | bin/ 15 | 16 | 17 | 18 | 19 | 20 | 21 | ${project.build.directory} 22 | / 23 | 24 | *.jar 25 | 26 | 27 | 28 | 29 | 30 | lib 31 | runtime 32 | 33 | ${groupId}:${artifactId} 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/http/MyX509TrustManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.http; 21 | 22 | import java.security.cert.CertificateException; 23 | import java.security.cert.X509Certificate; 24 | import javax.net.ssl.X509TrustManager; 25 | 26 | /** 27 | * Https证书管理类 28 | * 29 | * @author yangqisheng 30 | * @since 0.0.1 31 | */ 32 | public class MyX509TrustManager implements X509TrustManager { 33 | 34 | @Override 35 | public X509Certificate[] getAcceptedIssuers() { 36 | return null; 37 | } 38 | 39 | @Override 40 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 41 | } 42 | 43 | @Override 44 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/spi/IMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.spi; 21 | 22 | import javax.servlet.ServletInputStream; 23 | import org.weixin4j.WeixinException; 24 | 25 | /** 26 | * 输入消息处理器 27 | * 28 | * @author yangqisheng 29 | * @since 0.0.6 30 | */ 31 | public interface IMessageHandler { 32 | 33 | /** 34 | * 微信输入消息处理器 35 | * 36 | * @param inputStream 输入流 37 | * @return 返回xml格式的回复消息 38 | * @throws org.weixin4j.WeixinException 微信操作异常 39 | */ 40 | String invoke(ServletInputStream inputStream) throws WeixinException; 41 | 42 | /** 43 | * 微信输入消息处理器 44 | * 45 | * @param inputXml 输入xml 46 | * @return 返回xml格式的回复消息 47 | * @throws org.weixin4j.WeixinException 微信操作异常 48 | */ 49 | String invoke(String inputXml) throws WeixinException; 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/normal/ImageInputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.normal; 21 | 22 | import org.weixin4j.model.message.MsgType; 23 | 24 | /** 25 | * 图片消息 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class ImageInputMessage extends NormalMessage { 31 | 32 | //图片链接 33 | private String PicUrl; 34 | //图片消息媒体id,可以调用多媒体文件下载接口拉取数据。 35 | private String MediaId; 36 | 37 | @Override 38 | public String getMsgType() { 39 | return MsgType.Image.toString(); 40 | } 41 | 42 | public String getPicUrl() { 43 | return PicUrl; 44 | } 45 | 46 | public void setPicUrl(String PicUrl) { 47 | this.PicUrl = PicUrl; 48 | } 49 | 50 | public String getMediaId() { 51 | return MediaId; 52 | } 53 | 54 | public void setMediaId(String MediaId) { 55 | this.MediaId = MediaId; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/ViewEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | 24 | /** 25 | * 自定义菜单事件 26 | * 27 | * 点击菜单跳转链接时的事件推送 28 | * 29 | * @author yangqisheng 30 | * @since 0.0.1 31 | */ 32 | public class ViewEventMessage extends EventMessage { 33 | 34 | //事件KEY值,设置的跳转URL 35 | private String EventKey; 36 | private String MenuId; 37 | 38 | @Override 39 | public String getEvent() { 40 | return EventType.View.toString(); 41 | } 42 | 43 | public String getEventKey() { 44 | return EventKey; 45 | } 46 | 47 | public void setEventKey(String EventKey) { 48 | this.EventKey = EventKey; 49 | } 50 | 51 | public String getMenuId() { 52 | return MenuId; 53 | } 54 | 55 | public void setMenuId(String MenuId) { 56 | this.MenuId = MenuId; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/tags/Tag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.tags; 21 | 22 | /** 23 | * 用户标签管理 24 | * 25 | *

26 | * 通过Weixin产生一个请求对象,通过getUserTags()生成一个Tags,集合

27 | * 28 | * @author yangqisheng 29 | * @since 0.0.7 30 | */ 31 | public class Tag { 32 | 33 | private int id; //标签id,由微信分配 34 | private String name; //标签名,UTF8编码(30个字符以内) 35 | private int count; //此标签下粉丝数 36 | 37 | public int getId() { 38 | return id; 39 | } 40 | 41 | public void setId(int id) { 42 | this.id = id; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | public int getCount() { 54 | return count; 55 | } 56 | 57 | public void setCount(int count) { 58 | this.count = count; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/ScanCodeInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | import javax.xml.bind.annotation.XmlElement; 23 | import javax.xml.bind.annotation.XmlRootElement; 24 | 25 | /** 26 | * 扫描信息 27 | * 28 | * @author yangqisheng 29 | * @since 0.0.1 30 | */ 31 | @XmlRootElement(name = "ScanCodeInfo") 32 | public class ScanCodeInfo { 33 | 34 | //扫描类型,一般是qrcode 35 | private String ScanType; 36 | //扫描结果,即二维码对应的字符串信息 37 | private String ScanResult; 38 | 39 | public String getScanType() { 40 | return ScanType; 41 | } 42 | 43 | @XmlElement(name = "ScanType") 44 | public void setScanType(String ScanType) { 45 | this.ScanType = ScanType; 46 | } 47 | 48 | public String getScanResult() { 49 | return ScanResult; 50 | } 51 | 52 | @XmlElement(name = "ScanResult") 53 | public void setScanResult(String ScanResult) { 54 | this.ScanResult = ScanResult; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/normal/VideoInputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.normal; 21 | 22 | import org.weixin4j.model.message.MsgType; 23 | 24 | /** 25 | * 视频消息 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class VideoInputMessage extends NormalMessage { 31 | 32 | //视频消息媒体id,可以调用多媒体文件下载接口拉取数据。 33 | private String MediaId; 34 | //视频消息 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。 35 | private String ThumbMediaId; 36 | 37 | @Override 38 | public String getMsgType() { 39 | return MsgType.Video.toString(); 40 | } 41 | 42 | public String getMediaId() { 43 | return MediaId; 44 | } 45 | 46 | public void setMediaId(String MediaId) { 47 | this.MediaId = MediaId; 48 | } 49 | 50 | public String getThumbMediaId() { 51 | return ThumbMediaId; 52 | } 53 | 54 | public void setThumbMediaId(String ThumbMediaId) { 55 | this.ThumbMediaId = ThumbMediaId; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/QrsceneScanEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | 24 | /** 25 | * 扫描带参数二维码事件 26 | * 27 | * 用户已关注 28 | * 29 | * @author yangqisheng 30 | * @since 0.0.1 31 | */ 32 | public class QrsceneScanEventMessage extends EventMessage { 33 | 34 | //事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id 35 | private String EventKey; 36 | //二维码的ticket,可用来换取二维码图片 37 | private String Ticket; 38 | 39 | @Override 40 | public String getEvent() { 41 | return EventType.Scan.toString(); 42 | } 43 | 44 | public String getEventKey() { 45 | return EventKey; 46 | } 47 | 48 | public void setEventKey(String EventKey) { 49 | this.EventKey = EventKey; 50 | } 51 | 52 | public String getTicket() { 53 | return Ticket; 54 | } 55 | 56 | public void setTicket(String Ticket) { 57 | this.Ticket = Ticket; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/QrsceneSubscribeEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | 24 | /** 25 | * 扫描带参数二维码事件 26 | * 27 | * 用户未关注 28 | * 29 | * @author yangqisheng 30 | * @since 0.0.1 31 | */ 32 | public class QrsceneSubscribeEventMessage extends EventMessage { 33 | 34 | //事件KEY值,qrscene_为前缀,后面为二维码的参数值 35 | private String EventKey; 36 | //二维码的ticket,可用来换取二维码图片 37 | private String Ticket; 38 | 39 | @Override 40 | public String getEvent() { 41 | return EventType.Subscribe.toString(); 42 | } 43 | 44 | public String getEventKey() { 45 | return EventKey; 46 | } 47 | 48 | public void setEventKey(String EventKey) { 49 | this.EventKey = EventKey; 50 | } 51 | 52 | public String getTicket() { 53 | return Ticket; 54 | } 55 | 56 | public void setTicket(String Ticket) { 57 | this.Ticket = Ticket; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/normal/ShortVideoInputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.normal; 21 | 22 | import org.weixin4j.model.message.MsgType; 23 | 24 | /** 25 | * 小视频消息 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.7 29 | */ 30 | public class ShortVideoInputMessage extends NormalMessage { 31 | 32 | //视频消息媒体id,可以调用多媒体文件下载接口拉取数据。 33 | private String MediaId; 34 | //视频消息 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。 35 | private String ThumbMediaId; 36 | 37 | @Override 38 | public String getMsgType() { 39 | return MsgType.ShortVideo.toString(); 40 | } 41 | 42 | public String getMediaId() { 43 | return MediaId; 44 | } 45 | 46 | public void setMediaId(String MediaId) { 47 | this.MediaId = MediaId; 48 | } 49 | 50 | public String getThumbMediaId() { 51 | return ThumbMediaId; 52 | } 53 | 54 | public void setThumbMediaId(String ThumbMediaId) { 55 | this.ThumbMediaId = ThumbMediaId; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/MediaIdButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 永久素材(图片、音频、视频、图文消息) 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class MediaIdButton extends SingleButton { 29 | 30 | /** 31 | * 类型必须.网页链接,用户点击菜单可打开链接,不超过256字节 32 | */ 33 | private String mediaId; 34 | 35 | public MediaIdButton(String name, String mediaId) { 36 | super(name); 37 | this.mediaId = mediaId; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.Media_Id.toString(); 42 | } 43 | 44 | /** 45 | * 获取 调用新增永久素材接口返回的合法media_id 46 | * 47 | * @return 调用新增永久素材接口返回的合法media_id 48 | */ 49 | public String getMedia_Id() { 50 | return mediaId; 51 | } 52 | 53 | /** 54 | * 设置 调用新增永久素材接口返回的合法media_id 55 | * 56 | * @param mediaId 调用新增永久素材接口返回的合法media_id 57 | */ 58 | public void setMedia_Id(String mediaId) { 59 | this.mediaId = mediaId; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/util/MD5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.util; 21 | 22 | import java.security.MessageDigest; 23 | import java.security.NoSuchAlgorithmException; 24 | import org.weixin4j.misc.BASE64Encoder; 25 | 26 | /** 27 | * MD5加密算法 28 | * 29 | * @author yangqisheng 30 | * @since 0.0.1 31 | */ 32 | public class MD5 { 33 | 34 | /** 35 | * 将字符串加密 36 | * 37 | * @param str 要加密的字符串 38 | * @return 加密后的字符串 39 | */ 40 | public static String encryptByMd5(String str) { 41 | if (str == null) { 42 | return null; 43 | } 44 | try { 45 | MessageDigest md5 = MessageDigest.getInstance("MD5"); 46 | BASE64Encoder base64en = new BASE64Encoder(); 47 | byte[] b = str.getBytes(); 48 | byte[] digest = md5.digest(b); 49 | String newstr = base64en.encode(digest); 50 | return newstr; 51 | } catch (NoSuchAlgorithmException e) { 52 | throw new RuntimeException(e); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/loader/DefaultTicketLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.loader; 21 | 22 | import java.util.EnumMap; 23 | import java.util.Map; 24 | import org.apache.commons.lang.StringUtils; 25 | import org.weixin4j.model.js.Ticket; 26 | import org.weixin4j.model.js.TicketType; 27 | 28 | /** 29 | * 内存式Ticket存储器 30 | * 31 | * 单项目时使用(生产环境不推荐) 32 | * 33 | * @author yangqisheng 34 | * @since 0.1.0 35 | */ 36 | public class DefaultTicketLoader implements ITicketLoader { 37 | 38 | private final Map tickets = new EnumMap(TicketType.class); 39 | 40 | @Override 41 | public Ticket get(TicketType ticketType) { 42 | Ticket ticket = tickets.get(ticketType); 43 | return (ticket == null 44 | || StringUtils.isEmpty(ticket.getTicket()) 45 | || ticket.isExprexpired()) ? null : ticket; 46 | } 47 | 48 | @Override 49 | public void refresh(Ticket ticket) { 50 | tickets.put(ticket.getTicketType(), ticket); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/SingleButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * 带子菜单的按钮,此按钮中必须设置子菜单 27 | * 28 | * @author yangqisheng 29 | * @since 0.0.1 30 | */ 31 | public class SingleButton extends BaseButton { 32 | 33 | /** 34 | * 子菜单(此菜单需要手动添加,所以get和set方法能喝微信返回的json一致) 35 | */ 36 | private List subButton; 37 | 38 | public SingleButton(String name) { 39 | super(name); 40 | } 41 | 42 | /** 43 | * 设置 子菜单 44 | * 45 | * @param sub_button 子菜单 46 | */ 47 | public void setSubButton(List sub_button) { 48 | this.subButton = sub_button; 49 | } 50 | 51 | /** 52 | * 获取 子菜单 53 | * 54 | * @return 子菜单 55 | */ 56 | public List getSubButton() { 57 | if (subButton == null) { 58 | subButton = new ArrayList(0); 59 | } 60 | return this.subButton; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/ViewLimitedButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 永久素材(只能是图文消息) 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class ViewLimitedButton extends SingleButton { 29 | 30 | /** 31 | * 类型必须.网页链接,用户点击菜单可打开链接,不超过256字节 32 | */ 33 | private String mediaId; 34 | 35 | public ViewLimitedButton(String name, String mediaId) { 36 | super(name); 37 | this.mediaId = mediaId; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.View_Limited.toString(); 42 | } 43 | 44 | /** 45 | * 获取 调用新增永久素材接口返回的合法media_id 46 | * 47 | * @return 调用新增永久素材接口返回的合法media_id 48 | */ 49 | public String getMedia_Id() { 50 | return mediaId; 51 | } 52 | 53 | /** 54 | * 设置 调用新增永久素材接口返回的合法media_id 55 | * 56 | * @param mediaId 调用新增永久素材接口返回的合法media_id 57 | */ 58 | public void setMedia_Id(String mediaId) { 59 | this.mediaId = mediaId; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/util/XStreamFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.util; 21 | 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.io.UnsupportedEncodingException; 25 | 26 | /** 27 | * 将微信POST的流转换为XStream,然后转换为InputMessage对象 28 | * 29 | * @author yangqisheng 30 | * @since 0.0.1 31 | */ 32 | public class XStreamFactory { 33 | 34 | /** 35 | * 将输入流转读取成字符串 36 | * 37 | * @param in 输入流 38 | * @return 字符串 39 | * @throws UnsupportedEncodingException 字符转换异常 40 | * @throws IOException IO异常 41 | */ 42 | public static String inputStream2String(InputStream in) 43 | throws UnsupportedEncodingException, IOException { 44 | if (in == null) { 45 | return ""; 46 | } 47 | 48 | StringBuilder out = new StringBuilder(); 49 | byte[] b = new byte[4096]; 50 | for (int n; (n = in.read(b)) != -1;) { 51 | out.append(new String(b, 0, n, "UTF-8")); 52 | } 53 | return out.toString(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/SendPicsInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | import java.util.List; 23 | import javax.xml.bind.annotation.XmlElement; 24 | import javax.xml.bind.annotation.XmlElementWrapper; 25 | import javax.xml.bind.annotation.XmlRootElement; 26 | 27 | /** 28 | * 发送的图片信息 29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | @XmlRootElement(name = "SendPicsInfo") 34 | public class SendPicsInfo { 35 | 36 | //发送的图片数量 37 | private int Count; 38 | //图片列表 39 | private List PicList; 40 | 41 | public int getCount() { 42 | return Count; 43 | } 44 | 45 | @XmlElement(name = "Count") 46 | public void setCount(int Count) { 47 | this.Count = Count; 48 | } 49 | 50 | public List getPicList() { 51 | return PicList; 52 | } 53 | 54 | @XmlElementWrapper(name = "PicList") 55 | @XmlElement(name = "item") 56 | public void setPicList(List PicList) { 57 | this.PicList = PicList; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/PicWeixinButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 微信相册发图 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class PicWeixinButton extends SingleButton { 29 | 30 | /** 31 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节 32 | */ 33 | private String key; 34 | 35 | public PicWeixinButton(String name, String key) { 36 | super(name); 37 | this.key = key; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.Pic_Weixin.toString(); 42 | } 43 | 44 | /** 45 | * 获取 菜单KEY值 46 | * 47 | *

48 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

49 | * 50 | * @return 菜单KEY值 51 | */ 52 | public String getKey() { 53 | return key; 54 | } 55 | 56 | /** 57 | * 设置 菜单KEY值 58 | * 59 | *

60 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

61 | * 62 | * @param key 菜单KEY值 63 | */ 64 | public void setKey(String key) { 65 | this.key = key; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/PicSysPhotoButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 系统拍照发图 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class PicSysPhotoButton extends SingleButton { 29 | 30 | /** 31 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节 32 | */ 33 | private String key; 34 | 35 | public PicSysPhotoButton(String name, String key) { 36 | super(name); 37 | this.key = key; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.Pic_SysPhoto.toString(); 42 | } 43 | 44 | /** 45 | * 获取 菜单KEY值 46 | * 47 | *

48 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

49 | * 50 | * @return 菜单KEY值 51 | */ 52 | public String getKey() { 53 | return key; 54 | } 55 | 56 | /** 57 | * 设置 菜单KEY值 58 | * 59 | *

60 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

61 | * 62 | * @param key 菜单KEY值 63 | */ 64 | public void setKey(String key) { 65 | this.key = key; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/ScancodePushButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 扫码推事件 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class ScancodePushButton extends SingleButton { 29 | 30 | /** 31 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节 32 | */ 33 | private String key; 34 | 35 | public ScancodePushButton(String name, String key) { 36 | super(name); 37 | this.key = key; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.Scancode_Push.toString(); 42 | } 43 | 44 | /** 45 | * 获取 菜单KEY值 46 | * 47 | *

48 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

49 | * 50 | * @return 菜单KEY值 51 | */ 52 | public String getKey() { 53 | return key; 54 | } 55 | 56 | /** 57 | * 设置 菜单KEY值 58 | * 59 | *

60 | * click类型必须.菜单KEY值,用于消息接口推送,不超过128字节

61 | * 62 | * @param key 菜单KEY值 63 | */ 64 | public void setKey(String key) { 65 | this.key = key; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/LocationSelectButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 发送地理位置 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class LocationSelectButton extends SingleButton { 29 | 30 | /** 31 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节 32 | */ 33 | private String key; 34 | 35 | public LocationSelectButton(String name, String key) { 36 | super(name); 37 | this.key = key; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.Location_Select.toString(); 42 | } 43 | 44 | /** 45 | * 获取 菜单KEY值 46 | * 47 | *

48 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

49 | * 50 | * @return 菜单KEY值 51 | */ 52 | public String getKey() { 53 | return key; 54 | } 55 | 56 | /** 57 | * 设置 菜单KEY值 58 | * 59 | *

60 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

61 | * 62 | * @param key 菜单KEY值 63 | */ 64 | public void setKey(String key) { 65 | this.key = key; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/ClickButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 点击推事件 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class ClickButton extends SingleButton { 29 | 30 | /** 31 | * click类型必须.菜单KEY值,用于消息接口推送,不超过128字节 32 | */ 33 | private String key; 34 | 35 | public ClickButton(String name, String key) { 36 | super(name); 37 | this.key = key; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.Click.toString(); 42 | } 43 | 44 | /** 45 | * 获取 菜单KEY值 46 | * 47 | *

48 | * click类型必须.菜单KEY值, 用于消息接口推送,不超过128字节 49 | *

50 | * 51 | * @return 菜单KEY值 52 | */ 53 | public String getKey() { 54 | return key; 55 | } 56 | 57 | /** 58 | * 设置 菜单KEY值 59 | * 60 | *

61 | * click类型必须.菜单KEY值,用于消息接口推送,不超过128字节 62 | *

63 | * 64 | * @param key 菜单KEY值 65 | */ 66 | public void setKey(String key) { 67 | this.key = key; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/ScancodeWaitMsgButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 扫码带提示 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class ScancodeWaitMsgButton extends SingleButton { 29 | 30 | /** 31 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节 32 | */ 33 | private String key; 34 | 35 | public ScancodeWaitMsgButton(String name, String key) { 36 | super(name); 37 | this.key = key; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.Scancode_Waitmsg.toString(); 42 | } 43 | 44 | /** 45 | * 获取 菜单KEY值 46 | * 47 | *

48 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

49 | * 50 | * @return 菜单KEY值 51 | */ 52 | public String getKey() { 53 | return key; 54 | } 55 | 56 | /** 57 | * 设置 菜单KEY值 58 | * 59 | *

60 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

61 | * 62 | * @param key 菜单KEY值 63 | */ 64 | public void setKey(String key) { 65 | this.key = key; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/qrcode/Qrcode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.qrcode; 21 | 22 | /** 23 | * 二维码ticket 24 | * 25 | * @author yangqisheng 26 | * @since 0.1.0 27 | */ 28 | public class Qrcode { 29 | 30 | /** 31 | * 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。 32 | */ 33 | private String ticket; 34 | /** 35 | * 二维码的有效时间,以秒为单位。最大不超过1800。 36 | */ 37 | private int expire_seconds; 38 | /** 39 | * 二维码图片解析后的地址,开发者可根据该地址自行生成需要的二维码图片 40 | */ 41 | private String url; 42 | 43 | public String getTicket() { 44 | return ticket; 45 | } 46 | 47 | public void setTicket(String ticket) { 48 | this.ticket = ticket; 49 | } 50 | 51 | public int getExpire_seconds() { 52 | return expire_seconds; 53 | } 54 | 55 | public void setExpire_seconds(int expire_seconds) { 56 | this.expire_seconds = expire_seconds; 57 | } 58 | 59 | public String getUrl() { 60 | return url; 61 | } 62 | 63 | public void setUrl(String url) { 64 | this.url = url; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/PicPhotoOrAlbumButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 拍照或者相册发图 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class PicPhotoOrAlbumButton extends SingleButton { 29 | 30 | /** 31 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节 32 | */ 33 | private String key; 34 | 35 | public PicPhotoOrAlbumButton(String name, String key) { 36 | super(name); 37 | this.key = key; 38 | } 39 | 40 | public String getType() { 41 | return ButtonType.Pic_Photo_OR_Album.toString(); 42 | } 43 | 44 | /** 45 | * 获取 菜单KEY值 46 | * 47 | *

48 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

49 | * 50 | * @return 菜单KEY值 51 | */ 52 | public String getKey() { 53 | return key; 54 | } 55 | 56 | /** 57 | * 设置 菜单KEY值 58 | * 59 | *

60 | * 类型必须.菜单KEY值,用于消息接口推送,不超过128字节

61 | * 62 | * @param key 菜单KEY值 63 | */ 64 | public void setKey(String key) { 65 | this.key = key; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/PicSysPhotoEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | import org.weixin4j.model.message.SendPicsInfo; 24 | 25 | /** 26 | * 自定义菜单事件 27 | * 28 | * 扫码推事件的事件推送 29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | public class PicSysPhotoEventMessage extends EventMessage { 34 | 35 | //事件KEY值,与自定义菜单接口中KEY值对应 36 | private String EventKey; 37 | //发送的图片信息 38 | private SendPicsInfo SendPicsInfo; 39 | 40 | @Override 41 | public String getEvent() { 42 | return EventType.Pic_Sysphoto.toString(); 43 | } 44 | 45 | public String getEventKey() { 46 | return EventKey; 47 | } 48 | 49 | public void setEventKey(String EventKey) { 50 | this.EventKey = EventKey; 51 | } 52 | 53 | public SendPicsInfo getSendPicsInfo() { 54 | return SendPicsInfo; 55 | } 56 | 57 | public void setSendPicsInfo(SendPicsInfo SendPicsInfo) { 58 | this.SendPicsInfo = SendPicsInfo; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/PicWeixinEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | import org.weixin4j.model.message.SendPicsInfo; 24 | 25 | /** 26 | * 自定义菜单事件 27 | * 28 | * 弹出微信相册发图器的事件推送 29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | public class PicWeixinEventMessage extends EventMessage { 34 | 35 | //事件KEY值,与自定义菜单接口中KEY值对应 36 | private String EventKey; 37 | //发送的图片信息 38 | private SendPicsInfo SendPicsInfo; 39 | 40 | @Override 41 | public String getEvent() { 42 | return EventType.Pic_Weixin.toString(); 43 | } 44 | 45 | public String getEventKey() { 46 | return EventKey; 47 | } 48 | 49 | public void setEventKey(String EventKey) { 50 | this.EventKey = EventKey; 51 | } 52 | 53 | public SendPicsInfo getSendPicsInfo() { 54 | return SendPicsInfo; 55 | } 56 | 57 | public void setSendPicsInfo(SendPicsInfo SendPicsInfo) { 58 | this.SendPicsInfo = SendPicsInfo; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/ScanCodePushEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | import org.weixin4j.model.message.ScanCodeInfo; 24 | 25 | /** 26 | * 自定义菜单事件 27 | * 28 | * 扫码推事件的事件推送 29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | public class ScanCodePushEventMessage extends EventMessage { 34 | 35 | //事件KEY值,与自定义菜单接口中KEY值对应 36 | private String EventKey; 37 | //扫描信息 38 | private ScanCodeInfo ScanCodeInfo; 39 | 40 | @Override 41 | public String getEvent() { 42 | return EventType.Scancode_Push.toString(); 43 | } 44 | 45 | public String getEventKey() { 46 | return EventKey; 47 | } 48 | 49 | public void setEventKey(String EventKey) { 50 | this.EventKey = EventKey; 51 | } 52 | 53 | public ScanCodeInfo getScanCodeInfo() { 54 | return ScanCodeInfo; 55 | } 56 | 57 | public void setScanCodeInfo(ScanCodeInfo ScanCodeInfo) { 58 | this.ScanCodeInfo = ScanCodeInfo; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/template/Miniprogram.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.template; 21 | 22 | /** 23 | * 实体类对象,用来设置TemplateMessage中的跳小程序所需数据 24 | * 25 | * @author yangqisheng 26 | * @since 0.1.0 27 | */ 28 | public class Miniprogram implements java.io.Serializable { 29 | 30 | /** 31 | * 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系) 32 | */ 33 | private String appid; 34 | /** 35 | * 所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar) 36 | */ 37 | private String pagepath; 38 | 39 | public Miniprogram() { 40 | } 41 | 42 | public Miniprogram(String appid, String pagepath) { 43 | this.appid = appid; 44 | this.pagepath = pagepath; 45 | } 46 | 47 | public String getAppid() { 48 | return appid; 49 | } 50 | 51 | public void setAppid(String appid) { 52 | this.appid = appid; 53 | } 54 | 55 | public String getPagepath() { 56 | return pagepath; 57 | } 58 | 59 | public void setPagepath(String pagepath) { 60 | this.pagepath = pagepath; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/PicPhotoOrAlbumEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | import org.weixin4j.model.message.SendPicsInfo; 24 | 25 | /** 26 | * 自定义菜单事件 27 | * 28 | * 弹出拍照或者相册发图的事件推送 29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | public class PicPhotoOrAlbumEventMessage extends EventMessage { 34 | 35 | //事件KEY值,与自定义菜单接口中KEY值对应 36 | private String EventKey; 37 | //发送的图片信息 38 | private SendPicsInfo SendPicsInfo; 39 | 40 | @Override 41 | public String getEvent() { 42 | return EventType.Pic_Photo_OR_Album.toString(); 43 | } 44 | 45 | public String getEventKey() { 46 | return EventKey; 47 | } 48 | 49 | public void setEventKey(String EventKey) { 50 | this.EventKey = EventKey; 51 | } 52 | 53 | public SendPicsInfo getSendPicsInfo() { 54 | return SendPicsInfo; 55 | } 56 | 57 | public void setSendPicsInfo(SendPicsInfo SendPicsInfo) { 58 | this.SendPicsInfo = SendPicsInfo; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/ScanCodeWaitMsgEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | import org.weixin4j.model.message.ScanCodeInfo; 24 | 25 | /** 26 | * 自定义菜单事件 27 | * 28 | * 扫码推事件且弹出“消息接收中”提示框的事件推送 29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | public class ScanCodeWaitMsgEventMessage extends EventMessage { 34 | 35 | //事件KEY值,与自定义菜单接口中KEY值对应 36 | private String EventKey; 37 | //扫描信息 38 | private ScanCodeInfo ScanCodeInfo; 39 | 40 | @Override 41 | public String getEvent() { 42 | return EventType.Scancode_Waitmsg.toString(); 43 | } 44 | 45 | public String getEventKey() { 46 | return EventKey; 47 | } 48 | 49 | public void setEventKey(String EventKey) { 50 | this.EventKey = EventKey; 51 | } 52 | 53 | public ScanCodeInfo getScanCodeInfo() { 54 | return ScanCodeInfo; 55 | } 56 | 57 | public void setScanCodeInfo(ScanCodeInfo ScanCodeInfo) { 58 | this.ScanCodeInfo = ScanCodeInfo; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/normal/LinkInputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.normal; 21 | 22 | import org.weixin4j.model.message.MsgType; 23 | 24 | /** 25 | * 链接消息 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class LinkInputMessage extends NormalMessage { 31 | 32 | //消息标题 33 | private String Title; 34 | //消息描述 35 | private String Description; 36 | //消息链接 37 | private String Url; 38 | 39 | @Override 40 | public String getMsgType() { 41 | return MsgType.Link.toString(); 42 | } 43 | 44 | public String getTitle() { 45 | return Title; 46 | } 47 | 48 | public void setTitle(String Title) { 49 | this.Title = Title; 50 | } 51 | 52 | public String getDescription() { 53 | return Description; 54 | } 55 | 56 | public void setDescription(String Description) { 57 | this.Description = Description; 58 | } 59 | 60 | public String getUrl() { 61 | return Url; 62 | } 63 | 64 | public void setUrl(String Url) { 65 | this.Url = Url; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/ViewButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 跳转URL 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class ViewButton extends SingleButton { 29 | 30 | /** 31 | * view类型必须.网页链接,用户点击菜单可打开链接,不超过256字节 32 | */ 33 | private String url; 34 | 35 | public ViewButton(String name) { 36 | super(name); 37 | } 38 | 39 | public ViewButton(String name, String url) { 40 | super(name); 41 | this.url = url; 42 | } 43 | 44 | public String getType() { 45 | return ButtonType.View.toString(); 46 | } 47 | 48 | /** 49 | * 获取 网页链接 50 | * 51 | *

52 | * view类型必须.网页链接,用户点击菜单可打开链接,不超过256字节 53 | *

54 | * 55 | * @return 网页链接 56 | */ 57 | public String getUrl() { 58 | return url; 59 | } 60 | 61 | /** 62 | * 设置 网页链接 63 | * 64 | *

65 | * view类型必须.网页链接,用户点击菜单可打开链接,不超过256字节 66 | *

67 | * 68 | * @param url 网页链接 69 | */ 70 | public void setUrl(String url) { 71 | this.url = url; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/LocationSelectEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | import org.weixin4j.model.message.SendLocationInfo; 24 | 25 | /** 26 | * 自定义菜单事件 27 | * 28 | * 弹出地理位置选择器的事件推送 29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | public class LocationSelectEventMessage extends EventMessage { 34 | 35 | //事件KEY值,与自定义菜单接口中KEY值对应 36 | private String EventKey; 37 | //发送的位置信息 38 | private SendLocationInfo SendLocationInfo; 39 | 40 | @Override 41 | public String getEvent() { 42 | return EventType.Location_Select.toString(); 43 | } 44 | 45 | public String getEventKey() { 46 | return EventKey; 47 | } 48 | 49 | public void setEventKey(String EventKey) { 50 | this.EventKey = EventKey; 51 | } 52 | 53 | public SendLocationInfo getSendLocationInfo() { 54 | return SendLocationInfo; 55 | } 56 | 57 | public void setSendLocationInfo(SendLocationInfo SendLocationInfo) { 58 | this.SendLocationInfo = SendLocationInfo; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/MsgType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 消息类型 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public enum MsgType { 29 | 30 | /** 31 | * 1 文本消息 32 | */ 33 | Text("text"), 34 | /** 35 | * 2 图片消息 36 | */ 37 | Image("image"), 38 | /** 39 | * 3 语音消息 40 | */ 41 | Voice("voice"), 42 | /** 43 | * 4 视频消息 44 | */ 45 | Video("video"), 46 | /** 47 | * 5 小视频消息 48 | */ 49 | ShortVideo("shortvideo"), 50 | /** 51 | * 6 地理位置消息 52 | */ 53 | Location("location"), 54 | /** 55 | * 7 链接消息 56 | */ 57 | Link("link"), 58 | /** 59 | * 事件消息 60 | */ 61 | Event("event"), 62 | /** 63 | * 音乐消息 64 | */ 65 | Music("music"), 66 | /** 67 | * 图文消息 68 | */ 69 | News("news"); 70 | private String value = ""; 71 | 72 | MsgType(String value) { 73 | this.value = value; 74 | } 75 | 76 | /** 77 | * @return the msgType 78 | */ 79 | @Override 80 | public String toString() { 81 | return value; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/LocationEventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | import org.weixin4j.model.message.EventType; 23 | 24 | /** 25 | * 上报地理位置事件 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class LocationEventMessage extends EventMessage { 31 | 32 | //地理位置纬度 33 | private String Latitude; 34 | //地理位置经度 35 | private String Longitude; 36 | //地理位置精度 37 | private String Precision; 38 | 39 | @Override 40 | public String getEvent() { 41 | return EventType.Location.toString(); 42 | } 43 | 44 | public String getLatitude() { 45 | return Latitude; 46 | } 47 | 48 | public void setLatitude(String Latitude) { 49 | this.Latitude = Latitude; 50 | } 51 | 52 | public String getLongitude() { 53 | return Longitude; 54 | } 55 | 56 | public void setLongitude(String Longitude) { 57 | this.Longitude = Longitude; 58 | } 59 | 60 | public String getPrecision() { 61 | return Precision; 62 | } 63 | 64 | public void setPrecision(String Precision) { 65 | this.Precision = Precision; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/material/Media.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.material; 21 | 22 | import java.util.Date; 23 | import org.weixin4j.model.message.MediaType; 24 | 25 | /** 26 | * 上传成功后的素材对象 27 | * 28 | * @author yangqisheng 29 | * @since 0.1.4 30 | */ 31 | public class Media { 32 | 33 | /** 34 | * 媒体文件类型 35 | * 36 | * 分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb,主要用于视频与音乐格式的缩略图) 37 | */ 38 | private MediaType mediaType; 39 | /** 40 | * 媒体文件上传后,获取标识 41 | */ 42 | private String mediaId; 43 | /** 44 | * 媒体文件上传时间 45 | */ 46 | private Date createdAt; 47 | 48 | public MediaType getMediaType() { 49 | return mediaType; 50 | } 51 | 52 | public void setMediaType(MediaType mediaType) { 53 | this.mediaType = mediaType; 54 | } 55 | 56 | public String getMediaId() { 57 | return mediaId; 58 | } 59 | 60 | public void setMediaId(String mediaId) { 61 | this.mediaId = mediaId; 62 | } 63 | 64 | public Date getCreatedAt() { 65 | return createdAt; 66 | } 67 | 68 | public void setCreatedAt(Date createdAt) { 69 | this.createdAt = createdAt; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/normal/VoiceInputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.normal; 21 | 22 | import org.weixin4j.model.message.MsgType; 23 | 24 | /** 25 | * 语音消息 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class VoiceInputMessage extends NormalMessage { 31 | 32 | //语音消息媒体id,可以调用多媒体文件下载接口拉取数据。 33 | private String MediaId; 34 | //语音格式,如amr,speex等 35 | private String Format; 36 | //语音识别结果,使用UTF8编码 37 | private String Recognition; 38 | 39 | @Override 40 | public String getMsgType() { 41 | return MsgType.Voice.toString(); 42 | } 43 | 44 | public String getMediaId() { 45 | return MediaId; 46 | } 47 | 48 | public void setMediaId(String MediaId) { 49 | this.MediaId = MediaId; 50 | } 51 | 52 | public String getFormat() { 53 | return Format; 54 | } 55 | 56 | public void setFormat(String Format) { 57 | this.Format = Format; 58 | } 59 | 60 | public String getRecognition() { 61 | return Recognition; 62 | } 63 | 64 | public void setRecognition(String Recognition) { 65 | this.Recognition = Recognition; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/loader/DefaultTokenLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.loader; 21 | 22 | import org.weixin4j.model.base.Token; 23 | import org.apache.commons.lang.StringUtils; 24 | 25 | /** 26 | * 内存式AccessToken存储器 27 | * 28 | * 单项目时使用(生产环境不推荐) 29 | * 30 | * @author yangqisheng 31 | * @since 0.1.0 32 | */ 33 | public class DefaultTokenLoader implements ITokenLoader { 34 | 35 | /** 36 | * AccessToken对象 37 | */ 38 | private Token token = null; 39 | 40 | @Override 41 | public Token get() { 42 | return (token == null 43 | || StringUtils.isEmpty(token.getAccess_token()) 44 | || token.isExprexpired()) ? null : token; 45 | } 46 | 47 | @Override 48 | public void refresh(Token token) { 49 | if (null == token || StringUtils.isEmpty(token.getAccess_token())) { 50 | throw new IllegalStateException("access_token is null or empty"); 51 | } 52 | if (token.getCreate_time() <= 0) { 53 | throw new IllegalStateException("createtime can not be zero"); 54 | } 55 | if (token.isExprexpired()) { 56 | throw new IllegalStateException("access_token is exprexpired"); 57 | } 58 | this.token = token; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/event/EventMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.event; 21 | 22 | /** 23 | * 事件消息 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public abstract class EventMessage { 29 | 30 | //开发者微信号 31 | private String ToUserName; 32 | //发送方帐号(一个OpenID) 33 | private String FromUserName; 34 | //消息创建时间 (整型) 35 | private Long CreateTime; 36 | //消息类型,event 37 | private final String MsgType = "event"; 38 | 39 | /** 40 | * 获取 事件类型 41 | * 42 | * @return 事件类型 43 | */ 44 | public abstract String getEvent(); 45 | 46 | public String getToUserName() { 47 | return ToUserName; 48 | } 49 | 50 | public void setToUserName(String ToUserName) { 51 | this.ToUserName = ToUserName; 52 | } 53 | 54 | public String getFromUserName() { 55 | return FromUserName; 56 | } 57 | 58 | public void setFromUserName(String FromUserName) { 59 | this.FromUserName = FromUserName; 60 | } 61 | 62 | public Long getCreateTime() { 63 | return CreateTime; 64 | } 65 | 66 | public void setCreateTime(Long CreateTime) { 67 | this.CreateTime = CreateTime; 68 | } 69 | 70 | public String getMsgType() { 71 | return MsgType; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/MediaType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 24 | * 素材类型 25 | * 26 | * @author yangqisheng 27 | * @since 0.0.1 28 | */ 29 | public enum MediaType { 30 | 31 | /** 32 | * 图片 33 | */ 34 | Image("image"), 35 | /** 36 | * 语音 37 | */ 38 | Voice("voice"), 39 | /** 40 | * 视频 41 | */ 42 | Video("video"), 43 | /** 44 | * 缩略图 45 | */ 46 | Thumb("thumb"); 47 | 48 | private String value = ""; 49 | 50 | MediaType(String value) { 51 | this.value = value; 52 | } 53 | 54 | // /** 55 | // * 根据媒体类型字符串,返回媒体类型枚举对象 56 | // * 57 | // * @param mediaType 媒体类型字符串 58 | // * @return 媒体类型枚举对象 59 | // */ 60 | // public MediaType valueOf(String mediaType) { 61 | // if (mediaType.equals(Voice.toString())) { 62 | // return Voice; 63 | // } 64 | // if (mediaType.equals(Image.toString())) { 65 | // return Image; 66 | // } 67 | // if (mediaType.equals(Video.toString())) { 68 | // return Image; 69 | // } 70 | // if (mediaType.equals(Thumb.toString())) { 71 | // return Image; 72 | // } 73 | // return null; 74 | // } 75 | 76 | @Override 77 | public String toString() { 78 | return value; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/normal/LocationInputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.normal; 21 | 22 | import org.weixin4j.model.message.MsgType; 23 | 24 | /** 25 | * 地理位置消息 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class LocationInputMessage extends NormalMessage { 31 | 32 | //地理位置维度 33 | private String Location_X; 34 | //地理位置经度 35 | private String Location_Y; 36 | //地图缩放大小 37 | private Long Scale; 38 | //地理位置信息 39 | private String Label; 40 | 41 | @Override 42 | public String getMsgType() { 43 | return MsgType.Location.toString(); 44 | } 45 | 46 | public String getLocation_X() { 47 | return Location_X; 48 | } 49 | 50 | public void setLocation_X(String Location_X) { 51 | this.Location_X = Location_X; 52 | } 53 | 54 | public String getLocation_Y() { 55 | return Location_Y; 56 | } 57 | 58 | public void setLocation_Y(String Location_Y) { 59 | this.Location_Y = Location_Y; 60 | } 61 | 62 | public Long getScale() { 63 | return Scale; 64 | } 65 | 66 | public void setScale(Long Scale) { 67 | this.Scale = Scale; 68 | } 69 | 70 | public String getLabel() { 71 | return Label; 72 | } 73 | 74 | public void setLabel(String Label) { 75 | this.Label = Label; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/template/TemplateData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.template; 21 | 22 | /** 23 | * 实体类对象,用来设置TemplateMessage中的模板数据 24 | * 25 | * @author yangqisheng 26 | * @since 0.1.0 27 | */ 28 | public class TemplateData implements java.io.Serializable { 29 | 30 | /** 31 | * 字段Key 32 | */ 33 | private String key; 34 | 35 | /** 36 | * 值 37 | */ 38 | private String value; 39 | 40 | /** 41 | * 颜色 42 | */ 43 | private String color; 44 | 45 | public TemplateData() { 46 | } 47 | 48 | public TemplateData(String key, String value) { 49 | this.key = key; 50 | this.value = value; 51 | } 52 | 53 | public TemplateData(String key, String value, String color) { 54 | this.key = key; 55 | this.value = value; 56 | this.color = color; 57 | } 58 | 59 | public String getKey() { 60 | return key; 61 | } 62 | 63 | public void setKey(String key) { 64 | this.key = key; 65 | } 66 | 67 | public String getValue() { 68 | return value; 69 | } 70 | 71 | public void setValue(String value) { 72 | this.value = value; 73 | } 74 | 75 | public String getColor() { 76 | return color; 77 | } 78 | 79 | public void setColor(String color) { 80 | this.color = color; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/groups/Group.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.groups; 21 | 22 | /** 23 | * 微信平台分组对象 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.4 27 | */ 28 | public class Group implements java.io.Serializable { 29 | 30 | private int id; //分组id,由微信分配 31 | private String name; //分组名字,UTF8编码(30个字符以内) 32 | private int count; //分组内用户数量 33 | 34 | /** 35 | * 获取 分组id 36 | * 37 | * @return 分组id 38 | */ 39 | public int getId() { 40 | return id; 41 | } 42 | 43 | /** 44 | * 设置 分组id 45 | * 46 | * @param id 分组id 47 | */ 48 | public void setId(int id) { 49 | this.id = id; 50 | } 51 | 52 | /** 53 | * 获取 分组名字 54 | * 55 | * @return 分组名字 56 | */ 57 | public String getName() { 58 | return name; 59 | } 60 | 61 | /** 62 | * 设置 分组名字 63 | * 64 | *

30个字符以内

65 | * 66 | * @param name 分组名字 67 | */ 68 | public void setName(String name) { 69 | this.name = name; 70 | } 71 | 72 | /** 73 | * 获取 用户数量 74 | * 75 | * @return 用户数量 76 | */ 77 | public int getCount() { 78 | return count; 79 | } 80 | 81 | /** 82 | * 设置 用户数量 83 | * 84 | * @param count 用户数量 85 | */ 86 | public void setCount(int count) { 87 | this.count = count; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/ButtonType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 自定义菜单类型 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public enum ButtonType { 29 | 30 | /** 31 | * 点击推事件 32 | */ 33 | Click("click"), 34 | /** 35 | * 跳转URL 36 | */ 37 | View("view"), 38 | /** 39 | * 扫码推事件 40 | */ 41 | Scancode_Push("scancode_push"), 42 | /** 43 | * 扫码推事件且弹出“消息接收中”提示框 44 | */ 45 | Scancode_Waitmsg("scancode_waitmsg"), 46 | /** 47 | * 弹出系统拍照发图 48 | */ 49 | Pic_SysPhoto("pic_sysphoto"), 50 | /** 51 | * 弹出拍照或者相册发图 52 | */ 53 | Pic_Photo_OR_Album("pic_photo_or_album"), 54 | /** 55 | * 弹出微信相册发图器 56 | */ 57 | Pic_Weixin("pic_weixin"), 58 | /** 59 | * 弹出地理位置选择器 60 | */ 61 | Location_Select("location_select"), 62 | /** 63 | * 下发消息(除文本消息) 64 | */ 65 | Media_Id("media_id"), 66 | /** 67 | * 跳转图文消息URL 68 | */ 69 | View_Limited("view_limited"), 70 | /** 71 | * 小程序菜单 72 | */ 73 | Miniprogram("miniprogram"); 74 | 75 | private String value = ""; 76 | 77 | ButtonType(String value) { 78 | this.value = value; 79 | } 80 | 81 | /** 82 | * @return the msgType 83 | */ 84 | @Override 85 | public String toString() { 86 | return value; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/qrcode/QrcodeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.qrcode; 21 | 22 | /** 23 | * 二维码类型 24 | * 25 | * @author yangqisheng 26 | * @since 0.1.0 27 | */ 28 | public enum QrcodeType { 29 | 30 | /** 31 | * 临时的整型参数值 32 | */ 33 | QR_SCENE("QR_SCENE"), 34 | /** 35 | * 临时的字符串参数值 36 | */ 37 | QR_STR_SCENE("QR_STR_SCENE"), 38 | /** 39 | * 永久的整型参数值 40 | */ 41 | QR_LIMIT_SCENE("QR_LIMIT_SCENE"), 42 | /** 43 | * 永久的字符串参数值 44 | */ 45 | QR_LIMIT_STR_SCENE("QR_LIMIT_STR_SCENE"); 46 | 47 | private String value = ""; 48 | 49 | QrcodeType(String value) { 50 | this.value = value; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return value; 56 | } 57 | 58 | public static QrcodeType parse(String value) { 59 | if (value == null) { 60 | return null; 61 | } 62 | if (value.toUpperCase().equals(QR_SCENE.toString())) { 63 | return QR_SCENE; 64 | } 65 | if (value.toUpperCase().equals(QR_STR_SCENE.toString())) { 66 | return QR_STR_SCENE; 67 | } 68 | if (value.toUpperCase().equals(QR_LIMIT_SCENE.toString())) { 69 | return QR_LIMIT_SCENE; 70 | } 71 | if (value.toUpperCase().equals(QR_LIMIT_STR_SCENE.toString())) { 72 | return QR_LIMIT_STR_SCENE; 73 | } 74 | return null; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/EventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 事件类型 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public enum EventType { 29 | 30 | /** 31 | * 订阅 32 | */ 33 | Subscribe("subscribe"), 34 | /** 35 | * 取消订阅 36 | */ 37 | Unsubscribe("unsubscribe"), 38 | /** 39 | * 已关注用户扫描带参数二维码 40 | */ 41 | Scan("scan"), 42 | /** 43 | * 上报地理位置 44 | */ 45 | Location("location"), 46 | /** 47 | * 点击自定义菜单 48 | */ 49 | Click("click"), 50 | /** 51 | * 查看菜单 52 | */ 53 | View("view"), 54 | /** 55 | * 扫码推事件 56 | */ 57 | Scancode_Push("scancode_push"), 58 | /** 59 | * 扫码推事件 60 | */ 61 | Scancode_Waitmsg("scancode_waitmsg"), 62 | /** 63 | * 弹出系统拍照发图的事件 64 | */ 65 | Pic_Sysphoto("pic_sysphoto"), 66 | /** 67 | * 弹出拍照或者相册发图的事件 68 | */ 69 | Pic_Photo_OR_Album("pic_photo_or_album"), 70 | /** 71 | * 弹出微信相册发图器的事件 72 | */ 73 | Pic_Weixin("pic_weixin"), 74 | /** 75 | * 弹出地理位置选择器的事件 76 | */ 77 | Location_Select("location_select"); 78 | 79 | private String value = ""; 80 | 81 | EventType(String value) { 82 | this.value = value; 83 | } 84 | 85 | /** 86 | * @return the msgType 87 | */ 88 | @Override 89 | public String toString() { 90 | return value; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/misc/BASE64Encoder.java: -------------------------------------------------------------------------------- 1 | package org.weixin4j.misc; 2 | 3 | import java.io.OutputStream; 4 | import java.io.IOException; 5 | 6 | public class BASE64Encoder extends CharacterEncoder { 7 | 8 | @Override 9 | protected int bytesPerAtom() { 10 | return (3); 11 | } 12 | 13 | @Override 14 | protected int bytesPerLine() { 15 | return (57); 16 | } 17 | 18 | private final static char pem_array[] = { 19 | // 0 1 2 3 4 5 6 7 20 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 21 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 22 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 23 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 24 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 25 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 26 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 27 | '4', '5', '6', '7', '8', '9', '+', '/' 28 | }; 29 | 30 | @Override 31 | protected void encodeAtom(OutputStream outStream, byte data[], int offset, 32 | int len) throws IOException { 33 | byte a, b, c; 34 | if (len == 1) { 35 | a = data[offset]; 36 | b = 0; 37 | c = 0; 38 | outStream.write(pem_array[(a >>> 2) & 0x3F]); 39 | outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]); 40 | outStream.write('='); 41 | outStream.write('='); 42 | } else if (len == 2) { 43 | a = data[offset]; 44 | b = data[offset + 1]; 45 | c = 0; 46 | outStream.write(pem_array[(a >>> 2) & 0x3F]); 47 | outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]); 48 | outStream.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]); 49 | outStream.write('='); 50 | } else { 51 | a = data[offset]; 52 | b = data[offset + 1]; 53 | c = data[offset + 2]; 54 | outStream.write(pem_array[(a >>> 2) & 0x3F]); 55 | outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]); 56 | outStream.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]); 57 | outStream.write(pem_array[c & 0x3F]); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/Video.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 回复视频消息中的视频对象 24 | * 25 | *

提供了获取视频IdgetMediaId()等主要方法.

26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class Video implements java.io.Serializable { 31 | 32 | private String MediaId; //通过上传多媒体文件,得到的id 33 | private String Title; //视频消息的标题 34 | private String Description; //视频消息的描述 35 | 36 | /** 37 | * 获取 通过上传多媒体文件,得到的id 38 | * 39 | * @return 通过上传多媒体文件,得到的id 40 | */ 41 | public String getMediaId() { 42 | return MediaId; 43 | } 44 | 45 | /** 46 | * 设置 通过上传多媒体文件,得到的id 47 | * 48 | * @param mediaId 通过上传多媒体文件,得到的id 49 | */ 50 | public void setMediaId(String mediaId) { 51 | this.MediaId = mediaId; 52 | } 53 | 54 | /** 55 | * @return the Title 56 | */ 57 | public String getTitle() { 58 | return Title; 59 | } 60 | 61 | /** 62 | * @param Title the Title to set 63 | */ 64 | public void setTitle(String Title) { 65 | this.Title = Title; 66 | } 67 | 68 | /** 69 | * @return the Description 70 | */ 71 | public String getDescription() { 72 | return Description; 73 | } 74 | 75 | /** 76 | * @param Description the Description to set 77 | */ 78 | public void setDescription(String Description) { 79 | this.Description = Description; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/js/WxConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.js; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * 微信js接口config配置 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public class WxConfig implements Serializable { 31 | 32 | private String appId; 33 | private String timestamp; 34 | private String nonceStr; 35 | private String signature; 36 | 37 | public String getAppId() { 38 | return appId; 39 | } 40 | 41 | public void setAppId(String appId) { 42 | this.appId = appId; 43 | } 44 | 45 | public String getTimestamp() { 46 | return timestamp; 47 | } 48 | 49 | public void setTimestamp(String timestamp) { 50 | this.timestamp = timestamp; 51 | } 52 | 53 | public String getNonceStr() { 54 | return nonceStr; 55 | } 56 | 57 | public void setNonceStr(String nonceStr) { 58 | this.nonceStr = nonceStr; 59 | } 60 | 61 | public String getSignature() { 62 | return signature; 63 | } 64 | 65 | public void setSignature(String signature) { 66 | this.signature = signature; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "{appId:\"" + this.getAppId() + "\",\n" 72 | + "timestamp: \"" + this.getTimestamp() + "\",\n" 73 | + "nonceStr: \"" + this.getNonceStr() + "\",\n" 74 | + "signature: \"" + this.getSignature() + "\",}"; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/Music.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 回复音乐消息中的音乐对象 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class Music implements java.io.Serializable { 29 | 30 | private String Title; //音乐标题 31 | private String Description; //音乐描述 32 | private String MusicUrl; //音乐链接 33 | private String HQMusicUrl; //高质量音乐链接,WIFI环境优先使用该链接播放音乐 34 | private String ThumbMediaId; //缩略图的媒体id,通过上传多媒体文件,得到的id 35 | 36 | public String getTitle() { 37 | return Title; 38 | } 39 | 40 | public void setTitle(String Title) { 41 | this.Title = Title; 42 | } 43 | 44 | public String getDescription() { 45 | return Description; 46 | } 47 | 48 | public void setDescription(String Description) { 49 | this.Description = Description; 50 | } 51 | 52 | public String getMusicUrl() { 53 | return MusicUrl; 54 | } 55 | 56 | public void setMusicUrl(String MusicUrl) { 57 | this.MusicUrl = MusicUrl; 58 | } 59 | 60 | public String getHQMusicUrl() { 61 | return HQMusicUrl; 62 | } 63 | 64 | public void setHQMusicUrl(String HQMusicUrl) { 65 | this.HQMusicUrl = HQMusicUrl; 66 | } 67 | 68 | public String getThumbMediaId() { 69 | return ThumbMediaId; 70 | } 71 | 72 | public void setThumbMediaId(String ThumbMediaId) { 73 | this.ThumbMediaId = ThumbMediaId; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/menu/MiniprogramButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.menu; 21 | 22 | /** 23 | * 打开小程序 24 | * 25 | * @author yangqisheng 26 | * @since 0.1.2 27 | */ 28 | public class MiniprogramButton extends SingleButton { 29 | 30 | /** 31 | * 小程序的appid(仅认证公众号可配置) 32 | */ 33 | private String appid; 34 | /** 35 | * 小程序的页面路径 36 | */ 37 | private String pagepath; 38 | /** 39 | * 网页 链接,用户点击菜单可打开链接,不超过1024字节。 40 | * 41 | * 不支持小程序的老版本客户端将打开本url。 42 | */ 43 | private String url; 44 | 45 | public MiniprogramButton(String name) { 46 | super(name); 47 | } 48 | 49 | public MiniprogramButton(String name, String appid, String pagepath, String url) { 50 | super(name); 51 | this.appid = appid; 52 | this.pagepath = pagepath; 53 | this.url = url; 54 | } 55 | 56 | public String getType() { 57 | return ButtonType.Miniprogram.toString(); 58 | } 59 | 60 | public String getAppid() { 61 | return appid; 62 | } 63 | 64 | public void setAppid(String appid) { 65 | this.appid = appid; 66 | } 67 | 68 | public String getPagepath() { 69 | return pagepath; 70 | } 71 | 72 | public void setPagepath(String pagepath) { 73 | this.pagepath = pagepath; 74 | } 75 | 76 | public String getUrl() { 77 | return url; 78 | } 79 | 80 | public void setUrl(String url) { 81 | this.url = url; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/util/SHA1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.util; 21 | 22 | import java.security.MessageDigest; 23 | import java.security.NoSuchAlgorithmException; 24 | 25 | /** 26 | * SHA1算法 27 | * 28 | * @author yangqisheng 29 | * @since 0.0.1 30 | */ 31 | public final class SHA1 { 32 | 33 | private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 34 | 35 | /** 36 | * Takes the raw bytes from the digest and formats them correct. 37 | * 38 | * @param bytes the raw bytes from the digest. 39 | * @return the formatted bytes. 40 | */ 41 | private static String getFormattedText(byte[] bytes) { 42 | int len = bytes.length; 43 | StringBuilder buf = new StringBuilder(len * 2); 44 | // 把密文转换成十六进制的字符串形式 45 | for (int j = 0; j < len; j++) { 46 | buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]); 47 | buf.append(HEX_DIGITS[bytes[j] & 0x0f]); 48 | } 49 | return buf.toString(); 50 | } 51 | 52 | public static String encode(String str) { 53 | if (str == null) { 54 | return null; 55 | } 56 | try { 57 | MessageDigest messageDigest = MessageDigest.getInstance("SHA1"); 58 | messageDigest.update(str.getBytes()); 59 | return getFormattedText(messageDigest.digest()); 60 | } catch (NoSuchAlgorithmException e) { 61 | throw new RuntimeException(e); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/template/TemplateMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.template; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * 实体类对象,发送模板消息对象 26 | * 27 | * @author yangqisheng 28 | * @since 0.1.0 29 | */ 30 | public class TemplateMessage implements java.io.Serializable { 31 | 32 | /** 33 | * 接收者openid,对应官方参数touser 34 | */ 35 | private String openid; 36 | /** 37 | * 模板ID 38 | */ 39 | private String templateId; 40 | /** 41 | * 模板跳转链接 42 | */ 43 | private String url; 44 | /** 45 | * 跳小程序所需数据,不需跳小程序可不用传该数据 46 | */ 47 | private Miniprogram miniprogram; 48 | /** 49 | * 模板数据 50 | */ 51 | private List data; 52 | 53 | public String getOpenid() { 54 | return openid; 55 | } 56 | 57 | public void setOpenid(String openid) { 58 | this.openid = openid; 59 | } 60 | 61 | public String getTemplateId() { 62 | return templateId; 63 | } 64 | 65 | public void setTemplateId(String templateId) { 66 | this.templateId = templateId; 67 | } 68 | 69 | public String getUrl() { 70 | return url; 71 | } 72 | 73 | public void setUrl(String url) { 74 | this.url = url; 75 | } 76 | 77 | public Miniprogram getMiniprogram() { 78 | return miniprogram; 79 | } 80 | 81 | public void setMiniprogram(Miniprogram miniprogram) { 82 | this.miniprogram = miniprogram; 83 | } 84 | 85 | public List getData() { 86 | return data; 87 | } 88 | 89 | public void setData(List data) { 90 | this.data = data; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/normal/NormalMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.normal; 21 | 22 | import javax.xml.bind.annotation.XmlElement; 23 | 24 | /** 25 | * 普通消息 26 | * 27 | * @author yangqisheng 28 | * @since 0.0.1 29 | */ 30 | public abstract class NormalMessage { 31 | 32 | /** 33 | * 开发者微信号 34 | */ 35 | private String ToUserName; 36 | /** 37 | * 发送方帐号(一个OpenID) 38 | */ 39 | private String FromUserName; 40 | /** 41 | * 消息创建时间 (整型) 42 | */ 43 | private Long CreateTime; 44 | /** 45 | * 消息id,64位整型 46 | */ 47 | private Long MsgId; 48 | 49 | /** 50 | * 获取 消息类型 51 | * 52 | * @return 消息类型 53 | */ 54 | public abstract String getMsgType(); 55 | 56 | public String getToUserName() { 57 | return ToUserName; 58 | } 59 | 60 | @XmlElement(name = "ToUserName") 61 | public void setToUserName(String ToUserName) { 62 | this.ToUserName = ToUserName; 63 | } 64 | 65 | public String getFromUserName() { 66 | return FromUserName; 67 | } 68 | 69 | @XmlElement(name = "FromUserName") 70 | public void setFromUserName(String FromUserName) { 71 | this.FromUserName = FromUserName; 72 | } 73 | 74 | public Long getCreateTime() { 75 | return CreateTime; 76 | } 77 | 78 | @XmlElement(name = "CreateTime") 79 | public void setCreateTime(Long CreateTime) { 80 | this.CreateTime = CreateTime; 81 | } 82 | 83 | public Long getMsgId() { 84 | return MsgId; 85 | } 86 | 87 | @XmlElement(name = "MsgId") 88 | public void setMsgId(Long MsgId) { 89 | this.MsgId = MsgId; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/user/Followers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.user; 21 | 22 | /** 23 | * 微信平台关注者对象 24 | * 25 | *

通过Weixin产生一个请求对象,通过getWeixinUser()生成一个WeixinUser, 26 | * 然后调用getUserList(),得到本对象.

27 | * 28 | * @author yangqisheng 29 | * @since 0.0.1 30 | */ 31 | public class Followers { 32 | 33 | private int total; //关注该公众账号的总用户数 34 | private int count; //拉取的OPENID个数,最大值为10000 35 | private Data data; //列表数据,OPENID的列表 36 | private String next_openid; //拉取列表的后一个用户的OPENID 37 | 38 | /** 39 | * @return the total 40 | */ 41 | public int getTotal() { 42 | return total; 43 | } 44 | 45 | /** 46 | * @param total the total to set 47 | */ 48 | public void setTotal(int total) { 49 | this.total = total; 50 | } 51 | 52 | /** 53 | * @return the count 54 | */ 55 | public int getCount() { 56 | return count; 57 | } 58 | 59 | /** 60 | * @param count the count to set 61 | */ 62 | public void setCount(int count) { 63 | this.count = count; 64 | } 65 | 66 | /** 67 | * @return the next_openid 68 | */ 69 | public String getNext_openid() { 70 | return next_openid; 71 | } 72 | 73 | /** 74 | * @param next_openid the next_openid to set 75 | */ 76 | public void setNext_openid(String next_openid) { 77 | this.next_openid = next_openid; 78 | } 79 | 80 | /** 81 | * @return the data 82 | */ 83 | public Data getData() { 84 | return data; 85 | } 86 | 87 | /** 88 | * @param data the data to set 89 | */ 90 | public void setData(Data data) { 91 | this.data = data; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/OutputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 微信发送被动响应消息的抽象类 24 | * 25 | *

26 | * 应用程序需要定义一个子类,来实现具体方法

27 | * 28 | * @author yangqisheng 29 | * @since 0.0.1 30 | */ 31 | public abstract class OutputMessage implements java.io.Serializable { 32 | 33 | /** 34 | * 接收方帐号(收到的OpenID) 35 | */ 36 | private String ToUserName; 37 | /** 38 | * 开发者微信号 39 | */ 40 | private String FromUserName; 41 | /** 42 | * 消息创建时间 (整型) 43 | */ 44 | private Long CreateTime; 45 | 46 | /** 47 | * 获取 接收方帐号(收到的OpenID) 48 | * 49 | * @return 接收方帐号(收到的OpenID) 50 | */ 51 | public String getToUserName() { 52 | return ToUserName; 53 | } 54 | 55 | /** 56 | * 设置 接收方帐号(收到的OpenID) 57 | * 58 | * @return 接收方帐号(收到的OpenID) 59 | */ 60 | public String getFromUserName() { 61 | return FromUserName; 62 | } 63 | 64 | /** 65 | * 获取 消息创建时间 (整型) 66 | * 67 | * @return 消息创建时间 (整型) 68 | */ 69 | public Long getCreateTime() { 70 | return CreateTime; 71 | } 72 | 73 | /** 74 | * 获取 消息类型 75 | * 76 | * @return 消息类型 77 | */ 78 | public abstract String getMsgType(); 79 | 80 | /** 81 | * 将对象转换为xml字符串 82 | * 83 | * @return 对象xml字符串 84 | */ 85 | public abstract String toXML(); 86 | 87 | public void setToUserName(String ToUserName) { 88 | this.ToUserName = ToUserName; 89 | } 90 | 91 | public void setFromUserName(String FromUserName) { 92 | this.FromUserName = FromUserName; 93 | } 94 | 95 | public void setCreateTime(Long CreateTime) { 96 | this.CreateTime = CreateTime; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Weixin4j ## 2 | 3 | 微信SDK For Java 4 | 为Java微信开发爱好者提供的微信公众开发平台SDK 5 | 6 | ## 官方网站 ## 7 | 8 | http://www.weixin4j.org/ 9 | 10 | ## 入门视频 ## 11 | 12 | 腾讯视频播放链接地址:https://v.qq.com/x/page/t0630doxoaz.html 13 | 14 | ##更新日志 15 | 16 | 2020年05月07日 17 | 18 | weixin4j-v0.1.6 19 | 1.升级fastjson版本,1.2.31升级为1.2.68 20 | 2.WeixinPayConfig配置商户号字段改名partnerId改为mchId、partnerKey改为mchKey,兼容原字段 21 | 3.去除微信支付v2.5相关过期方法 22 | 4.优化base()组件获取token时因fastjson版本过高json解析无效BUG 23 | 24 | 2019年07月03日 25 | 26 | weixin4j-v0.1.5 27 | 1.增加自定义菜单支持创建小程序菜单 28 | 2.升级fastjson版本,1.2.7升级为1.2.31 29 | 3.增加微信支付普通服务商下单接口 30 | 4.优化部分代码格式 31 | 32 | 2019年03月20日 33 | 34 | weixin4j-v0.1.4 35 | 1.修复模板消息支持添加小程序 36 | 2.优化媒体文件下载接口 37 | 3.增加新增临时素材接口 38 | 4.优化部分代码格式 39 | 40 | 2018年08月16日 41 | 42 | weixin4j-v0.1.3 43 | 1.增加WeixinConfig对象、WeixinPayConfig对象 44 | 2.增加WeixinFactory对象及DefaultWeixinFactory 45 | 3.优化WeixinBuilder支持传WeixinConfig、WeixinPayConfig 46 | 47 | 2018年08月09日 48 | 49 | weixin4j-v0.1.2 50 | 1.优化自定义菜单组件 51 | 2.新增创建小程序菜单对象 52 | 53 | 2018年06月08日 54 | 55 | weixin4j-v0.1.1 56 | 1.新增微信支付订单查询 57 | 2.优化access_token并发导致过期BUG 58 | 59 | 2018年04月16日 60 | 61 | weixin4j-v0.1.0 62 | 全新版本升级,支持多公众号,组件化调用,接口更全,一行代码接入,调用更快捷。 63 | 64 | 2017年10月18日 65 | 66 | weixin4j-v0.0.9.2 复BUG,未关注公众号扫场景二维码事件未触发。 67 | 68 | 2016年05月26日 69 | 70 | weixin4j-v0.0.9.1 修复BUG,点击菜单跳转链接时的事件推送消息解析异常。 71 | 72 | 2016年04月29日 73 | 74 | weixin4j-v0.0.9 微信用户标签接口更新,完美支持用户标签和用户备注接口。 75 | 76 | 2015年11月29日 77 | 78 | weixin4j-v0.0.8 Weixin对象中新增“获取微信服务器IP地址”方法。 79 | 80 | 2015年10月16日 81 | 82 | weixin4j-v0.0.8 Weixin对象新增getOAuthToken()方法,获取access_token对象 83 | 84 | 2015年10月01日 85 | 86 | weixin4j-v0.0.8 优化微信网页支付功能 87 | 88 | 2015年09月04日 89 | 90 | weixin4j-v0.0.8 新增红包发送功能 91 | 92 | 2015年09月01日 93 | 94 | weixin4j-v0.0.7版内部发布 95 | 1.改进消息接入WeixinUrlFiter 96 | 2.新增消息类型枚举对象MsgType 97 | 3.优化自定义菜单,新增多项子菜单类型 98 | 99 | 2015年08月01日 100 | 101 | weixin4j-beta-v0.0.7版内测 102 | 103 | 2015年07月28日 104 | 105 | weixin4j-v0.0.6版上线 106 | 107 | 2015年05月01日 108 | 109 | weixin4j-v0.0.5版上线 110 | 111 | 2015年03月15日 112 | 113 | weixin4j-v0.0.4版上线 114 | 115 | 2015年01月01日 116 | 117 | weixin4j-v0.0.3版上线 118 | 119 | 2014年11月15日 120 | 121 | weixin4j-v0.0.2版上线 122 | 123 | 2014年10月01日 124 | 125 | weixin4j-v0.0.1版上线 126 | 127 | 2014年09月05日 128 | 129 | weixin4j-beta-v0.0.1版内测 -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/SendLocationInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | import javax.xml.bind.annotation.XmlElement; 23 | import javax.xml.bind.annotation.XmlRootElement; 24 | 25 | /** 26 | * 发送的位置信息 27 | * 28 | * @author yangqisheng 29 | * @since 0.0.1 30 | */ 31 | @XmlRootElement(name = "SendLocationInfo") 32 | public class SendLocationInfo { 33 | 34 | //X坐标信息 35 | private double Location_X; 36 | //Y坐标信息 37 | private double Location_Y; 38 | //精度,可理解为精度或者比例尺、越精细的话 scale越高 39 | private int Scale; 40 | //地理位置的字符串信息 41 | private String Label; 42 | //朋友圈POI的名字,可能为空 43 | private String Poiname; 44 | 45 | public double getLocation_X() { 46 | return Location_X; 47 | } 48 | 49 | @XmlElement(name = "Location_X") 50 | public void setLocation_X(double Location_X) { 51 | this.Location_X = Location_X; 52 | } 53 | 54 | public double getLocation_Y() { 55 | return Location_Y; 56 | } 57 | 58 | @XmlElement(name = "Location_Y") 59 | public void setLocation_Y(double Location_Y) { 60 | this.Location_Y = Location_Y; 61 | } 62 | 63 | public int getScale() { 64 | return Scale; 65 | } 66 | 67 | @XmlElement(name = "Scale") 68 | public void setScale(int Scale) { 69 | this.Scale = Scale; 70 | } 71 | 72 | public String getLabel() { 73 | return Label; 74 | } 75 | 76 | @XmlElement(name = "Label") 77 | public void setLabel(String Label) { 78 | this.Label = Label; 79 | } 80 | 81 | public String getPoiname() { 82 | return Poiname; 83 | } 84 | 85 | @XmlElement(name = "Poiname") 86 | public void setPoiname(String Poiname) { 87 | this.Poiname = Poiname; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /example/weixin4j-example/src/main/resources/weixin4j.properties: -------------------------------------------------------------------------------- 1 | #\u5fae\u4fe1SDK\u914d\u7f6e\u6587\u4ef6 2 | #\u8bfb\u53d6\u89c4\u5219\uff1a\u4f18\u5148\u8bfb\u53d6System.getProperty() 3 | #\u518d\u4eceweixin4j.properties\u8bfb\u53d6,key 4 | #\u5982\u679cSystem.getProperty()\u4e0eweixin4j.properties\u90fd\u6ca1\u8bbe\u7f6e\uff0c\u5219\u9ed8\u8ba4\u672aNULL 5 | 6 | #\u5f00\u53d1\u8005\u8c03\u8bd5\u8bbe\u7f6e 7 | weixin4j.debug=true 8 | #\u516c\u4f17\u53f7Token 9 | weixin4j.token=weixin4j 10 | 11 | #\u516c\u4f17\u53f7\u539f\u59cbID 12 | weixin4j.oauth.originalid= 13 | #\u5f00\u53d1\u8005\u7b2c\u4e09\u65b9\u7528\u6237\u552f\u4e00\u51ed\u8bc1 14 | weixin4j.oauth.appid=wx1234567890 15 | #\u5f00\u53d1\u8005\u7b2c\u4e09\u65b9\u7528\u6237\u552f\u4e00\u51ed\u8bc1\u5bc6\u94a5 16 | weixin4j.oauth.secret=11111 17 | #\u6d88\u606f\u52a0\u5bc6\u65b9\u5f0f 0:\u660e\u6587\u6a21\u5f0f(\u9ed8\u8ba4), 1:\u517c\u5bb9\u6a21\u5f0f, 2:\u5b89\u5168\u6a21\u5f0f(\u63a8\u8350) 18 | weixin4j.oauth.encodingtype=0 19 | #\u6d88\u606f\u52a0\u5bc6\u5bc6\u94a5(43\u4f4d\u5b57\u7b26\u7ec4\u6210A-Za-z0-9) 20 | weixin4j.oauth.encodingaeskey=0123456789abcedfghijklmnopqrstuvwxyzZXCVBNM 21 | #\u7f51\u9875\u5b89\u5168\u6388\u6743URL 22 | weixin4j.oauth.url= 23 | 24 | #\u516c\u4f17\u5e73\u53f0\u63a5\u53e3\u57df\u540d 25 | #\u901a\u7528\u57df\u540d(api.weixin.qq.com)\uff0c\u4f7f\u7528\u8be5\u57df\u540d\u5c06\u8bbf\u95ee\u5b98\u65b9\u6307\u5b9a\u5c31\u8fd1\u7684\u63a5\u5165\u70b9\uff1b 26 | #\u4e0a\u6d77\u57df\u540d(sh.api.weixin.qq.com)\uff0c\u4f7f\u7528\u8be5\u57df\u540d\u5c06\u8bbf\u95ee\u4e0a\u6d77\u7684\u63a5\u5165\u70b9\uff1b 27 | #\u6df1\u5733\u57df\u540d(sz.api.weixin.qq.com)\uff0c\u4f7f\u7528\u8be5\u57df\u540d\u5c06\u8bbf\u95ee\u6df1\u5733\u7684\u63a5\u5165\u70b9\uff1b 28 | #\u9999\u6e2f\u57df\u540d(hk.api.weixin.qq.com)\uff0c\u4f7f\u7528\u8be5\u57df\u540d\u5c06\u8bbf\u95ee\u9999\u6e2f\u7684\u63a5\u5165\u70b9\u3002 29 | weixin4j.api.domain=api.weixin.qq.com 30 | 31 | #\u5fae\u4fe1\u652f\u4ed8_\u5546\u6237ID 32 | weixin4j.pay.partner.id= 33 | #\u5fae\u4fe1\u652f\u4ed8_\u5546\u6237\u5bc6\u94a5 34 | weixin4j.pay.partner.key= 35 | #\u5fae\u4fe1\u652f\u4ed8_\u901a\u77e5URL 36 | weixin4j.pay.notify_url= 37 | 38 | #\u8fde\u63a5\u8d85\u65f6\u8bbe\u7f6e 39 | weixin4j.http.connectionTimeout=25000 40 | #\u8bf7\u6c42\u8d85\u65f6\u8bbe\u7f6e 41 | weixin4j.http.readTimeout=25000 42 | #\u8bc1\u4e66\u8def\u5f84 43 | weixin4j.http.cert.path= 44 | weixin4j.http.cert.secret= 45 | 46 | #\u9ed8\u8ba4\u6d88\u606f\u5904\u7406\u51fd\u6570 47 | weixin4j.handler=org.weixin4j.spi.DefaultMessageHandler 48 | weixin4j.message.handler.normal=org.weixin4j.spi.DefaultNormalMessageHandler 49 | weixin4j.message.handler.event=org.weixin4j.spi.DefaultEventMessageHandler -------------------------------------------------------------------------------- /example/weixin4j-example-web/src/main/java/com/ansitech/weixin4j/example/handler/AtsNormalMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.ansitech.weixin4j.example.handler; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.weixin4j.model.message.OutputMessage; 6 | import org.weixin4j.model.message.normal.ImageInputMessage; 7 | import org.weixin4j.model.message.normal.LinkInputMessage; 8 | import org.weixin4j.model.message.normal.LocationInputMessage; 9 | import org.weixin4j.model.message.normal.ShortVideoInputMessage; 10 | import org.weixin4j.model.message.normal.TextInputMessage; 11 | import org.weixin4j.model.message.normal.VideoInputMessage; 12 | import org.weixin4j.model.message.normal.VoiceInputMessage; 13 | import org.weixin4j.model.message.output.TextOutputMessage; 14 | import org.weixin4j.spi.INormalMessageHandler; 15 | 16 | /** 17 | * 自定义普通消息处理器 18 | * 19 | * @author yangqisheng 20 | */ 21 | public class AtsNormalMessageHandler implements INormalMessageHandler { 22 | 23 | protected final Logger LOG = LoggerFactory.getLogger(AtsNormalMessageHandler.class); 24 | 25 | @Override 26 | public OutputMessage textTypeMsg(TextInputMessage msg) { 27 | LOG.debug("文本消息:" + msg.getContent()); 28 | TextOutputMessage out = new TextOutputMessage(); 29 | out.setContent("您发的消息是:" + msg.getContent()); 30 | return out; 31 | } 32 | 33 | @Override 34 | public OutputMessage imageTypeMsg(ImageInputMessage msg) { 35 | TextOutputMessage out = new TextOutputMessage(); 36 | out.setContent("你的消息已经收到!"); 37 | return out; 38 | } 39 | 40 | @Override 41 | public OutputMessage voiceTypeMsg(VoiceInputMessage msg) { 42 | TextOutputMessage out = new TextOutputMessage(); 43 | out.setContent("你的消息已经收到!"); 44 | return out; 45 | } 46 | 47 | @Override 48 | public OutputMessage videoTypeMsg(VideoInputMessage msg) { 49 | TextOutputMessage out = new TextOutputMessage(); 50 | out.setContent("你的消息已经收到!"); 51 | return out; 52 | } 53 | 54 | @Override 55 | public OutputMessage shortvideoTypeMsg(ShortVideoInputMessage msg) { 56 | TextOutputMessage out = new TextOutputMessage(); 57 | out.setContent("你的消息已经收到!"); 58 | return out; 59 | } 60 | 61 | @Override 62 | public OutputMessage locationTypeMsg(LocationInputMessage msg) { 63 | TextOutputMessage out = new TextOutputMessage(); 64 | out.setContent("你的消息已经收到!"); 65 | return out; 66 | } 67 | 68 | @Override 69 | public OutputMessage linkTypeMsg(LinkInputMessage msg) { 70 | TextOutputMessage out = new TextOutputMessage(); 71 | out.setContent("你的消息已经收到!"); 72 | return out; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/pay/WCPay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.pay; 21 | 22 | import org.weixin4j.util.SignUtil; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | * 微信内网页支付 28 | * 29 | * @author yangqisheng 30 | * @since 0.0.4 31 | */ 32 | public class WCPay { 33 | 34 | private final String appId; //公众号Id 35 | private final String timeStamp; //时间戳 36 | private final String nonceStr; //随机字符串 37 | private final String packages; //订单详情扩展字符串 统一下单接口返回的prepay_id参数值,提交格式如:prepay_id=*** 38 | private final String signType = "MD5"; //签名方式 签名算法,暂支持MD5 39 | private final String paySign; //签名 40 | 41 | /** 42 | * getBrandWCPayRequest 43 | * 44 | * @param appId 公众号Id 45 | * @param prepay_id 预下单Id 46 | * @param paternerKey 商户密钥 47 | */ 48 | public WCPay(String appId, String prepay_id, String paternerKey) { 49 | this.appId = appId; 50 | this.timeStamp = System.currentTimeMillis() / 1000 + ""; 51 | this.nonceStr = java.util.UUID.randomUUID().toString().substring(0, 15); 52 | this.packages = "prepay_id=" + prepay_id; 53 | 54 | //对提交的参数进行签名 55 | Map paySignMap = new HashMap(); 56 | paySignMap.put("appId", this.appId); 57 | paySignMap.put("timeStamp", this.timeStamp); 58 | paySignMap.put("nonceStr", this.nonceStr); 59 | paySignMap.put("package", this.packages); 60 | paySignMap.put("signType", this.signType); 61 | 62 | //签名 63 | this.paySign = SignUtil.getSign(paySignMap, paternerKey); 64 | } 65 | 66 | public String getAppId() { 67 | return appId; 68 | } 69 | 70 | public String getTimeStamp() { 71 | return timeStamp; 72 | } 73 | 74 | public String getNonceStr() { 75 | return nonceStr; 76 | } 77 | 78 | public String getPackage() { 79 | return packages; 80 | } 81 | 82 | public String getSignType() { 83 | return signType; 84 | } 85 | 86 | public String getPaySign() { 87 | return paySign; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/spi/DefaultNormalMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.spi; 21 | 22 | import org.weixin4j.model.message.normal.TextInputMessage; 23 | import org.weixin4j.model.message.normal.ImageInputMessage; 24 | import org.weixin4j.model.message.normal.LinkInputMessage; 25 | import org.weixin4j.model.message.normal.LocationInputMessage; 26 | import org.weixin4j.model.message.normal.NormalMessage; 27 | import org.weixin4j.model.message.normal.ShortVideoInputMessage; 28 | import org.weixin4j.model.message.normal.VideoInputMessage; 29 | import org.weixin4j.model.message.normal.VoiceInputMessage; 30 | import org.weixin4j.model.message.OutputMessage; 31 | import org.weixin4j.model.message.output.TextOutputMessage; 32 | 33 | /** 34 | *

35 | * Title: 微信公众平台接受消息处理器

36 | * 37 | *

38 | * Description: 此消息处理器只负责接收消息和返回已收到消息的功能,无特殊功能。

39 | * 40 | * @author yangqisheng 41 | * @since 0.0.6 42 | */ 43 | public class DefaultNormalMessageHandler implements INormalMessageHandler { 44 | 45 | private OutputMessage allType(NormalMessage msg) { 46 | TextOutputMessage out = new TextOutputMessage(); 47 | out.setContent("你的消息已经收到!"); 48 | return out; 49 | } 50 | 51 | @Override 52 | public OutputMessage textTypeMsg(TextInputMessage msg) { 53 | return allType(msg); 54 | } 55 | 56 | @Override 57 | public OutputMessage imageTypeMsg(ImageInputMessage msg) { 58 | return allType(msg); 59 | } 60 | 61 | @Override 62 | public OutputMessage voiceTypeMsg(VoiceInputMessage msg) { 63 | return allType(msg); 64 | } 65 | 66 | @Override 67 | public OutputMessage videoTypeMsg(VideoInputMessage msg) { 68 | return allType(msg); 69 | } 70 | 71 | @Override 72 | public OutputMessage shortvideoTypeMsg(ShortVideoInputMessage msg) { 73 | return allType(msg); 74 | } 75 | 76 | @Override 77 | public OutputMessage locationTypeMsg(LocationInputMessage msg) { 78 | return allType(msg); 79 | } 80 | 81 | @Override 82 | public OutputMessage linkTypeMsg(LinkInputMessage msg) { 83 | return allType(msg); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/output/MusicOutputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.output; 21 | 22 | import org.weixin4j.model.message.Music; 23 | import org.weixin4j.model.message.OutputMessage; 24 | 25 | /** 26 | * 这个类实现了OutputMessage,用来回复音乐消息 27 | * 28 | *

29 | * 提供了获取音乐链接getMusicURL()等主要方法.

30 | * 31 | * @author yangqisheng 32 | * @since 0.0.1 33 | */ 34 | public class MusicOutputMessage extends OutputMessage { 35 | 36 | /** 37 | * 消息类型:音乐消息 38 | */ 39 | private final String MsgType = "music"; 40 | /** 41 | * 音乐消息对象 42 | */ 43 | private Music Music; 44 | 45 | @Override 46 | public String getMsgType() { 47 | return MsgType; 48 | } 49 | 50 | public MusicOutputMessage(Music music) { 51 | super(); 52 | Music = music; 53 | } 54 | 55 | public Music getMusic() { 56 | return Music; 57 | } 58 | 59 | public void setMusic(Music Music) { 60 | this.Music = Music; 61 | } 62 | 63 | @Override 64 | public String toXML() { 65 | StringBuilder sb = new StringBuilder(); 66 | sb.append(""); 67 | sb.append(""); 68 | sb.append(""); 69 | sb.append("").append(this.getCreateTime()).append(""); 70 | sb.append(""); 71 | sb.append(""); 72 | sb.append("<![CDATA[").append(this.getMusic().getTitle()).append("]]>"); 73 | sb.append(""); 74 | sb.append(""); 75 | sb.append(""); 76 | sb.append(""); 77 | sb.append(""); 78 | sb.append(""); 79 | return sb.toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/output/TextOutputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.output; 21 | 22 | import org.weixin4j.model.message.OutputMessage; 23 | 24 | /** 25 | * 这个类实现了OutputMessage,用来回复文本消息 26 | * 27 | *

28 | * 提供了获取文本内容getContent()等主要方法.

29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | public class TextOutputMessage extends OutputMessage { 34 | 35 | /** 36 | * 消息类型:文本消息 37 | */ 38 | private final String MsgType = "text"; 39 | /** 40 | * 文本消息 41 | */ 42 | private String Content; 43 | 44 | /** 45 | * 创建一个新的 Output Message.并且MsgType的值为text. 46 | */ 47 | public TextOutputMessage() { 48 | } 49 | 50 | /** 51 | * 创建一个自定义文本内容content的Output Message. 52 | * 53 | * @param content 文本内容 54 | */ 55 | public TextOutputMessage(String content) { 56 | Content = content; 57 | } 58 | 59 | /** 60 | * 获取 消息类型 61 | * 62 | * @return 消息类型 63 | */ 64 | @Override 65 | public String getMsgType() { 66 | return MsgType; 67 | } 68 | 69 | /** 70 | * 获取 文本消息 71 | * 72 | * @return 文本消息 73 | */ 74 | public String getContent() { 75 | return Content; 76 | } 77 | 78 | /** 79 | * 设置 文本消息 80 | * 81 | * @param content 文本消息 82 | */ 83 | public void setContent(String content) { 84 | Content = content; 85 | } 86 | 87 | @Override 88 | public String toXML() { 89 | StringBuilder sb = new StringBuilder(); 90 | sb.append(""); 91 | sb.append(""); 92 | sb.append(""); 93 | sb.append("").append(this.getCreateTime()).append(""); 94 | sb.append(""); 95 | sb.append(""); 96 | sb.append(""); 97 | return sb.toString(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/util/TokenUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.util; 21 | 22 | import org.weixin4j.Configuration; 23 | import java.util.ArrayList; 24 | import java.util.Collections; 25 | import java.util.Comparator; 26 | import java.util.List; 27 | 28 | /** 29 | *

30 | * Title: 微信公众平台Token算法工具类

31 | * 32 | *

33 | * Description: 为应用提供URL算法 根据不同的URL返回不同的Token,以适应多微站的需求 34 | * 例如:Url:http://www.weixin4j.org/api/tiexinqiao 35 | * 则默认Token:为jEvQdLxi0PvtgK8N+HzUpA== 根据配置的系统Token不同,而改变

36 | * 37 | * @author yangqisheng 38 | * @since 0.0.1 39 | */ 40 | public class TokenUtil { 41 | 42 | //此加密密钥用于加密公众号Token,一经配置,不能修改,一旦修改,所有公众号需要重新填写Token 43 | private static String systemToken = null; 44 | 45 | /** 46 | * 获取配置文件配置的Token 47 | * 48 | * @return 微站Token 49 | */ 50 | public static String get() { 51 | if (systemToken == null) { 52 | systemToken = Configuration.getProperty("weixin4j.token", "weixin4j"); 53 | } 54 | return systemToken; 55 | } 56 | 57 | /** 58 | * 加密/校验流程如下: 59 | * 60 | *

61 | * 1. 将token、timestamp、nonce三个参数进行字典序排序
62 | * 2.将三个参数字符串拼接成一个字符串进行sha1加密
63 | * 3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
64 | *

65 | * 66 | * @param token Token验证密钥 67 | * @param signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数,nonce参数 68 | * @param timestamp 时间戳 69 | * @param nonce 随机数 70 | * @return 验证成功返回true,否则返回false 71 | */ 72 | public static boolean checkSignature(String token, String signature, String timestamp, String nonce) { 73 | List params = new ArrayList(); 74 | params.add(token); 75 | params.add(timestamp); 76 | params.add(nonce); 77 | //1. 将token、timestamp、nonce三个参数进行字典序排序 78 | Collections.sort(params, new Comparator() { 79 | @Override 80 | public int compare(String o1, String o2) { 81 | return o1.compareTo(o2); 82 | } 83 | }); 84 | //2. 将三个参数字符串拼接成一个字符串进行sha1加密 85 | String temp = SHA1.encode(params.get(0) + params.get(1) + params.get(2)); 86 | //3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信 87 | return temp.equals(signature); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/WeixinConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j; 21 | 22 | /** 23 | * 微信配置 24 | * 25 | * @author yangqisheng 26 | * @since 0.1.3 27 | */ 28 | public class WeixinConfig { 29 | 30 | /** 31 | * 开发者第三方用户唯一凭证 32 | */ 33 | private String appid; 34 | /** 35 | * 开发者第三方用户唯一凭证密钥 36 | */ 37 | private String secret; 38 | /** 39 | * 公众号原始ID 40 | */ 41 | private String originalid; 42 | /** 43 | * 消息加密方式 0:明文模式(默认), 1:兼容模式, 2:安全模式(推荐) 44 | */ 45 | private int encodingtype = 0; 46 | /** 47 | * 消息加密密钥(43位字符组成A-Za-z0-9) 48 | */ 49 | private String encodingaeskey; 50 | /** 51 | * 网页安全授权URL 52 | */ 53 | private String oauthUrl; 54 | /** 55 | * 公众平台接口域名 56 | */ 57 | private String apiDomain = "api.weixin.qq.com"; 58 | 59 | public String getAppid() { 60 | return appid; 61 | } 62 | 63 | public void setAppid(String appid) { 64 | this.appid = appid; 65 | } 66 | 67 | public String getSecret() { 68 | return secret; 69 | } 70 | 71 | public void setSecret(String secret) { 72 | this.secret = secret; 73 | } 74 | 75 | public String getOriginalid() { 76 | return originalid; 77 | } 78 | 79 | public void setOriginalid(String originalid) { 80 | this.originalid = originalid; 81 | } 82 | 83 | public int getEncodingtype() { 84 | return encodingtype; 85 | } 86 | 87 | public void setEncodingtype(int encodingtype) { 88 | this.encodingtype = encodingtype; 89 | } 90 | 91 | public String getEncodingaeskey() { 92 | return encodingaeskey; 93 | } 94 | 95 | public void setEncodingaeskey(String encodingaeskey) { 96 | this.encodingaeskey = encodingaeskey; 97 | } 98 | 99 | public String getOauthUrl() { 100 | return oauthUrl; 101 | } 102 | 103 | public void setOauthUrl(String oauthUrl) { 104 | this.oauthUrl = oauthUrl; 105 | } 106 | 107 | public String getApiDomain() { 108 | return apiDomain; 109 | } 110 | 111 | public void setApiDomain(String apiDomain) { 112 | this.apiDomain = apiDomain; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/spi/INormalMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.spi; 21 | 22 | import org.weixin4j.model.message.normal.TextInputMessage; 23 | import org.weixin4j.model.message.normal.ImageInputMessage; 24 | import org.weixin4j.model.message.normal.LinkInputMessage; 25 | import org.weixin4j.model.message.normal.LocationInputMessage; 26 | import org.weixin4j.model.message.normal.ShortVideoInputMessage; 27 | import org.weixin4j.model.message.normal.VideoInputMessage; 28 | import org.weixin4j.model.message.normal.VoiceInputMessage; 29 | import org.weixin4j.model.message.OutputMessage; 30 | 31 | /** 32 | *

33 | * Title: 微信公众平台接受消息处理器

34 | * 35 | *

36 | * Description: 接受消息分8类,普通消息(1.文本消息、2.图片消息、3.语音消息 37 | * 、4.视频消息、5.地理位置消息、6.链接消息) 38 | * 事件推送(1.关注/取消关注事件、2.扫描带二维码参数事件、3.上报地理位置事件、4.自定义 39 | * 菜单事件、5.点击菜单拉取消息时事件推送、6.点击菜单跳转链接时的事件推送

40 | * 41 | * @author yangqisheng 42 | * @since 0.0.6 43 | */ 44 | public interface INormalMessageHandler { 45 | 46 | /** 47 | * 文字内容的消息处理 48 | * 49 | * @param msg 接受消息对象 50 | * @return 输出消息对象 51 | */ 52 | public OutputMessage textTypeMsg(TextInputMessage msg); 53 | 54 | /** 55 | * 图片类型的消息处理 56 | * 57 | * @param msg 接受消息对象 58 | * @return 输出消息对象 59 | */ 60 | public OutputMessage imageTypeMsg(ImageInputMessage msg); 61 | 62 | /** 63 | * 语音类型的消息处理 64 | * 65 | * @param msg 接受消息对象 66 | * @return 输出消息对象 67 | */ 68 | public OutputMessage voiceTypeMsg(VoiceInputMessage msg); 69 | 70 | /** 71 | * 视频类型的消息处理 72 | * 73 | * @param msg 接受消息对象 74 | * @return 输出消息对象 75 | */ 76 | public OutputMessage videoTypeMsg(VideoInputMessage msg); 77 | 78 | /** 79 | * 小视频类型的消息处理 80 | * 81 | * @param msg 接受消息对象 82 | * @return 输出消息对象 83 | */ 84 | public OutputMessage shortvideoTypeMsg(ShortVideoInputMessage msg); 85 | 86 | /** 87 | * 地理位置类型的消息处理 88 | * 89 | * @param msg 接受消息对象 90 | * @return 输出消息对象 91 | */ 92 | public OutputMessage locationTypeMsg(LocationInputMessage msg); 93 | 94 | /** 95 | * 链接类型的消息处理 96 | * 97 | * @param msg 接受消息对象 98 | * @return 输出消息对象 99 | */ 100 | public OutputMessage linkTypeMsg(LinkInputMessage msg); 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/util/PayUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.util; 21 | 22 | import java.io.StringReader; 23 | import java.util.Map; 24 | import javax.xml.bind.JAXBContext; 25 | import javax.xml.bind.JAXBException; 26 | import javax.xml.bind.Unmarshaller; 27 | import org.weixin4j.model.pay.PayNotifyResult; 28 | import org.weixin4j.model.pay.WCPay; 29 | import org.weixin4j.model.pay.WXPay; 30 | 31 | /** 32 | * 微信支付工具 33 | * 34 | * @author yangqisheng 35 | * @since 0.0.4 36 | */ 37 | public class PayUtil { 38 | 39 | /** 40 | * 对预下单Id进行H5支付 41 | * 42 | * @param appId 开发者Id 43 | * @param prepay_id 预下单Id 44 | * @param mchKey API密钥 45 | * @return 支付对象 46 | */ 47 | public static WCPay getBrandWCPayRequest(String appId, String prepay_id, String mchKey) { 48 | //初始化支付对象 49 | return new WCPay(appId, prepay_id, mchKey); 50 | } 51 | 52 | /** 53 | * chooseWXPay 54 | * 55 | * @param appId 公众号Id 56 | * @param jsapi_ticket jsapi验证票据 57 | * @param prepay_id 预下单Id 58 | * @param mchKey API密钥 59 | * @param url 发起请求的url地址 60 | * @return 支付对象 61 | */ 62 | public static WXPay getChooseWXPay(String appId, String jsapi_ticket, String prepay_id, String url, String mchKey) { 63 | return new WXPay(appId, jsapi_ticket, prepay_id, url, mchKey); 64 | } 65 | 66 | /** 67 | * 验证签名 68 | * 69 | * @param xmlMsg xml参数字符串 70 | * @param mchKey 商户密钥 71 | * @return 签名验证,成功返回true,否则返回false 72 | */ 73 | public static boolean verifySign(String xmlMsg, String mchKey) { 74 | try { 75 | JAXBContext context = JAXBContext.newInstance(PayNotifyResult.class); 76 | Unmarshaller unmarshaller = context.createUnmarshaller(); 77 | PayNotifyResult result = (PayNotifyResult) unmarshaller.unmarshal(new StringReader(xmlMsg)); 78 | //转换为Map 79 | Map map = result.toMap(); 80 | if (map.containsKey("sign")) { 81 | map.remove("sign"); 82 | } 83 | //签名 84 | String sign = SignUtil.getSign(map, mchKey); 85 | if (sign == null || sign.equals("")) { 86 | return false; 87 | } 88 | //判断是否一致 89 | return sign.equals(result.getSign()); 90 | } catch (JAXBException ex) { 91 | return false; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /example/weixin4j-example-web/src/main/java/com/ansitech/weixin4j/example/controller/WeixinJieruController.java: -------------------------------------------------------------------------------- 1 | package com.ansitech.weixin4j.example.controller; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletInputStream; 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.weixin4j.WeixinException; 11 | import org.weixin4j.spi.HandlerFactory; 12 | import org.weixin4j.spi.IMessageHandler; 13 | import org.weixin4j.util.TokenUtil; 14 | 15 | /** 16 | * 微信开发者接入 17 | * 18 | * @author yangqisheng 19 | */ 20 | @Controller 21 | @RequestMapping("/weixin/jieru") 22 | public class WeixinJieruController { 23 | 24 | //开发者接入验证 25 | @RequestMapping(method = RequestMethod.GET) 26 | public void get(HttpServletRequest request, HttpServletResponse response) throws IOException { 27 | //消息来源可靠性验证 28 | String signature = request.getParameter("signature");// 微信加密签名 29 | String timestamp = request.getParameter("timestamp");// 时间戳 30 | String nonce = request.getParameter("nonce"); // 随机数 31 | //Token为weixin4j.properties中配置的Token 32 | String token = TokenUtil.get(); 33 | //1.验证消息真实性 34 | //http://mp.weixin.qq.com/wiki/index.php?title=验证消息真实性 35 | //成为开发者验证 36 | String echostr = request.getParameter("echostr"); 37 | //确认此次GET请求来自微信服务器,原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败 38 | if (TokenUtil.checkSignature(token, signature, timestamp, nonce)) { 39 | response.getWriter().write(echostr); 40 | } 41 | } 42 | 43 | //接收微信消息 44 | @RequestMapping(method = RequestMethod.POST) 45 | public void post(HttpServletRequest request, HttpServletResponse response) throws IOException { 46 | //消息来源可靠性验证 47 | String signature = request.getParameter("signature");// 微信加密签名 48 | String timestamp = request.getParameter("timestamp");// 时间戳 49 | String nonce = request.getParameter("nonce"); // 随机数 50 | //Token为weixin4j.properties中配置的Token 51 | String token = TokenUtil.get(); 52 | //确认此次GET请求来自微信服务器,原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败 53 | if (!TokenUtil.checkSignature(token, signature, timestamp, nonce)) { 54 | //消息不可靠,直接返回 55 | response.getWriter().write(""); 56 | return; 57 | } 58 | //用户每次向公众号发送消息、或者产生自定义菜单点击事件时,响应URL将得到推送 59 | try { 60 | response.setCharacterEncoding("UTF-8"); 61 | response.setContentType("text/xml"); 62 | //获取POST流 63 | ServletInputStream in = request.getInputStream(); 64 | //非注解方式,依然采用消息处理工厂模式调用 65 | IMessageHandler messageHandler = HandlerFactory.getMessageHandler(); 66 | //处理输入消息,返回结果 67 | String xml = messageHandler.invoke(in); 68 | //返回结果 69 | response.getWriter().write(xml); 70 | } catch (IOException | WeixinException ex) { 71 | response.getWriter().write(""); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/output/VoiceOutputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.output; 21 | 22 | import org.weixin4j.model.message.Voice; 23 | import org.weixin4j.model.message.OutputMessage; 24 | 25 | /** 26 | * 这个类实现了OutputMessage,用来回复语音消息 27 | * 28 | *

提供了获取语音IdgetVoice()等主要方法.

29 | * 30 | * @author yangqisheng 31 | * @since 0.0.1 32 | */ 33 | public class VoiceOutputMessage extends OutputMessage { 34 | 35 | /** 36 | * 消息类型:语音消息 37 | */ 38 | private final String MsgType = "voice"; 39 | /** 40 | * 通过上传多媒体文件,得到的id封装的Voice对象 41 | */ 42 | private Voice Voice; 43 | 44 | /** 45 | * 创建一个新的 Output Message.并且MsgType的值为voice. 46 | */ 47 | public VoiceOutputMessage() { 48 | } 49 | 50 | /** 51 | * 创建一个自定义语音Id mediaId的Output Message. 52 | * 53 | * @param voice 语音资源Id 54 | */ 55 | public VoiceOutputMessage(Voice voice) { 56 | Voice = voice; 57 | } 58 | 59 | /** 60 | * 获取 消息类型 61 | * 62 | * @return 消息类型 63 | */ 64 | @Override 65 | public String getMsgType() { 66 | return MsgType; 67 | } 68 | 69 | /** 70 | * 获取 通过上传多媒体文件,得到的id封装的Voice对象 71 | * 72 | * @return 通过上传多媒体文件,得到的id封装的Voice对象 73 | */ 74 | public Voice getVoice() { 75 | return Voice; 76 | } 77 | 78 | /** 79 | * 设置 通过上传多媒体文件,得到的id封装的Voice对象 80 | * 81 | * @param voice 通过上传多媒体文件,得到的id封装的Voice对象 82 | */ 83 | public void setVoice(Voice voice) { 84 | Voice = voice; 85 | } 86 | 87 | @Override 88 | public String toXML() { 89 | StringBuilder sb = new StringBuilder(); 90 | sb.append(""); 91 | sb.append(""); 92 | sb.append(""); 93 | sb.append("").append(this.getCreateTime()).append(""); 94 | sb.append(""); 95 | sb.append(""); 96 | sb.append(""); 97 | sb.append(""); 98 | sb.append(""); 99 | return sb.toString(); 100 | } 101 | } -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/output/ImageOutputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.output; 21 | 22 | import org.weixin4j.model.message.Image; 23 | import org.weixin4j.model.message.OutputMessage; 24 | 25 | /** 26 | * 这个类实现了OutputMessage,用来回复图片消息 27 | * 28 | *

29 | * 提供了获取图片IdgetMediaId()等主要方法.

30 | * 31 | * @author yangqisheng 32 | * @since 0.0.1 33 | */ 34 | public class ImageOutputMessage extends OutputMessage { 35 | 36 | /** 37 | * 消息类型:图片消息 38 | */ 39 | private final String MsgType = "image"; 40 | /** 41 | * 通过上传多媒体文件,得到的id 42 | */ 43 | private Image Image; 44 | 45 | /** 46 | * 创建一个图片 Output Message. 47 | * 48 | * 并且MsgType的值为image. 49 | */ 50 | public ImageOutputMessage() { 51 | } 52 | 53 | /** 54 | * 创建一个图片 的Output Message. 55 | * 56 | * 并且MsgType的值为image. 57 | * 58 | * @param image 图片 59 | */ 60 | public ImageOutputMessage(Image image) { 61 | this.Image = image; 62 | } 63 | 64 | /** 65 | * 获取 消息类型 66 | * 67 | * @return 消息类型 68 | */ 69 | @Override 70 | public String getMsgType() { 71 | return MsgType; 72 | } 73 | 74 | /** 75 | * 获取 通过上传多媒体文件,得到的id 76 | * 77 | * @return 通过上传多媒体文件,得到的id封装的image对象 78 | */ 79 | public Image getImage() { 80 | return this.Image; 81 | } 82 | 83 | /** 84 | * 设置 通过上传多媒体文件,得到的id 85 | * 86 | * @param image 通过上传多媒体文件,得到的id封装的image对象 87 | */ 88 | public void setImage(Image image) { 89 | this.Image = image; 90 | } 91 | 92 | @Override 93 | public String toXML() { 94 | StringBuilder sb = new StringBuilder(); 95 | sb.append(""); 96 | sb.append(""); 97 | sb.append(""); 98 | sb.append("").append(this.getCreateTime()).append(""); 99 | sb.append(""); 100 | sb.append(""); 101 | sb.append(""); 102 | sb.append(""); 103 | sb.append(""); 104 | return sb.toString(); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /example/weixin4j-0.0.9.2微信支付案例/pay_notify.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="org.weixin4j.pay.PayNotifyResult"%> 2 | <%@page import="javax.xml.bind.JAXBContext"%> 3 | <%@page import="javax.xml.bind.Unmarshaller"%> 4 | <%@page import="org.weixin4j.Configuration"%> 5 | <%@page import="org.weixin4j.pay.PayUtil"%> 6 | <%@page import="org.weixin4j.util.XStreamFactory"%> 7 | <%@page import="java.util.Enumeration"%> 8 | <%@page import="java.util.Map"%> 9 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 10 | <% 11 | try { 12 | //--------------------------------------------------------- 13 | //微信支付支付通知(后台通知)示例,商户按照此文档进行开发即可 14 | //--------------------------------------------------------- 15 | //创建支付应答对象 16 | System.out.println("收到微信支付回调 start"); 17 | //获取Post的流 18 | ServletInputStream in = request.getInputStream(); 19 | //将流转换为字符串 20 | String xmlMsg = XStreamFactory.inputStream2String(in); 21 | //商户密钥 22 | String paternerKey = Configuration.getProperty("weixin4j.pay.partner.key"); 23 | 24 | JAXBContext context = JAXBContext.newInstance(PayNotifyResult.class); 25 | Unmarshaller unmarshaller = context.createUnmarshaller(); 26 | //结果 27 | PayNotifyResult payNotifyResult = (PayNotifyResult) unmarshaller.unmarshal(new StringReader(xmlMsg)); 28 | 29 | //商户订单号 30 | String out_trade_no = payNotifyResult.getOut_trade_no(); 31 | //支付结果 32 | String return_code = payNotifyResult.getReturn_code(); 33 | 34 | System.out.println("收到微信支付回调 return_code = " + return_code); 35 | System.out.println("收到微信支付回调 out_trade_no = " + out_trade_no); 36 | //判断签名及结果 37 | if ("SUCCESS".equals(return_code)) { 38 | //验证签名 39 | boolean verify = PayUtil.verifySign(xmlMsg, paternerKey); 40 | if (verify) { 41 | //------------------------------ 42 | //即时到账处理业务开始 43 | //------------------------------ 44 | //根据id查询支付订单信息 45 | //商户内部处理订单交易状态业务逻辑 start 46 | //商户内部代码 47 | //商户内部处理订单交易状态业务逻辑 end 48 | //注意交易单不要重复处理 49 | //注意判断返回金额 50 | //------------------------------ 51 | //即时到账处理业务完毕 52 | //------------------------------ 53 | //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知 54 | response.getWriter().write(""); 55 | System.out.println("收到微信支付回调 成功"); 56 | } else { 57 | System.out.println("收到微信支付回调 签名失败"); 58 | response.getWriter().write(""); 59 | } 60 | } else { 61 | System.out.println("收到微信支付回调 支付失败"); 62 | response.getWriter().write(""); 63 | } 64 | } catch (Exception ex) { 65 | System.out.println("收到微信支付回调 异常"); 66 | response.getWriter().write(""); 67 | } 68 | %> -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/Articles.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message; 21 | 22 | /** 23 | * 实体类对象,用来接受NewsOutputMessage中的条目 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class Articles { 29 | 30 | /** 31 | * 图文消息标题 32 | */ 33 | private String Title; 34 | /** 35 | * 图文消息描述 36 | */ 37 | private String Description; 38 | /** 39 | * 发送被动响应时设置的图片url 40 | * 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200 41 | */ 42 | private String PicUrl; 43 | /** 44 | * 发送客服消息时设置的图片URL 45 | */ 46 | private String picurl; 47 | /** 48 | * 点击图文消息跳转链接 49 | */ 50 | private String Url; 51 | 52 | /** 53 | * 获取 图文消息的标题 54 | * 55 | * @return 图文消息的标题 56 | */ 57 | public String getTitle() { 58 | return Title; 59 | } 60 | 61 | /** 62 | * 设置 图文消息的标题 63 | * 64 | * @param Title 图文消息的标题 65 | */ 66 | public void setTitle(String Title) { 67 | this.Title = Title; 68 | } 69 | 70 | /** 71 | * 获取 图文消息的描述 72 | * 73 | * @return 图文消息的描述 74 | */ 75 | public String getDescription() { 76 | return Description; 77 | } 78 | 79 | /** 80 | * 设置 图文消息的描述 81 | * 82 | * @param Description 图文消息的描述 83 | */ 84 | public void setDescription(String Description) { 85 | this.Description = Description; 86 | } 87 | 88 | /** 89 | * 获取 图片链接 90 | * 91 | * @return 图片链接 92 | */ 93 | public String getPicUrl() { 94 | return PicUrl; 95 | } 96 | 97 | /** 98 | * 设置 图片链接 99 | * 100 | * @param PicUrl 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200 101 | */ 102 | public void setPicUrl(String PicUrl) { 103 | this.PicUrl = PicUrl; 104 | } 105 | 106 | /** 107 | * 获取 点击图文消息跳转链接 108 | * 109 | * @return 点击图文消息跳转链接 110 | */ 111 | public String getUrl() { 112 | return Url; 113 | } 114 | 115 | /** 116 | * 设置 点击图文消息跳转链接 117 | * 118 | * @param Url 点击图文消息跳转链接 119 | */ 120 | public void setUrl(String Url) { 121 | this.Url = Url; 122 | } 123 | 124 | /** 125 | * @return the picurl 126 | */ 127 | public String getPicurl() { 128 | return picurl; 129 | } 130 | 131 | /** 132 | * @param picurl the picurl to set 133 | */ 134 | public void setPicurl(String picurl) { 135 | this.picurl = picurl; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/sns/SnsUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.sns; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * 网页授权用户信息 26 | * 27 | * @author yangqisheng 28 | * @since 0.1.0 29 | */ 30 | public class SnsUser implements Serializable{ 31 | 32 | private String openid; //用户的标识,对当前公众号唯一 33 | private String nickname; //用户的昵称 34 | private int sex; //用户的性别,值为1时是男性,值为2时是女性,值为0时是未知 35 | private String province; //用户所在省份 36 | private String city; //用户所在城市 37 | private String country; //用户所在国家 38 | private String headimgurl; //用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空 39 | private String[] privilege; //用户特权信息,json 数组,如微信沃卡用户为(chinaunicom) 40 | private String unionid; //只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。 41 | 42 | public String getOpenid() { 43 | return openid; 44 | } 45 | 46 | public void setOpenid(String openid) { 47 | this.openid = openid; 48 | } 49 | 50 | public String getNickname() { 51 | return nickname; 52 | } 53 | 54 | public void setNickname(String nickname) { 55 | this.nickname = nickname; 56 | } 57 | 58 | public int getSex() { 59 | return sex; 60 | } 61 | 62 | public void setSex(int sex) { 63 | this.sex = sex; 64 | } 65 | 66 | public String getProvince() { 67 | return province; 68 | } 69 | 70 | public void setProvince(String province) { 71 | this.province = province; 72 | } 73 | 74 | public String getCity() { 75 | return city; 76 | } 77 | 78 | public void setCity(String city) { 79 | this.city = city; 80 | } 81 | 82 | public String getCountry() { 83 | return country; 84 | } 85 | 86 | public void setCountry(String country) { 87 | this.country = country; 88 | } 89 | 90 | public String getHeadimgurl() { 91 | return headimgurl; 92 | } 93 | 94 | public void setHeadimgurl(String headimgurl) { 95 | this.headimgurl = headimgurl; 96 | } 97 | 98 | public String[] getPrivilege() { 99 | return privilege; 100 | } 101 | 102 | public void setPrivilege(String[] privilege) { 103 | this.privilege = privilege; 104 | } 105 | 106 | public String getUnionid() { 107 | return unionid; 108 | } 109 | 110 | public void setUnionid(String unionid) { 111 | this.unionid = unionid; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/js/Ticket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.js; 21 | 22 | import java.io.Serializable; 23 | import java.util.Date; 24 | 25 | /** 26 | * 凭证 27 | * 28 | * @author yangqisheng 29 | * @since 0.1.0 30 | */ 31 | public final class Ticket implements Serializable { 32 | 33 | /** 34 | * 凭证字符串 35 | */ 36 | private String ticket; 37 | 38 | /** 39 | * 凭证类型 40 | */ 41 | private TicketType ticketType; 42 | 43 | /** 44 | * 有效时间(s) 45 | */ 46 | private int expires_in; 47 | 48 | /** 49 | * 过期时间 50 | */ 51 | private long exprexpired_time; 52 | 53 | /** 54 | * 创建时间 55 | */ 56 | private long create_time; 57 | 58 | public Ticket(TicketType ticketType, String ticket, int expires_in) { 59 | this(ticketType, ticket, expires_in, System.currentTimeMillis()); 60 | } 61 | 62 | public Ticket(TicketType ticketType, String ticket, int expires_in, long create_time) { 63 | this.ticketType = ticketType; 64 | this.ticket = ticket; 65 | this.expires_in = expires_in; 66 | //获取当前时间毫秒数 67 | this.create_time = create_time - 60000; 68 | //设置下次过期时间 = 当前时间 + (凭证有效时间(秒) * 1000) 69 | this.exprexpired_time = this.create_time + (expires_in * 1000); 70 | } 71 | 72 | public String getTicket() { 73 | return ticket; 74 | } 75 | 76 | public void setTicket(String ticket) { 77 | this.ticket = ticket; 78 | } 79 | 80 | public TicketType getTicketType() { 81 | return ticketType; 82 | } 83 | 84 | public void setTicketType(TicketType ticketType) { 85 | this.ticketType = ticketType; 86 | } 87 | 88 | /** 89 | * 判断凭证是否过期 90 | * 91 | * @return 过期返回 true,否则返回false 92 | */ 93 | public boolean isExprexpired() { 94 | Date now = new Date(); 95 | long nowLong = now.getTime(); 96 | return nowLong >= exprexpired_time; 97 | } 98 | 99 | public int getExpires_in() { 100 | return expires_in; 101 | } 102 | 103 | public long getCreate_time() { 104 | return create_time + 60000; 105 | } 106 | 107 | /** 108 | * 将数据转换为JSON数据包 109 | * 110 | * @return JSON数据包 111 | */ 112 | @Override 113 | public String toString() { 114 | //对外的时间 需要加上扣掉的 60秒 115 | return "{\"ticket\":\"" + this.getTicket() + "\",\"expires_in\":" + this.getExpires_in() + ",\"create_time\" : " + this.getCreate_time() + "}"; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/misc/BASE64Decoder.java: -------------------------------------------------------------------------------- 1 | package org.weixin4j.misc; 2 | 3 | import java.io.OutputStream; 4 | import java.io.PushbackInputStream; 5 | 6 | public class BASE64Decoder extends CharacterDecoder { 7 | 8 | @Override 9 | protected int bytesPerAtom() { 10 | return (4); 11 | } 12 | 13 | @Override 14 | protected int bytesPerLine() { 15 | return (72); 16 | } 17 | 18 | private final static char pem_array[] = { 19 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 20 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 21 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 22 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 23 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 24 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 25 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 26 | '4', '5', '6', '7', '8', '9', '+', '/' 27 | }; 28 | 29 | private final static byte pem_convert_array[] = new byte[256]; 30 | 31 | static { 32 | for (int i = 0; i < 255; i++) { 33 | pem_convert_array[i] = -1; 34 | } 35 | for (int i = 0; i < pem_array.length; i++) { 36 | pem_convert_array[pem_array[i]] = (byte) i; 37 | } 38 | } 39 | byte decode_buffer[] = new byte[4]; 40 | 41 | @Override 42 | protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int rem) 43 | throws java.io.IOException { 44 | int i; 45 | byte a = -1, b = -1, c = -1, d = -1; 46 | 47 | if (rem < 2) { 48 | throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom."); 49 | } 50 | do { 51 | i = inStream.read(); 52 | if (i == -1) { 53 | throw new CEStreamExhausted(); 54 | } 55 | } while (i == '\n' || i == '\r'); 56 | decode_buffer[0] = (byte) i; 57 | 58 | i = readFully(inStream, decode_buffer, 1, rem - 1); 59 | if (i == -1) { 60 | throw new CEStreamExhausted(); 61 | } 62 | 63 | if (rem > 3 && decode_buffer[3] == '=') { 64 | rem = 3; 65 | } 66 | if (rem > 2 && decode_buffer[2] == '=') { 67 | rem = 2; 68 | } 69 | switch (rem) { 70 | case 4: 71 | d = pem_convert_array[decode_buffer[3] & 0xff]; 72 | // NOBREAK 73 | case 3: 74 | c = pem_convert_array[decode_buffer[2] & 0xff]; 75 | // NOBREAK 76 | case 2: 77 | b = pem_convert_array[decode_buffer[1] & 0xff]; 78 | a = pem_convert_array[decode_buffer[0] & 0xff]; 79 | break; 80 | } 81 | 82 | switch (rem) { 83 | case 2: 84 | outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3))); 85 | break; 86 | case 3: 87 | outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3))); 88 | outStream.write((byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf))); 89 | break; 90 | case 4: 91 | outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3))); 92 | outStream.write((byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf))); 93 | outStream.write((byte) (((c << 6) & 0xc0) | (d & 0x3f))); 94 | break; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /example/weixin4j-example-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.ansitech 5 | weixin4j-example-web 6 | 1.0.0 7 | jar 8 | 9 | org.springframework.boot 10 | spring-boot-starter-parent 11 | 1.5.9.RELEASE 12 | 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | org.weixin4j 26 | weixin4j 27 | 0.1.4 28 | 29 | 30 | 31 | UTF-8 32 | 1.7 33 | 1.7 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-jar-plugin 41 | 2.6 42 | 43 | 44 | 45 | 46 | com.ansitech.weixin4j.example.Application 47 | true 48 | lib/ 49 | 50 | 51 | ./ 52 | 53 | 54 | 55 | 56 | 57 | maven-assembly-plugin 58 | 59 | 60 | false 61 | 62 | 63 | src/main/resources/package.xml 64 | 65 | 66 | 67 | 68 | make-assembly 69 | package 70 | 71 | single 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/message/output/VideoOutputMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.message.output; 21 | 22 | import org.weixin4j.model.message.Video; 23 | import org.weixin4j.model.message.OutputMessage; 24 | 25 | /** 26 | * 这个类实现了OutputMessage,用来回复视频消息 27 | * 28 | *

29 | * 提供了获取视频IdgetMediaId()等主要方法.

30 | * 31 | * @author yangqisheng 32 | * @since 0.0.1 33 | */ 34 | public class VideoOutputMessage extends OutputMessage { 35 | 36 | /** 37 | * 消息类型:视频消息 38 | */ 39 | private final String MsgType = "video"; 40 | /** 41 | * 通过上传多媒体文件,得到的id 42 | */ 43 | private Video Video; 44 | 45 | /** 46 | * 创建一个视频 Output Message. 47 | * 48 | * 并且MsgType的值为video. 49 | */ 50 | public VideoOutputMessage() { 51 | } 52 | 53 | /** 54 | * 创建一个视频 Output Message. 55 | * 56 | * 并且MsgType的值为video. 57 | * 58 | * @param video 视频 59 | */ 60 | public VideoOutputMessage(Video video) { 61 | Video = video; 62 | } 63 | 64 | /** 65 | * 获取 消息类型 66 | * 67 | * @return 消息类型 68 | */ 69 | @Override 70 | public String getMsgType() { 71 | return MsgType; 72 | } 73 | 74 | /** 75 | * 获取 通过上传多媒体文件,得到的id 76 | * 77 | * @return 通过上传多媒体文件,得到的id 78 | */ 79 | public Video getVideo() { 80 | return Video; 81 | } 82 | 83 | /** 84 | * 设置 通过上传多媒体文件,得到的id 85 | * 86 | * @param video 通过上传多媒体文件,得到的id 87 | */ 88 | public void setVideo(Video video) { 89 | Video = video; 90 | } 91 | 92 | @Override 93 | public String toXML() { 94 | StringBuilder sb = new StringBuilder(); 95 | sb.append(""); 96 | sb.append(""); 97 | sb.append(""); 98 | sb.append("").append(this.getCreateTime()).append(""); 99 | sb.append(""); 100 | sb.append(""); 105 | sb.append(""); 106 | return sb.toString(); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/WeixinPayConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j; 21 | 22 | /** 23 | * 微信支付配置 24 | * 25 | * @author yangqisheng 26 | * @since 0.1.3 27 | */ 28 | public class WeixinPayConfig { 29 | 30 | /** 31 | * 微信支付_商户ID 32 | */ 33 | @Deprecated 34 | private String partnerId; 35 | /** 36 | * 微信支付_商户密钥 37 | */ 38 | @Deprecated 39 | private String partnerKey; 40 | /** 41 | * 微信支付_通知URL 42 | */ 43 | @Deprecated 44 | private String notifyUrl; 45 | /** 46 | * 开发者第三方用户唯一凭证 47 | */ 48 | private String appId; 49 | /** 50 | * 商户号 51 | * 52 | * @since 0.1.6 53 | */ 54 | private String mchId; 55 | /** 56 | * Api密钥 57 | */ 58 | private String mchKey; 59 | /** 60 | * 证书路径 61 | */ 62 | private String certPath; 63 | /** 64 | * 证书密钥,证书密码默认为您的商户号 65 | */ 66 | private String certSecret; 67 | 68 | /** 69 | * 商户号,官方已改名,请调用getMchId()方法 70 | * 71 | * @return 商户号 72 | * @since 0.1.3 73 | * @deprecated 74 | */ 75 | @Deprecated 76 | public String getPartnerId() { 77 | return partnerId; 78 | } 79 | 80 | @Deprecated 81 | public void setPartnerId(String partnerId) { 82 | this.partnerId = partnerId; 83 | } 84 | 85 | /** 86 | * 支付密钥,官方已改名,请调用getMchKey()方法 87 | * 88 | *

89 | * 账户设置--API安全--密钥设置

90 | * 91 | * @return 支付密钥 92 | * @since 0.1.3 93 | * @deprecated 94 | */ 95 | @Deprecated 96 | public String getPartnerKey() { 97 | return partnerKey; 98 | } 99 | 100 | @Deprecated 101 | public void setPartnerKey(String partnerKey) { 102 | this.partnerKey = partnerKey; 103 | } 104 | 105 | @Deprecated 106 | public String getNotifyUrl() { 107 | return notifyUrl; 108 | } 109 | 110 | @Deprecated 111 | public void setNotifyUrl(String notifyUrl) { 112 | this.notifyUrl = notifyUrl; 113 | } 114 | 115 | public String getAppId() { 116 | return appId; 117 | } 118 | 119 | public void setAppId(String appId) { 120 | this.appId = appId; 121 | } 122 | 123 | public String getMchId() { 124 | return mchId; 125 | } 126 | 127 | public void setMchId(String mchId) { 128 | this.mchId = mchId; 129 | } 130 | 131 | public String getMchKey() { 132 | return mchKey; 133 | } 134 | 135 | public void setMchKey(String mchKey) { 136 | this.mchKey = mchKey; 137 | } 138 | 139 | public String getCertPath() { 140 | return certPath; 141 | } 142 | 143 | public void setCertPath(String certPath) { 144 | this.certPath = certPath; 145 | } 146 | 147 | public String getCertSecret() { 148 | return certSecret; 149 | } 150 | 151 | public void setCertSecret(String certSecret) { 152 | this.certSecret = certSecret; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/model/media/Article.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.model.media; 21 | 22 | /** 23 | * 图文消息对象 24 | * 25 | * @author yangqisheng 26 | * @since 0.0.1 27 | */ 28 | public class Article { 29 | 30 | private String thumb_media_id; //图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得 31 | private String author; //图文消息的作者 32 | private String title; //图文消息的标题 33 | private String content_source_url; //在图文消息页面点击“阅读原文”后的页面 34 | private String content; //图文消息页面的内容,支持HTML标签 35 | private String digest; //图文消息的描述,如本字段为空,则默认抓取正文前64个字 36 | private int show_cover_pic;//是否显示封面,1为显示,0为不显示 37 | 38 | /** 39 | * @return the thumb_media_id 40 | */ 41 | public String getThumb_media_id() { 42 | return thumb_media_id; 43 | } 44 | 45 | /** 46 | * @param thumb_media_id the thumb_media_id to set 47 | */ 48 | public void setThumb_media_id(String thumb_media_id) { 49 | this.thumb_media_id = thumb_media_id; 50 | } 51 | 52 | /** 53 | * @return the author 54 | */ 55 | public String getAuthor() { 56 | return author; 57 | } 58 | 59 | /** 60 | * @param author the author to set 61 | */ 62 | public void setAuthor(String author) { 63 | this.author = author; 64 | } 65 | 66 | /** 67 | * @return the title 68 | */ 69 | public String getTitle() { 70 | return title; 71 | } 72 | 73 | /** 74 | * @param title the title to set 75 | */ 76 | public void setTitle(String title) { 77 | this.title = title; 78 | } 79 | 80 | /** 81 | * @return the content_source_url 82 | */ 83 | public String getContent_source_url() { 84 | return content_source_url; 85 | } 86 | 87 | /** 88 | * @param content_source_url the content_source_url to set 89 | */ 90 | public void setContent_source_url(String content_source_url) { 91 | this.content_source_url = content_source_url; 92 | } 93 | 94 | /** 95 | * @return the content 96 | */ 97 | public String getContent() { 98 | return content; 99 | } 100 | 101 | /** 102 | * @param content the content to set 103 | */ 104 | public void setContent(String content) { 105 | this.content = content; 106 | } 107 | 108 | /** 109 | * @return the digest 110 | */ 111 | public String getDigest() { 112 | return digest; 113 | } 114 | 115 | /** 116 | * @param digest the digest to set 117 | */ 118 | public void setDigest(String digest) { 119 | this.digest = digest; 120 | } 121 | 122 | /** 123 | * @return the show_cover_pic 124 | */ 125 | public int getShow_cover_pic() { 126 | return show_cover_pic; 127 | } 128 | 129 | /** 130 | * @param show_cover_pic the show_cover_pic to set 131 | */ 132 | public void setShow_cover_pic(int show_cover_pic) { 133 | this.show_cover_pic = show_cover_pic; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/util/SignUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 微信公众平台(JAVA) SDK 3 | * 4 | * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. 5 | * 6 | * http://www.weixin4j.org/ 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.weixin4j.util; 21 | 22 | import java.io.UnsupportedEncodingException; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | import org.apache.commons.codec.digest.DigestUtils; 26 | import org.weixin4j.Configuration; 27 | 28 | /** 29 | * 签名算法 30 | * 31 | * @author yangqisheng 32 | * @since 0.0.1 33 | */ 34 | public class SignUtil { 35 | 36 | /** 37 | * 生成jsapi授权签名 38 | * 39 | * 签名算法 40 | * 41 | * 签名生成规则如下: 42 | * 43 | * 参与签名的字段包括noncestr(随机字符串), 有效的jsapi_ticket, timestamp(时间戳), 44 | * url(当前网页的URL,不包含#及其后面部分)。 45 | * 46 | * 对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序)后,使用URL键值对的格式,拼接成字符串string1 47 | * 48 | * 这里需要注意的是所有参数名均为小写字符。 49 | * 50 | * 对string1进行sha1签名,得到signature, 字段名和字段值都采用原始值,不进行URL 转义。 51 | * 52 | * @param jsapi_ticket 微信JS接口的临时票据 53 | * @param noncestr 随机字符串 54 | * @param timestamp 时间戳 55 | * @param url 调用的页面Url,包括?后的部分 56 | * @return 成功返回授权签名,否则返回空 57 | */ 58 | public static String getSignature(String jsapi_ticket, String noncestr, String timestamp, String url) { 59 | Map params = new HashMap(); 60 | params.put("jsapi_ticket", jsapi_ticket); 61 | params.put("noncestr", noncestr); 62 | params.put("timestamp", timestamp); 63 | params.put("url", url); 64 | //1.1 对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序) 65 | Map sortParams = MapUtil.sortAsc(params); 66 | //1.2 使用URL键值对的格式拼接成字符串 67 | String string1 = MapUtil.mapJoin(sortParams, false); 68 | try { 69 | //2 对string1进行sha1签名 70 | return DigestUtils.sha1Hex(string1.getBytes("UTF-8")); 71 | } catch (UnsupportedEncodingException e) { 72 | } 73 | return ""; 74 | } 75 | 76 | /** 77 | * getBrandWCPayRequest签名 78 | * 79 | * @param map 待签名参数 80 | * @param mchKey 商户密钥 81 | * @return 签名paySign 82 | */ 83 | public static String getSign(Map map, String mchKey) { 84 | //1.1 对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序) 85 | Map sortParams = MapUtil.sortAsc(map); 86 | //1.2 使用URL键值对的格式 87 | String string1 = MapUtil.mapJoin(sortParams, false); 88 | if (Configuration.isDebug()) { 89 | System.out.println("#1.生成字符串:"); 90 | System.out.println(string1); 91 | } 92 | //拼接签名字符串 93 | String stringSignTemp = string1 + "&key=" + mchKey; 94 | if (Configuration.isDebug()) { 95 | System.out.println("#2.连接商户key:"); 96 | System.out.println(stringSignTemp); 97 | } 98 | //2.对string1进行MD5签名 99 | String sign = DigestUtils.md5Hex(stringSignTemp).toUpperCase(); 100 | if (Configuration.isDebug()) { 101 | System.out.println("#3.md5编码并转成大写:"); 102 | System.out.println("sign=" + sign); 103 | } 104 | return sign; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/org/weixin4j/component/MaterialComponent.java: -------------------------------------------------------------------------------- 1 | package org.weixin4j.component; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.util.Date; 7 | import org.apache.commons.lang.WordUtils; 8 | import org.weixin4j.Configuration; 9 | import org.weixin4j.Weixin; 10 | import org.weixin4j.WeixinException; 11 | import org.weixin4j.http.HttpClient; 12 | import org.weixin4j.http.HttpsClient; 13 | import org.weixin4j.model.material.Media; 14 | import org.weixin4j.model.media.Attachment; 15 | import org.weixin4j.model.message.MediaType; 16 | 17 | /** 18 | * 素材组件 19 | * 20 | * @author yangqisheng 21 | * @since 0.1.0 22 | */ 23 | public class MaterialComponent extends AbstractComponent { 24 | 25 | public MaterialComponent(Weixin weixin) { 26 | super(weixin); 27 | } 28 | 29 | /** 30 | * 新增临时素材 31 | * 32 | * @param mediaType 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb) 33 | * @param file form-data中媒体文件标识,有filename、filelength、content-type等信息 34 | * @return 上传成功返回素材Id,否则返回null 35 | * @throws org.weixin4j.WeixinException 微信操作异常 36 | * @since 0.1.4 37 | */ 38 | public Media upload(MediaType mediaType, File file) throws WeixinException { 39 | //创建请求对象 40 | HttpsClient http = new HttpsClient(); 41 | //上传素材,返回JSON数据包 42 | String jsonStr = http.uploadHttps("https://api.weixin.qq.com/cgi-bin/media/upload?access_token=" + weixin.getToken().getAccess_token() + "&type=" + mediaType.toString(), file); 43 | JSONObject jsonObj = JSONObject.parseObject(jsonStr); 44 | if (jsonObj != null) { 45 | if (Configuration.isDebug()) { 46 | System.out.println("新增临时素材返回json:" + jsonObj.toString()); 47 | } 48 | Object errcode = jsonObj.get("errcode"); 49 | if (errcode != null && !errcode.toString().equals("0")) { 50 | //返回异常信息 51 | throw new WeixinException(getCause(jsonObj.getIntValue("errcode"))); 52 | } else { 53 | //转换为Media对象 54 | Media media = new Media(); 55 | media.setMediaType(MediaType.valueOf(WordUtils.capitalize(jsonObj.getString("type")))); 56 | media.setMediaId(jsonObj.getString("media_id")); 57 | //转换为毫秒数 58 | long time = jsonObj.getLongValue("created_at") * 1000L; 59 | media.setCreatedAt(new Date(time)); 60 | //返回多媒体文件id 61 | return media; 62 | } 63 | } 64 | return null; 65 | } 66 | 67 | /** 68 | * 获取临时素材(不支持视频) 69 | * 70 | *

71 | * 本接口即为原“下载多媒体文件”接口。 72 | *

73 | * 74 | * @param mediaId 媒体文件ID 75 | * @return 正确返回附件对象,否则返回null 76 | * @throws org.weixin4j.WeixinException 微信操作异常 77 | */ 78 | public Attachment get(String mediaId) throws WeixinException { 79 | //下载资源 80 | String url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=" + weixin.getToken().getAccess_token() + "&media_id=" + mediaId; 81 | //创建请求对象 82 | HttpsClient http = new HttpsClient(); 83 | return http.downloadHttps(url); 84 | } 85 | 86 | /** 87 | * 高清语音素材获取接口 88 | * 89 | *

90 | * 可以使用本接口获取从JSSDK的uploadVoice接口上传的临时语音素材,格式为speex,16K采样率。 91 | *

92 | * 93 | * @param mediaId 媒体文件ID 94 | * @return 正确返回附件对象,否则返回null 95 | * @throws org.weixin4j.WeixinException 微信操作异常 96 | */ 97 | public Attachment getJssdkVoice(String mediaId) throws WeixinException { 98 | //下载资源 99 | String url = "https://api.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=" + weixin.getToken().getAccess_token() + "&media_id=" + mediaId; 100 | //创建请求对象 101 | HttpsClient http = new HttpsClient(); 102 | return http.downloadHttps(url); 103 | } 104 | } 105 | --------------------------------------------------------------------------------