fixed bugs

This commit is contained in:
jinyu 2015-06-29 17:03:29 +08:00
parent 735f897989
commit b706f80cee
14 changed files with 59 additions and 101 deletions

View File

@ -41,14 +41,14 @@ public class WeixinAccount implements Serializable {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSecret() {
return secret;
}
public void setId(String id) {
this.id = id;
}
public void setSecret(String secret) {
this.secret = secret;
}

View File

@ -12,7 +12,7 @@ import com.foxinmy.weixin4j.http.ContentType;
* <p>
* 企业号上传限制:</br> 图片image:1MB支持JPG格式</br>
* 语音voice2MB播放长度不超过60s支持AMR格式</br> 视频video10MB支持MP4格式</br>
* 普通文件file10MB</br>
* 普通文件file20MB</br>
* </p>
* <p>
* <font color='red'>媒体文件在后台保存时间为3天,即3天后media_id失效</font>

View File

@ -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;
}

View File

@ -4,7 +4,6 @@ import java.io.Serializable;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 数据统计:消息发送概况数据
@ -61,19 +60,23 @@ public class UpstreamMsg implements Serializable {
this.refHour = refHour;
}
public MessageType getMsgType() {
// 1代表文字 2代表图片 3代表语音 4代表视频 6代表第三方应用消息链接消息
/**
* 1代表文字 2代表图片 3代表语音 4代表视频 6代表第三方应用消息链接消息
*
* @return
*/
public String getMsgType() {
switch (msgType) {
case 1:
return MessageType.text;
return "text";
case 2:
return MessageType.image;
return "image";
case 3:
return MessageType.voice;
return "voice";
case 4:
return MessageType.video;
return "video";
case 6:
return MessageType.link;
return "link";
default:
return null;
}

View File

@ -487,7 +487,7 @@ public class WeixinProxy {
/**
* 获取部门成员
*
* @param partyId
* @param departId
* 部门ID 必须
* @param fetchChild
* 是否递归获取子部门下面的成员 非必须
@ -502,9 +502,9 @@ public class WeixinProxy {
* @return 成员列表
* @throws WeixinException
*/
public List<User> listUser(int partyId, boolean fetchChild,
public List<User> listUser(int departId, boolean fetchChild,
UserStatus userStatus, boolean findDetail) throws WeixinException {
return userApi.listUser(partyId, fetchChild, userStatus, findDetail);
return userApi.listUser(departId, fetchChild, userStatus, findDetail);
}
/**

View File

@ -221,7 +221,7 @@ public class UserApi extends QyApi {
/**
* 获取部门成员
*
* @param departId
* @param partyId
* 部门ID 必须
* @param fetchChild
* 是否递归获取子部门下面的成员 非必须

View File

@ -32,7 +32,7 @@ public class OUserInfo implements Serializable {
* 登陆管理员信息
*/
@JSONField(name = "user_info")
private User userInfo;
private User adminInfo;
/**
* 授权方企业信息
*/
@ -65,12 +65,12 @@ public class OUserInfo implements Serializable {
this.isInnerAdmin = isInnerAdmin;
}
public User getUserInfo() {
return userInfo;
public User getAdminInfo() {
return adminInfo;
}
public void setUserInfo(User userInfo) {
this.userInfo = userInfo;
public void setAdminInfo(User adminInfo) {
this.adminInfo = adminInfo;
}
public Corpinfo getCorpinfo() {
@ -100,7 +100,7 @@ public class OUserInfo implements Serializable {
@Override
public String toString() {
return "OUserInfo [isSysAdmin=" + isSysAdmin + ", isInnerAdmin="
+ isInnerAdmin + ", userInfo=" + userInfo + ", corpinfo="
+ isInnerAdmin + ", adminInfo=" + adminInfo + ", corpinfo="
+ corpinfo + ", agentInfo=" + agentInfo + ", authInfo="
+ authInfo + "]";
}

View File

@ -14,9 +14,11 @@ import com.foxinmy.weixin4j.model.WeixinAccount;
* >企业号设置</a>
*/
public class WeixinQyAccount extends WeixinAccount {
private static final long serialVersionUID = 3689999353867189585L;
public WeixinQyAccount(){
}
/**

View File

@ -178,9 +178,16 @@ public class WeixinMessageDispatcher {
protected void noHandlerFound(ChannelHandlerContext context,
WeixinRequest request, Object message) {
if (isDebug) {
if (message instanceof String) {
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);
}
} else {
context.writeAndFlush(
HttpUtil.createHttpResponse(null, NOT_FOUND, null))

View File

@ -17,7 +17,6 @@ import com.foxinmy.weixin4j.util.Consts;
import com.foxinmy.weixin4j.util.HttpUtil;
import com.foxinmy.weixin4j.util.MessageUtil;
import com.foxinmy.weixin4j.util.RandomUtil;
import com.foxinmy.weixin4j.util.StringUtil;
/**
* 微信回复编码类
@ -53,8 +52,7 @@ public class WeixinResponseEncoder extends
messageTransfer.getFromUserName()));
content.append(String.format(
"<FromUserName><![CDATA[%s]]></FromUserName>",
StringUtil.isBlank(aesToken.getWeixinId()) ? messageTransfer
.getToUserName() : aesToken.getWeixinId()));
messageTransfer.getToUserName()));
content.append(String.format(
"<CreateTime><![CDATA[%d]]></CreateTime>",
System.currentTimeMillis() / 1000l));
@ -64,8 +62,8 @@ public class WeixinResponseEncoder extends
content.append("</xml>");
if (encryptType == EncryptType.AES) {
String nonce = RandomUtil.generateString(32);
String timestamp = String
.valueOf(System.currentTimeMillis() / 1000l);
String timestamp = Long
.toString(System.currentTimeMillis() / 1000l);
String encrtypt = MessageUtil.aesEncrypt(
aesToken.getWeixinId(), aesToken.getAesKey(),
content.toString());

View File

@ -77,23 +77,24 @@ public final class WeixinServerBootstrap {
private final Map<String, AesToken> aesTokenMap;
/**
*
* 明文模式
*
* @param openid
* 微信号(原始ID)
* @param weixinid
* 微信号(原始ID)或者appid
* @param token
* 开发者token
*
*/
public WeixinServerBootstrap(String openid, String token) {
this(openid, token, null);
public WeixinServerBootstrap(String weixinid, String token) {
this(weixinid, token, null);
}
/**
* 兼容模式 & 密文模式
*
* @param appid
* 公众号的唯一ID
* 公众号的appid
* @param token
* 开发者填写的token
* @param aesKey

View File

@ -67,4 +67,10 @@ public class AesToken implements Serializable, Cloneable {
public String getAesKey() {
return aesKey;
}
@Override
public String toString() {
return "AesToken [weixinId=" + weixinId + ", token=" + token
+ ", aesKey=" + aesKey + "]";
}
}

View File

@ -39,6 +39,6 @@ public final class Base64 {
public static String encodeBase64String(final byte[] bytes) {
byte[] data = encodeBase64(bytes);
return HexUtil.encodeHexString(data);
return StringUtil.newStringUtf8(data).trim();
}
}

View File

@ -33,7 +33,7 @@ public final class MessageUtil {
*/
public static String signature(String... para) {
Arrays.sort(para);
StringBuilder sb = new StringBuilder();
StringBuffer sb = new StringBuffer();
for (String str : para) {
sb.append(str);
}
@ -55,7 +55,7 @@ public final class MessageUtil {
public static String aesEncrypt(String appId, String encodingAesKey,
String xmlContent) throws WeixinException {
byte[] randomBytes = StringUtil.getBytesUtf8(RandomUtil
.generateString(16));
.generateString(32));
byte[] xmlBytes = StringUtil.getBytesUtf8(xmlContent);
int xmlLength = xmlBytes.length;
byte[] orderBytes = new byte[4];
@ -64,6 +64,7 @@ public final class MessageUtil {
orderBytes[1] = (byte) (xmlLength >> 16 & 0xFF);
orderBytes[0] = (byte) (xmlLength >> 24 & 0xFF);
byte[] appidBytes = StringUtil.getBytesUtf8(appId);
int byteLength = randomBytes.length + xmlLength + orderBytes.length
+ appidBytes.length;
// ... + pad: 使用自定义的填充方式对明文进行补位填充