fixed bugs
This commit is contained in:
parent
735f897989
commit
b706f80cee
@ -41,14 +41,14 @@ public class WeixinAccount implements Serializable {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSecret() {
|
public String getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public void setSecret(String secret) {
|
public void setSecret(String secret) {
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import com.foxinmy.weixin4j.http.ContentType;
|
|||||||
* <p>
|
* <p>
|
||||||
* 企业号上传限制:</br> 图片(image):1MB,支持JPG格式</br>
|
* 企业号上传限制:</br> 图片(image):1MB,支持JPG格式</br>
|
||||||
* 语音(voice):2MB,播放长度不超过60s,支持AMR格式</br> 视频(video):10MB,支持MP4格式</br>
|
* 语音(voice):2MB,播放长度不超过60s,支持AMR格式</br> 视频(video):10MB,支持MP4格式</br>
|
||||||
* 普通文件(file):10MB</br>
|
* 普通文件(file):20MB</br>
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* <font color='red'>媒体文件在后台保存时间为3天,即3天后media_id失效</font>
|
* <font color='red'>媒体文件在后台保存时间为3天,即3天后media_id失效</font>
|
||||||
|
|||||||
@ -1,60 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.type;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* 消息类型
|
|
||||||
*
|
|
||||||
* @author jy.hu
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public enum MessageType {
|
|
||||||
/**
|
|
||||||
* 文字消息
|
|
||||||
*
|
|
||||||
* @see com.foxinmy.weixin4j.msg.TextMessage
|
|
||||||
*/
|
|
||||||
text,
|
|
||||||
/**
|
|
||||||
* 图片消息
|
|
||||||
*
|
|
||||||
* @see com.foxinmy.weixin4j.msg.ImageMessage
|
|
||||||
*/
|
|
||||||
image,
|
|
||||||
/**
|
|
||||||
* 语音消息
|
|
||||||
*
|
|
||||||
* @see com.foxinmy.weixin4j.msg.VoiceMessage
|
|
||||||
*/
|
|
||||||
voice,
|
|
||||||
/**
|
|
||||||
* 视频消息
|
|
||||||
*
|
|
||||||
* @see com.foxinmy.weixin4j.msg.VideoMessage
|
|
||||||
*/
|
|
||||||
video,
|
|
||||||
/**
|
|
||||||
* 小视频消息
|
|
||||||
*
|
|
||||||
* @see com.foxinmy.weixin4j.msg.VideoMessage
|
|
||||||
*/
|
|
||||||
shortvideo,
|
|
||||||
/**
|
|
||||||
* 位置消息
|
|
||||||
*
|
|
||||||
* @see com.foxinmy.weixin4j.msg.LocationMessage
|
|
||||||
*/
|
|
||||||
location,
|
|
||||||
/**
|
|
||||||
* 链接消息
|
|
||||||
*
|
|
||||||
* @see com.foxinmy.weixin4j.msg.LinkMessage
|
|
||||||
*/
|
|
||||||
link,
|
|
||||||
/**
|
|
||||||
* 事件消息
|
|
||||||
*
|
|
||||||
* @see com.foxinmy.weixin4j.msg.event.EventMessage
|
|
||||||
*/
|
|
||||||
event;
|
|
||||||
}
|
|
||||||
@ -4,7 +4,6 @@ import java.io.Serializable;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据统计:消息发送概况数据
|
* 数据统计:消息发送概况数据
|
||||||
@ -61,19 +60,23 @@ public class UpstreamMsg implements Serializable {
|
|||||||
this.refHour = refHour;
|
this.refHour = refHour;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageType getMsgType() {
|
/**
|
||||||
// 1代表文字 2代表图片 3代表语音 4代表视频 6代表第三方应用消息(链接消息)
|
* 1代表文字 2代表图片 3代表语音 4代表视频 6代表第三方应用消息(链接消息)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getMsgType() {
|
||||||
switch (msgType) {
|
switch (msgType) {
|
||||||
case 1:
|
case 1:
|
||||||
return MessageType.text;
|
return "text";
|
||||||
case 2:
|
case 2:
|
||||||
return MessageType.image;
|
return "image";
|
||||||
case 3:
|
case 3:
|
||||||
return MessageType.voice;
|
return "voice";
|
||||||
case 4:
|
case 4:
|
||||||
return MessageType.video;
|
return "video";
|
||||||
case 6:
|
case 6:
|
||||||
return MessageType.link;
|
return "link";
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -487,7 +487,7 @@ public class WeixinProxy {
|
|||||||
/**
|
/**
|
||||||
* 获取部门成员
|
* 获取部门成员
|
||||||
*
|
*
|
||||||
* @param partyId
|
* @param departId
|
||||||
* 部门ID 必须
|
* 部门ID 必须
|
||||||
* @param fetchChild
|
* @param fetchChild
|
||||||
* 是否递归获取子部门下面的成员 非必须
|
* 是否递归获取子部门下面的成员 非必须
|
||||||
@ -502,9 +502,9 @@ public class WeixinProxy {
|
|||||||
* @return 成员列表
|
* @return 成员列表
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public List<User> listUser(int partyId, boolean fetchChild,
|
public List<User> listUser(int departId, boolean fetchChild,
|
||||||
UserStatus userStatus, boolean findDetail) throws WeixinException {
|
UserStatus userStatus, boolean findDetail) throws WeixinException {
|
||||||
return userApi.listUser(partyId, fetchChild, userStatus, findDetail);
|
return userApi.listUser(departId, fetchChild, userStatus, findDetail);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -221,7 +221,7 @@ public class UserApi extends QyApi {
|
|||||||
/**
|
/**
|
||||||
* 获取部门成员
|
* 获取部门成员
|
||||||
*
|
*
|
||||||
* @param departId
|
* @param partyId
|
||||||
* 部门ID 必须
|
* 部门ID 必须
|
||||||
* @param fetchChild
|
* @param fetchChild
|
||||||
* 是否递归获取子部门下面的成员 非必须
|
* 是否递归获取子部门下面的成员 非必须
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public class OUserInfo implements Serializable {
|
|||||||
* 登陆管理员信息
|
* 登陆管理员信息
|
||||||
*/
|
*/
|
||||||
@JSONField(name = "user_info")
|
@JSONField(name = "user_info")
|
||||||
private User userInfo;
|
private User adminInfo;
|
||||||
/**
|
/**
|
||||||
* 授权方企业信息
|
* 授权方企业信息
|
||||||
*/
|
*/
|
||||||
@ -65,12 +65,12 @@ public class OUserInfo implements Serializable {
|
|||||||
this.isInnerAdmin = isInnerAdmin;
|
this.isInnerAdmin = isInnerAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUserInfo() {
|
public User getAdminInfo() {
|
||||||
return userInfo;
|
return adminInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserInfo(User userInfo) {
|
public void setAdminInfo(User adminInfo) {
|
||||||
this.userInfo = userInfo;
|
this.adminInfo = adminInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Corpinfo getCorpinfo() {
|
public Corpinfo getCorpinfo() {
|
||||||
@ -100,7 +100,7 @@ public class OUserInfo implements Serializable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "OUserInfo [isSysAdmin=" + isSysAdmin + ", isInnerAdmin="
|
return "OUserInfo [isSysAdmin=" + isSysAdmin + ", isInnerAdmin="
|
||||||
+ isInnerAdmin + ", userInfo=" + userInfo + ", corpinfo="
|
+ isInnerAdmin + ", adminInfo=" + adminInfo + ", corpinfo="
|
||||||
+ corpinfo + ", agentInfo=" + agentInfo + ", authInfo="
|
+ corpinfo + ", agentInfo=" + agentInfo + ", authInfo="
|
||||||
+ authInfo + "]";
|
+ authInfo + "]";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,9 +14,11 @@ import com.foxinmy.weixin4j.model.WeixinAccount;
|
|||||||
* >企业号设置</a>
|
* >企业号设置</a>
|
||||||
*/
|
*/
|
||||||
public class WeixinQyAccount extends WeixinAccount {
|
public class WeixinQyAccount extends WeixinAccount {
|
||||||
|
|
||||||
private static final long serialVersionUID = 3689999353867189585L;
|
private static final long serialVersionUID = 3689999353867189585L;
|
||||||
|
|
||||||
public WeixinQyAccount() {
|
public WeixinQyAccount(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -178,9 +178,16 @@ public class WeixinMessageDispatcher {
|
|||||||
protected void noHandlerFound(ChannelHandlerContext context,
|
protected void noHandlerFound(ChannelHandlerContext context,
|
||||||
WeixinRequest request, Object message) {
|
WeixinRequest request, Object message) {
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
|
if (message instanceof String) {
|
||||||
context.writeAndFlush(
|
context.writeAndFlush(
|
||||||
new TextResponse(request.getOriginalContent()))
|
new TextResponse(request.getOriginalContent()
|
||||||
|
.replaceAll("\\!\\[CDATA\\[", "")
|
||||||
|
.replaceAll("\\]\\]", ""))).addListener(
|
||||||
|
ChannelFutureListener.CLOSE);
|
||||||
|
} else {
|
||||||
|
context.writeAndFlush(new TextResponse(message.toString()))
|
||||||
.addListener(ChannelFutureListener.CLOSE);
|
.addListener(ChannelFutureListener.CLOSE);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
context.writeAndFlush(
|
context.writeAndFlush(
|
||||||
HttpUtil.createHttpResponse(null, NOT_FOUND, null))
|
HttpUtil.createHttpResponse(null, NOT_FOUND, null))
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import com.foxinmy.weixin4j.util.Consts;
|
|||||||
import com.foxinmy.weixin4j.util.HttpUtil;
|
import com.foxinmy.weixin4j.util.HttpUtil;
|
||||||
import com.foxinmy.weixin4j.util.MessageUtil;
|
import com.foxinmy.weixin4j.util.MessageUtil;
|
||||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||||
import com.foxinmy.weixin4j.util.StringUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信回复编码类
|
* 微信回复编码类
|
||||||
@ -53,8 +52,7 @@ public class WeixinResponseEncoder extends
|
|||||||
messageTransfer.getFromUserName()));
|
messageTransfer.getFromUserName()));
|
||||||
content.append(String.format(
|
content.append(String.format(
|
||||||
"<FromUserName><![CDATA[%s]]></FromUserName>",
|
"<FromUserName><![CDATA[%s]]></FromUserName>",
|
||||||
StringUtil.isBlank(aesToken.getWeixinId()) ? messageTransfer
|
messageTransfer.getToUserName()));
|
||||||
.getToUserName() : aesToken.getWeixinId()));
|
|
||||||
content.append(String.format(
|
content.append(String.format(
|
||||||
"<CreateTime><![CDATA[%d]]></CreateTime>",
|
"<CreateTime><![CDATA[%d]]></CreateTime>",
|
||||||
System.currentTimeMillis() / 1000l));
|
System.currentTimeMillis() / 1000l));
|
||||||
@ -64,8 +62,8 @@ public class WeixinResponseEncoder extends
|
|||||||
content.append("</xml>");
|
content.append("</xml>");
|
||||||
if (encryptType == EncryptType.AES) {
|
if (encryptType == EncryptType.AES) {
|
||||||
String nonce = RandomUtil.generateString(32);
|
String nonce = RandomUtil.generateString(32);
|
||||||
String timestamp = String
|
String timestamp = Long
|
||||||
.valueOf(System.currentTimeMillis() / 1000l);
|
.toString(System.currentTimeMillis() / 1000l);
|
||||||
String encrtypt = MessageUtil.aesEncrypt(
|
String encrtypt = MessageUtil.aesEncrypt(
|
||||||
aesToken.getWeixinId(), aesToken.getAesKey(),
|
aesToken.getWeixinId(), aesToken.getAesKey(),
|
||||||
content.toString());
|
content.toString());
|
||||||
|
|||||||
@ -77,23 +77,24 @@ public final class WeixinServerBootstrap {
|
|||||||
private final Map<String, AesToken> aesTokenMap;
|
private final Map<String, AesToken> aesTokenMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* 明文模式
|
* 明文模式
|
||||||
*
|
*
|
||||||
* @param openid
|
* @param weixinid
|
||||||
* 微信号(原始ID)
|
* 微信号(原始ID)或者appid
|
||||||
* @param token
|
* @param token
|
||||||
* 开发者token
|
* 开发者token
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public WeixinServerBootstrap(String openid, String token) {
|
public WeixinServerBootstrap(String weixinid, String token) {
|
||||||
this(openid, token, null);
|
this(weixinid, token, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 兼容模式 & 密文模式
|
* 兼容模式 & 密文模式
|
||||||
*
|
*
|
||||||
* @param appid
|
* @param appid
|
||||||
* 公众号的唯一ID
|
* 公众号的appid
|
||||||
* @param token
|
* @param token
|
||||||
* 开发者填写的token
|
* 开发者填写的token
|
||||||
* @param aesKey
|
* @param aesKey
|
||||||
|
|||||||
@ -67,4 +67,10 @@ public class AesToken implements Serializable, Cloneable {
|
|||||||
public String getAesKey() {
|
public String getAesKey() {
|
||||||
return aesKey;
|
return aesKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "AesToken [weixinId=" + weixinId + ", token=" + token
|
||||||
|
+ ", aesKey=" + aesKey + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,6 @@ public final class Base64 {
|
|||||||
|
|
||||||
public static String encodeBase64String(final byte[] bytes) {
|
public static String encodeBase64String(final byte[] bytes) {
|
||||||
byte[] data = encodeBase64(bytes);
|
byte[] data = encodeBase64(bytes);
|
||||||
return HexUtil.encodeHexString(data);
|
return StringUtil.newStringUtf8(data).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public final class MessageUtil {
|
|||||||
*/
|
*/
|
||||||
public static String signature(String... para) {
|
public static String signature(String... para) {
|
||||||
Arrays.sort(para);
|
Arrays.sort(para);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (String str : para) {
|
for (String str : para) {
|
||||||
sb.append(str);
|
sb.append(str);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ public final class MessageUtil {
|
|||||||
public static String aesEncrypt(String appId, String encodingAesKey,
|
public static String aesEncrypt(String appId, String encodingAesKey,
|
||||||
String xmlContent) throws WeixinException {
|
String xmlContent) throws WeixinException {
|
||||||
byte[] randomBytes = StringUtil.getBytesUtf8(RandomUtil
|
byte[] randomBytes = StringUtil.getBytesUtf8(RandomUtil
|
||||||
.generateString(16));
|
.generateString(32));
|
||||||
byte[] xmlBytes = StringUtil.getBytesUtf8(xmlContent);
|
byte[] xmlBytes = StringUtil.getBytesUtf8(xmlContent);
|
||||||
int xmlLength = xmlBytes.length;
|
int xmlLength = xmlBytes.length;
|
||||||
byte[] orderBytes = new byte[4];
|
byte[] orderBytes = new byte[4];
|
||||||
@ -64,6 +64,7 @@ public final class MessageUtil {
|
|||||||
orderBytes[1] = (byte) (xmlLength >> 16 & 0xFF);
|
orderBytes[1] = (byte) (xmlLength >> 16 & 0xFF);
|
||||||
orderBytes[0] = (byte) (xmlLength >> 24 & 0xFF);
|
orderBytes[0] = (byte) (xmlLength >> 24 & 0xFF);
|
||||||
byte[] appidBytes = StringUtil.getBytesUtf8(appId);
|
byte[] appidBytes = StringUtil.getBytesUtf8(appId);
|
||||||
|
|
||||||
int byteLength = randomBytes.length + xmlLength + orderBytes.length
|
int byteLength = randomBytes.length + xmlLength + orderBytes.length
|
||||||
+ appidBytes.length;
|
+ appidBytes.length;
|
||||||
// ... + pad: 使用自定义的填充方式对明文进行补位填充
|
// ... + pad: 使用自定义的填充方式对明文进行补位填充
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user