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(), ';')); StringUtil.join(header.getValue(), ';'));
} else { } else {
for (String headerValue : header.getValue()) { for (String headerValue : header.getValue()) {
httpMethod.addRequestHeader(header.getKey(), httpMethod.setRequestHeader(header.getKey(),
headerValue != null ? headerValue : ""); headerValue != null ? headerValue : "");
} }
} }

View File

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

View File

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

View File

@ -337,6 +337,14 @@
<code>40092</code> <code>40092</code>
<text>导入文件存在不合法的内容</text> <text>导入文件存在不合法的内容</text>
</error> </error>
<error>
<code>40093</code>
<text>不合法的跳转target</text>
</error>
<error>
<code>40094</code>
<text>不合法的URL</text>
</error>
<error> <error>
<code>40117</code> <code>40117</code>
<text>分组名字不合法</text> <text>分组名字不合法</text>
@ -463,6 +471,14 @@
<code>41025</code> <code>41025</code>
<text>缺少永久授权码</text> <text>缺少永久授权码</text>
</error> </error>
<error>
<code>41034</code>
<text>缺少login_ticket</text>
</error>
<error>
<code>41035</code>
<text>缺少跳转target</text>
</error>
<error> <error>
<code>42001</code> <code>42001</code>
<desc>access_token expired</desc> <desc>access_token expired</desc>
@ -821,6 +837,30 @@
<code>60017</code> <code>60017</code>
<text>不允许设置企业</text> <text>不允许设置企业</text>
</error> </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> <error>
<code>60102</code> <code>60102</code>
<text>UserID已存在</text> <text>UserID已存在</text>

View File

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

View File

