This commit is contained in:
jinyu 2015-12-29 16:28:30 +08:00
parent 92a847ecac
commit 1850b4fcdd
9 changed files with 109 additions and 18 deletions

View File

@ -151,7 +151,7 @@ public class HttpComponent3 extends AbstractHttpClient {
StringUtil.join(header.getValue(), ';'));
} else {
for (String headerValue : header.getValue()) {
httpMethod.addRequestHeader(header.getKey(),
httpMethod.setRequestHeader(header.getKey(),
headerValue != null ? headerValue : "");
}
}

View File

@ -82,11 +82,11 @@ public abstract class HttpComponent4 extends AbstractHttpClient {
.entrySet().iterator(); headerIterator.hasNext();) {
Entry<String, List<String>> header = headerIterator.next();
if (HttpHeaders.COOKIE.equalsIgnoreCase(header.getKey())) {
uriRequest.addHeader(header.getKey(),
uriRequest.setHeader(header.getKey(),
StringUtil.join(header.getValue(), ';'));
} else {
for (String headerValue : header.getValue()) {
uriRequest.addHeader(header.getKey(),
uriRequest.setHeader(header.getKey(),
headerValue != null ? headerValue : "");
}
}

View File

@ -181,7 +181,7 @@ public class Netty4HttpClient extends AbstractHttpClient {
for (Iterator<Entry<String, List<String>>> headerIterator = headers
.entrySet().iterator(); headerIterator.hasNext();) {
Entry<String, List<String>> header = headerIterator.next();
uriRequest.headers().add(header.getKey(), header.getValue());
uriRequest.headers().set(header.getKey(), header.getValue());
}
uriRequest.headers().set(HttpHeaders.CONNECTION,
io.netty.handler.codec.http.HttpHeaders.Values.CLOSE);

View File

@ -337,6 +337,14 @@
<code>40092</code>
<text>导入文件存在不合法的内容</text>
</error>
<error>
<code>40093</code>
<text>不合法的跳转target</text>
</error>
<error>
<code>40094</code>
<text>不合法的URL</text>
</error>
<error>
<code>40117</code>
<text>分组名字不合法</text>
@ -463,6 +471,14 @@
<code>41025</code>
<text>缺少永久授权码</text>
</error>
<error>
<code>41034</code>
<text>缺少login_ticket</text>
</error>
<error>
<code>41035</code>
<text>缺少跳转target</text>
</error>
<error>
<code>42001</code>
<desc>access_token expired</desc>
@ -821,6 +837,30 @@
<code>60017</code>
<text>不允许设置企业</text>
</error>
<error>
<code>60019</code>
<text>不允许设置应用地理位置上报开关</text>
</error>
<error>
<code>60020</code>
<text>访问ip不在白名单之中</text>
</error>
<error>
<code>60025</code>
<text>主页型应用不支持的消息类型</text>
</error>
<error>
<code>60027</code>
<text>主页型应用不支持调用该接口</text>
</error>
<error>
<code>60028</code>
<text>应用已授权予第三方不允许通过分级管理员主页url</text>
</error>
<error>
<code>60029</code>
<text>应用已授权予第三方,不允许通过分级管理员修改可信域名</text>
</error>
<error>
<code>60102</code>
<text>UserID已存在</text>

View File

@ -41,7 +41,7 @@ public class Token implements Serializable {
private String originalResult;
public Token() {
this.createTime = System.currentTimeMillis() / 1000l;
}
public Token(String accessToken) {

View File

@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Consts;
@ -35,7 +36,8 @@ public class OauthApi extends QyApi {
*/
public String getUserAuthorizeURL() {
String corpId = DEFAULT_WEIXIN_ACCOUNT.getId();
String redirectUri = Weixin4jConfigUtil.getValue("user.oauth.redirect.uri");
String redirectUri = Weixin4jConfigUtil
.getValue("user.oauth.redirect.uri");
return getUserAuthorizeURL(corpId, redirectUri, "state");
}
@ -73,7 +75,8 @@ public class OauthApi extends QyApi {
*/
public String getThirdAuthorizeURL() {
String corpId = DEFAULT_WEIXIN_ACCOUNT.getId();
String redirectUri = Weixin4jConfigUtil.getValue("third.oauth.redirect.uri");
String redirectUri = Weixin4jConfigUtil
.getValue("third.oauth.redirect.uri");
return getThirdAuthorizeURL(corpId, redirectUri, "state");
}
@ -121,7 +124,12 @@ public class OauthApi extends QyApi {
WeixinResponse response = weixinExecutor.post(
String.format(oauth_logininfo_uri, providerToken),
String.format("{\"auth_code\":\"%s\"}", authCode));
return JSON.parseObject(response.getAsString(), OUserInfo.class);
JSONObject obj = response.getAsJson();
OUserInfo oUser = JSON.toJavaObject(obj, OUserInfo.class);
oUser.getRedirectLoginInfo().setAccessToken(
obj.getJSONObject("redirect_login_info").getString(
"login_ticket"));
return oUser;
}
/**
@ -135,7 +143,8 @@ public class OauthApi extends QyApi {
* @return
*/
public String getSuiteAuthorizeURL(String suiteId, String preAuthCode) {
String redirectUri = Weixin4jConfigUtil.getValue("suite.oauth.redirect.uri");
String redirectUri = Weixin4jConfigUtil
.getValue("suite.oauth.redirect.uri");
return getSuiteAuthorizeURL(suiteId, preAuthCode, redirectUri, "state");
}

View File

@ -52,10 +52,15 @@ public class AgentSetter implements Serializable {
@JSONField(name = "isreportuser")
private boolean isReportUser;
/**
* 是否上报用户进入应用事件0不接收1接收
* 是否上报用户进入应用事件0不接收1接收主页型应用无需该参数
*/
@JSONField(name = "isreportenter")
private boolean isReportEnter;
/**
* 主页型应用urlurl必须以http或者https开头消息型应用无需该参数
*/
@JSONField(name = "home_url")
private String homeUrl;
public AgentSetter(int agentId) {
this.agentId = agentId;
@ -85,6 +90,10 @@ public class AgentSetter implements Serializable {
return redirectDomain;
}
public String getHomeUrl() {
return homeUrl;
}
// ---------- setter 应该全部去掉
public void setReportLocationType(ReportLocationType reportLocationType) {
@ -123,12 +132,17 @@ public class AgentSetter implements Serializable {
this.isReportEnter = isReportEnter;
}
public void setHomeUrl(String homeUrl) {
this.homeUrl = homeUrl;
}
@Override
public String toString() {
return "agentId=" + agentId + ", reportLocationType="
+ reportLocationType + ", logoMediaId=" + logoMediaId
+ ", name=" + name + ", description=" + description
+ ", redirectDomain=" + redirectDomain + ", isReportUser="
+ isReportUser + ", isReportEnter=" + isReportEnter;
+ isReportUser + ", isReportEnter=" + isReportEnter
+ ", homeUrl=" + homeUrl;
}
}

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.List;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.qy.type.AgentAuthType;
/**
@ -48,6 +49,11 @@ public class OUserInfo implements Serializable {
*/
@JSONField(name = "auth_info")
private AuthInfo authInfo;
/**
* 登录跳转的票据信息
*/
@JSONField(name = "redirect_login_info")
private Token redirectLoginInfo;
public boolean isSysAdmin() {
return isSysAdmin;
@ -73,6 +79,10 @@ public class OUserInfo implements Serializable {
return authInfo;
}
public Token getRedirectLoginInfo() {
return redirectLoginInfo;
}
// ---------- setter 应该全部去掉
public void setSysAdmin(boolean isSysAdmin) {
@ -99,12 +109,16 @@ public class OUserInfo implements Serializable {
this.authInfo = authInfo;
}
public void setRedirectLoginInfo(Token redirectLoginInfo) {
this.redirectLoginInfo = redirectLoginInfo;
}
@Override
public String toString() {
return "OUserInfo [isSysAdmin=" + isSysAdmin + ", isInnerAdmin="
+ isInnerAdmin + ", adminInfo=" + adminInfo + ", corpInfo="
+ corpInfo + ", agentInfo=" + agentInfo + ", authInfo="
+ authInfo + "]";
+ authInfo + ", redirectLoginInfo=" + redirectLoginInfo + "]";
}
/**

View File

@ -7,12 +7,14 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -150,8 +152,8 @@ public final class WeixinServerBootstrap {
this.aesTokenMap.put(aesToken.getWeixinId(), aesToken);
}
this.aesTokenMap.put(null, aesTokens[0]);
this.messageHandlerList = new LinkedList<WeixinMessageHandler>();
this.messageInterceptorList = new LinkedList<WeixinMessageInterceptor>();
this.messageHandlerList = new ArrayList<WeixinMessageHandler>();
this.messageInterceptorList = new ArrayList<WeixinMessageInterceptor>();
this.messageDispatcher = new WeixinMessageDispatcher(messageMatcher);
}
@ -183,7 +185,7 @@ public final class WeixinServerBootstrap {
* @return
* @throws WeixinException
*/
public void startup(int bossThreads, int workerThreads, int serverPort)
public void startup(int bossThreads, int workerThreads, final int serverPort)
throws WeixinException {
messageDispatcher.setMessageHandlerList(messageHandlerList);
messageDispatcher.setMessageInterceptorList(messageInterceptorList);
@ -199,8 +201,20 @@ public final class WeixinServerBootstrap {
.childHandler(
new WeixinServerInitializer(aesTokenMap,
messageDispatcher));
Channel ch = b.bind(serverPort).sync().channel();
logger.info("weixin4j server startup OK:{}", serverPort);
Channel ch = b.bind(serverPort)
.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future)
throws Exception {
if (future.isSuccess()) {
logger.info("weixin4j server startup OK:{}",
serverPort);
} else {
logger.info("weixin4j server startup FAIL:{}",
serverPort);
}
}
}).sync().channel();
ch.closeFuture().sync();
} catch (WeixinException e) {
throw e;