提供了获取语音IdgetMediaId()等主要方法.
26 | * 提供了获取图片IdgetMediaId()等主要方法.
26 | * 通过Weixin产生一个请求对象,通过getUserTags()生成一个Tags,集合
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()等主要方法.
通过Weixin产生一个请求对象,通过getWeixinUser()生成一个WeixinUser,
26 | * 然后调用getUserList(),得到本对象.
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 | Map35 | * 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()等主要方法.
28 | * 提供了获取文本内容getContent()等主要方法.
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 | *
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提供了获取语音IdgetVoice()等主要方法.
29 | * 提供了获取图片IdgetMediaId()等主要方法.
29 | * 提供了获取视频IdgetMediaId()等主要方法.
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 | Map71 | * 本接口即为原“下载多媒体文件”接口。 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 | --------------------------------------------------------------------------------