@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException; import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse; import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Consts; import com.foxinmy.weixin4j.model.Consts;
@ -35,7 +36,8 @@ public class OauthApi extends QyApi {
*/ */
public String getUserAuthorizeURL() { public String getUserAuthorizeURL() {
String corpId = DEFAULT_WEIXIN_ACCOUNT.getId(); 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"); return getUserAuthorizeURL(corpId, redirectUri, "state");
} }
@ -73,7 +75,8 @@ public class OauthApi extends QyApi {
*/ */
public String getThirdAuthorizeURL() { public String getThirdAuthorizeURL() {
String corpId = DEFAULT_WEIXIN_ACCOUNT.getId(); 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"); return getThirdAuthorizeURL(corpId, redirectUri, "state");
} }
@ -121,7 +124,12 @@ public class OauthApi extends QyApi {
WeixinResponse response = weixinExecutor.post( WeixinResponse response = weixinExecutor.post(
String.format(oauth_logininfo_uri, providerToken), String.format(oauth_logininfo_uri, providerToken),
String.format("{\"auth_code\":\"%s\"}", authCode)); 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 * @return
*/ */
public String getSuiteAuthorizeURL(String suiteId, String preAuthCode) { 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"); return getSuiteAuthorizeURL(suiteId, preAuthCode, redirectUri, "state");
} }

View File

@ -52,10 +52,15 @@ public class AgentSetter implements Serializable {
@JSONField(name = "isreportuser") @JSONField(name = "isreportuser")
private boolean isReportUser; private boolean isReportUser;
/** /**
* 是否上报用户进入应用事件0不接收1接收 * 是否上报用户进入应用事件0不接收1接收主页型应用无需该参数
*/ */
@JSONField(name = "isreportenter") @JSONField(name = "isreportenter")
private boolean isReportEnter; private boolean isReportEnter;
/**
* 主页型应用urlurl必须以http或者https开头消息型应用无需该参数
*/
@JSONField(name = "home_url")
private String homeUrl;
public AgentSetter(int agentId) { public AgentSetter(int agentId) {
this.agentId = agentId; this.agentId = agentId;
@ -85,6 +90,10 @@ public class AgentSetter implements Serializable {
return redirectDomain; return redirectDomain;
} }
public String getHomeUrl() {
return homeUrl;
}
// ---------- setter 应该全部去掉 // ---------- setter 应该全部去掉
public void setReportLocationType(ReportLocationType reportLocationType) { public void setReportLocationType(ReportLocationType reportLocationType) {
@ -123,12 +132,17 @@ public class AgentSetter implements Serializable {
this.isReportEnter = isReportEnter; this.isReportEnter = isReportEnter;
} }
public void setHomeUrl(String homeUrl) {
this.homeUrl = homeUrl;
}
@Override @Override
public String toString() { public String toString() {
return "agentId=" + agentId + ", reportLocationType=" return "agentId=" + agentId + ", reportLocationType="
+ reportLocationType + ", logoMediaId=" + logoMediaId + reportLocationType + ", logoMediaId=" + logoMediaId
+ ", name=" + name + ", description=" + description + ", name=" + name + ", description=" + description
+ ", redirectDomain=" + redirectDomain + ", isReportUser=" + ", 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 java.util.List;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.qy.type.AgentAuthType; import com.foxinmy.weixin4j.qy.type.AgentAuthType;
/** /**
@ -48,6 +49,11 @@ public class OUserInfo implements Serializable {
*/ */
@JSONField(name = "auth_info") @JSONField(name = "auth_info")
private AuthInfo authInfo; private AuthInfo authInfo;
/**
* 登录跳转的票据信息
*/
@JSONField(name = "redirect_login_info")
private Token redirectLoginInfo;
public boolean isSysAdmin() { public boolean isSysAdmin() {
return isSysAdmin; return isSysAdmin;
@ -73,6 +79,10 @@ public class OUserInfo implements Serializable {
return authInfo; return authInfo;
} }
public Token getRedirectLoginInfo() {
return redirectLoginInfo;
}
// ---------- setter 应该全部去掉 // ---------- setter 应该全部去掉
public void setSysAdmin(boolean isSysAdmin) { public void setSysAdmin(boolean isSysAdmin) {
@ -99,12 +109,16 @@ public class OUserInfo implements Serializable {
this.authInfo = authInfo; this.authInfo = authInfo;
} }
public void setRedirectLoginInfo(Token redirectLoginInfo) {
this.redirectLoginInfo = redirectLoginInfo;
}
@Override @Override
public String toString() { public String toString() {
return "OUserInfo [isSysAdmin=" + isSysAdmin + ", isInnerAdmin=" return "OUserInfo [isSysAdmin=" + isSysAdmin + ", isInnerAdmin="
+ isInnerAdmin + ", adminInfo=" + adminInfo + ", corpInfo=" + isInnerAdmin + ", adminInfo=" + adminInfo + ", corpInfo="
+ corpInfo + ", agentInfo=" + agentInfo + ", authInfo=" + 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.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LoggingHandler; 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.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -150,8 +152,8 @@ public final class WeixinServerBootstrap {
this.aesTokenMap.put(aesToken.getWeixinId(), aesToken); this.aesTokenMap.put(aesToken.getWeixinId(), aesToken);
} }
this.aesTokenMap.put(null, aesTokens[0]); this.aesTokenMap.put(null, aesTokens[0]);
this.messageHandlerList = new LinkedList<WeixinMessageHandler>(); this.messageHandlerList = new ArrayList<WeixinMessageHandler>();
this.messageInterceptorList = new LinkedList<WeixinMessageInterceptor>(); this.messageInterceptorList = new ArrayList<WeixinMessageInterceptor>();
this.messageDispatcher = new WeixinMessageDispatcher(messageMatcher); this.messageDispatcher = new WeixinMessageDispatcher(messageMatcher);
} }
@ -183,7 +185,7 @@ public final class WeixinServerBootstrap {
* @return * @return
* @throws WeixinException * @throws WeixinException
*/ */
public void startup(int bossThreads, int workerThreads, int serverPort) public void startup(int bossThreads, int workerThreads, final int serverPort)
throws WeixinException { throws WeixinException {
messageDispatcher.setMessageHandlerList(messageHandlerList); messageDispatcher.setMessageHandlerList(messageHandlerList);
messageDispatcher.setMessageInterceptorList(messageInterceptorList); messageDispatcher.setMessageInterceptorList(messageInterceptorList);
@ -199,8 +201,20 @@ public final class WeixinServerBootstrap {
.childHandler( .childHandler(
new WeixinServerInitializer(aesTokenMap, new WeixinServerInitializer(aesTokenMap,
messageDispatcher)); messageDispatcher));
Channel ch = b.bind(serverPort).sync().channel(); Channel ch = b.bind(serverPort)
logger.info("weixin4j server startup OK:{}", 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(); ch.closeFuture().sync();
} catch (WeixinException e) { } catch (WeixinException e) {
throw e; throw e;