foxinmy / weixin4j Goto Github PK
View Code? Open in Web Editor NEW(微信开发工具包)weixin sdk for Java
License: Other
(微信开发工具包)weixin sdk for Java
License: Other
您好!我有碰到如下Bug,也许对您有帮助。
Caused by: io.netty.channel.ChannelException: failed to open a new selector
at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:128)
at io.netty.channel.nio.NioEventLoop.(NioEventLoop.java:120)
at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:87)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:64)
... 51 more
Caused by: java.io.IOException: Too many open files
at sun.nio.ch.IOUtil.makePipe(Native Method)
at sun.nio.ch.EPollSelectorImpl.(EPollSelectorImpl.java:65)
at sun.nio.ch.EPollSelectorProvider.openSelector(EPollSelectorProvider.java:36)
at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:126)
... 54 more
java.lang.IllegalStateException: failed to create a child event loop
at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:68)
at io.netty.channel.MultithreadEventLoopGroup.(MultithreadEventLoopGroup.java:49)
at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:61)
at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:52)
at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:44)
at com.foxinmy.weixin4j.http.factory.Netty4HttpClientFactory.newInstance(Netty4HttpClientFactory.java:47)
at com.foxinmy.weixin4j.http.factory.HttpClientFactory.getInstance(HttpClientFactory.java:80)
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.(WeixinRequestExecutor.java:46)
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.(WeixinRequestExecutor.java:42)
at com.foxinmy.weixin4j.api.BaseApi.(BaseApi.java:31)
at com.foxinmy.weixin4j.mp.api.MpApi.(MpApi.java:17)
at com.foxinmy.weixin4j.mp.api.OauthApi.(OauthApi.java:26)
at com.caimei.hehe.controller.OauthController.oauth(OauthController.java:52)
at sun.reflect.GeneratedMethodAccessor1260.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: io.netty.channel.ChannelException: failed to open a new selector
at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:128)
at io.netty.channel.nio.NioEventLoop.(NioEventLoop.java:120)
at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:87)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:64)
... 51 more
此错误会导致服务器打开文件数过多,我服务器是centos6.5 的,windows对进程代开文件数貌似没有限制,linux对进程的打开文件数是有限制。所以隔一会就报错。
初步怀疑是使用NIO不当导致,没有深入研究您的源代码,说的不对,请原谅。
调用weixin.getUser("XXX");
Exception in thread "main" com.alibaba.fastjson.JSONException: com.foxinmy.weixin4j.qy.model.NameValue.<init>()
at com.alibaba.fastjson.util.TypeUtils.castToJavaBean(TypeUtils.java:872)
at com.alibaba.fastjson.util.TypeUtils.cast(TypeUtils.java:550)
at com.alibaba.fastjson.JSON.toJavaObject(JSON.java:701)
at com.foxinmy.weixin4j.qy.api.UserApi.getUser(UserApi.java:156)
at com.foxinmy.weixin4j.qy.WeixinProxy.getUser(WeixinProxy.java:615)
at com.xiaoleilu.ga.weixin.UserService.main(UserService.java:11)
Caused by: com.alibaba.fastjson.JSONException: com.foxinmy.weixin4j.qy.model.NameValue.<init>()
at com.alibaba.fastjson.util.TypeUtils.castToJavaBean(TypeUtils.java:872)
at com.alibaba.fastjson.util.TypeUtils.cast(TypeUtils.java:550)
at com.alibaba.fastjson.util.TypeUtils.cast(TypeUtils.java:560)
at com.alibaba.fastjson.util.TypeUtils.cast(TypeUtils.java:701)
at com.alibaba.fastjson.util.TypeUtils.castToJavaBean(TypeUtils.java:858)
... 5 more
Caused by: java.lang.NoSuchMethodException: com.foxinmy.weixin4j.qy.model.NameValue.<init>()
at java.lang.Class.getConstructor0(Class.java:2892)
at java.lang.Class.getDeclaredConstructor(Class.java:2058)
at com.alibaba.fastjson.util.TypeUtils.castToJavaBean(TypeUtils.java:843)
... 9 more
QY部分weixin.properties中的user_getid_uri应该是:
user_getid_uri={api_base_url}/user/getuserinfo?access_token=%s&code=%s&agentid=%d。
1.2版本中的代码是:
user_getid_uri={api_base_url}/getuserinfo?access_token=%s&code=%s&agentid=%d
能不能麻烦修正一下?谢谢!
上传永久视频,出现视频格式错误的bug。
2016-02-20 13:55:13,751 [main] DEBUG org.apache.http.wire[86] - http-outgoing-0 << "{"errcode":40113,"errmsg":"unsupported file type hint: [Ui6hia0676e292]"}"
问题原因:MediaAPI.uploadMaterialVideo() 方法中的media 上传文件的filename 没有后缀。
"Content-Disposition: form-data; name="media"; filename="56c7fec010fe409e83d9b9e7"[\r][\n]"
加上.mp4 后缀之后可以。
"Content-Disposition: form-data; name="media"; filename="56c7fec010fe409e83d9b9e7.mp4"[\r][\n]"
新手开发微信应用,感觉咱们的功能很强大,但是无从下手。
能不能有基于servlet或者springmvc的例子。
邮箱[email protected]如果有相关文档发一份,不胜感激
你好,我想问一下,现在的这个版本可以做多个微信公共账号一起管理吗?谢谢,我的qq:105242661,也可以加我一起聊聊。
1、其中使用netty,还是httpclient,还是simple 的,现在默认是netty,httpclient,simple 的 查找顺序;希望可以通过配置型选择使用哪一种 httpclient。
2、关于 connect time out 的问题,在我们测试的时候发现,在网络差的情况下,上传语音 or 视频的时候,经常会出现timeout 的问题,当我希望自定义 timeout 阀值 的时候,发现其很难自定义,且没有配置可言。如果有配置的话,也希望 上传 下载类的接口可以定义的时间长些;其他的json 的接口 定义的时间短些。
希望能尽快有解决方案。马上上线。。。
best wish for you
以下是过程日志:
[http-apr-8088-exec-4] INFO cn.macthink.map.web.controller.ActLotteryController - com.foxinmy.weixin4j.exception.WeixinException: com.foxinmy.weixin4j.http.HttpClientException: 400 Bad Request
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.doRequest(WeixinRequestExecutor.java:129)
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.get(WeixinRequestExecutor.java:52)
at com.foxinmy.weixin4j.mp.api.OauthApi.getOauthToken(OauthApi.java:89)
at cn.macthink.map.web.controller.ActLotteryController.index(ActLotteryController.java:106)
at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:55)
at cn.macthink.map.web.interceptor.ActLotteryStatusInterceptor.intercept(ActLotteryStatusInterceptor.java:60)
at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:51)
at cn.macthink.jfinalbase.ext.core.interceptor.ExceptionInterceptor.intercept(ExceptionInterceptor.java:37)
at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:51)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:77)
at cn.macthink.jfinalbase.ext.core.handler.xss.XssHandler.handle(XssHandler.java:19)
at cn.macthink.jfinalbase.ext.core.handler.SessionHandler.handle(SessionHandler.java:51)
at cn.macthink.map.web.handler.AppHandler.handle(AppHandler.java:21)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2463)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2452)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.foxinmy.weixin4j.http.HttpClientException: 400 Bad Request
at com.foxinmy.weixin4j.http.AbstractHttpClient.handleResponse(AbstractHttpClient.java:122)
at com.foxinmy.weixin4j.http.factory.HttpComponent4_2.execute(HttpComponent4_2.java:74)
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.doRequest(WeixinRequestExecutor.java:96)
... 34 more
微信media api upload 上传媒体 类型文件,使用httpclient4,经测试产生乱码。
我的代码执行顺序如下:
1.我自己的java类
OauthApi oauth = new OauthApi();
OauthToken ot = oauth.getOauthToken(code, WeixinUtil.appId, WeixinUtil.appSecret);
2.OauthApi类
protected final WeixinRequestExecutor weixinExecutor;
public BaseApi() {
this.weixinExecutor = new WeixinRequestExecutor();
}
public OauthToken getOauthToken(String code, String appid, String appsecret)
throws WeixinException {
String user_token_uri = getRequestUri("sns_user_token_uri");
WeixinResponse response = weixinExecutor.get(String.format(
user_token_uri, appid, appsecret, code));
return response.getAsObject(new TypeReference<OauthToken>() {
});
}
3.WeixinRequestExecutor类
public WeixinResponse get(String url) throws WeixinException {
HttpRequest request = new HttpRequest(HttpMethod.GET, url);
return doRequest(request);
}
public WeixinResponse doRequest(HttpRequest request) throws WeixinException {
request.setParams(params);
try {
HttpResponse httpResponse = httpClient.execute(request);
HttpHeaders headers = httpResponse.getHeaders();
WeixinResponse response = new WeixinResponse(httpResponse);
String contentType = headers.getFirst(HttpHeaders.CONTENT_TYPE);
String disposition = headers
.getFirst(HttpHeaders.CONTENT_DISPOSITION);
// json
if (contentType
.contains(ContentType.APPLICATION_JSON.getMimeType())
|| (disposition != null && disposition.indexOf(".json") > 0)) {
checkJson(response);
} else if (contentType.contains(ContentType.TEXT_XML.getMimeType())) {
checkXml(response);
} else if (contentType.contains(ContentType.TEXT_PLAIN
.getMimeType())
|| contentType
.contains(ContentType.TEXT_HTML.getMimeType())) {
try {
checkJson(response);
return response;
} catch (JSONException e) {
;
}
try {
checkXml(response);
return response;
} catch (IllegalArgumentException ex) {
;
}
throw new WeixinException(response.getAsString());
}
return response;
} catch (HttpClientException e) {
throw new WeixinException(e);
}
}
4.HttpComponent4_2类
public HttpResponse execute(HttpRequest request) throws HttpClientException {
HttpResponse response = null;
try {
HttpRequestBase uriRequest = methodMap.get(request.getMethod());
uriRequest.setURI(request.getURI());
boolean useSSL = "https".equals(request.getURI().getScheme());
SSLContext sslContext = null;
X509HostnameVerifier hostnameVerifier = null;
HttpParams params = request.getParams();
if (params != null) {
Builder requestConfig = RequestConfig.custom()
.setSocketTimeout(params.getSocketTimeout())
.setConnectTimeout(params.getConnectTimeout())
.setConnectionRequestTimeout(params.getReadTimeout());
if (params.getProxy() != null) {
InetSocketAddress socketAddress = (InetSocketAddress) params
.getProxy().address();
HttpHost proxy = new HttpHost(socketAddress.getHostName(),
socketAddress.getPort());
requestConfig.setProxy(proxy);
useSSL = false;
}
uriRequest.setConfig(requestConfig.build());
sslContext = params.getSSLContext();
hostnameVerifier = new CustomHostnameVerifier(
params.getHostnameVerifier());
}
if (useSSL) {
if (sslContext == null) {
sslContext = HttpClientFactory.allowSSLContext();
}
if (hostnameVerifier == null) {
hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
}
httpClient = HttpClients.custom()
.setHostnameVerifier(hostnameVerifier)
.setSslcontext(sslContext).build();
}
addHeaders(request.getHeaders(), uriRequest);
addEntity(request.getEntity(), uriRequest);
CloseableHttpResponse httpResponse = httpClient.execute(uriRequest);
response = new HttpComponent4_2Response(httpResponse,
getContent(httpResponse));
handleResponse(response);
} catch (IOException e) {
throw new HttpClientException("I/O error on "
+ request.getMethod().name() + " request for ""
+ request.getURI().toString() + "":" + e.getMessage(), e);
} finally {
if (response != null) {
response.close();
}
}
return response;
}
5.CustomHostnameVerifier
protected static class CustomHostnameVerifier implements
X509HostnameVerifier {
private final HostnameVerifier hostnameVerifier;
public CustomHostnameVerifier(HostnameVerifier hostnameVerifier) {
this.hostnameVerifier = hostnameVerifier;
}
@Override
public boolean verify(String hostname, SSLSession session) {
return hostnameVerifier.verify(hostname, session);
}
@Override
public void verify(String host, SSLSocket ssl) throws IOException {
}
@Override
public void verify(String host, X509Certificate cert)
throws SSLException {
}
@Override
public void verify(String host, String[] cns, String[] subjectAlts)
throws SSLException {
}
}
在第2步的时候,我们有new 一个WeixinRequestExecutor,看代码:
public WeixinRequestExecutor() {
this(new HttpParams());
}
我们接着new 了一个HttpParams,HttpParams中有一个属性:private HostnameVerifier hostnameVerifier; 上面new的时候没有赋值,导致第5步的public boolean verify(String hostname, SSLSession session) 执行时报空指针异常。
微信卡包感觉是个很有用的功能,对应的SDK什么时候能出来呢
ClassUtil!getClasses里用了url
fullPath.getPath() 是 file:/C:/Users/Administrator/workspace1/weixin4j-server/target/classes/com%5cfoxinmy%5cweixin4j%5cqy%5cevent
new File()不认啊..
weixin4j-server是一个独立的系统,但是如果要和现有的tomcat的系统集成,消息的处理要调用tomcat系统的函数,要如何来做
谢谢~
应该是Group类的count属性没有setCount(int count)方法导致的。
是漏了吗,还是有意为之?其他一些类也看到一些属性只有get方法没有set方法,如MpArticle的content属性。
在weixin4j.properties ,已经配置了 weixin4j.tokenStorager=RedisTokenStorager,但是系统获取到的依然是FileTokenStorager对象,如果想让其支持RedisTokenStorager,如何处理
该方法如果查询参数 MediaType 不为 news 则永远返回空。
代码如下:
WeixinResponse response = weixinExecutor.post(
String.format(material_media_list_uri, token.getAccessToken()),
obj.toJSONString());
obj = response.getAsJson();
MediaRecord mediaRecord = JSON.toJavaObject(obj, MediaRecord.class);
if (mediaType == MediaType.news) {
mediaRecord.setItems(JSON.parseArray(obj.getString("itemlist"),
MediaItem.class));
}
RT
比如:基本的入门使用方法
比如:微信介入
比如:回复信息
等等
如题,作者检查下。总是提示缺少agentId参数,原来是这个方法里没加进这个参数到obj里……
目前QY部分的WeixinProxy中没有getUserByCode接口。希望可以提供:User getUserByCode(String code)接口,因为微信服务器oauth调用之后返回的是code,而不是userid。
2015-12-29 14:48:49,863 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "User-Agent: apache/httpclient4[\r][\n]"
2015-12-29 14:48:49,863 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "Accept: /[\r][\n]"
2015-12-29 14:48:49,863 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "User-Agent: apache/httpclient4[\r][\n]"
2015-12-29 14:48:49,864 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "Accept: /[\r][\n]"
2015-12-29 14:48:49,864 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "User-Agent: apache/httpclient4[\r][\n]"
2015-12-29 14:48:49,864 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "Accept: /[\r][\n]"
2015-12-29 14:48:49,864 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "User-Agent: apache/httpclient4[\r][\n]"
2015-12-29 14:48:49,865 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "Content-Length: 129[\r][\n]"
2015-12-29 14:48:49,865 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "Content-Type: text/plain; charset=UTF-8[\r][\n]"
2015-12-29 14:48:49,865 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "Host: api.weixin.qq.com[\r][\n]"
2015-12-29 14:48:49,866 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "Connection: Keep-Alive[\r][\n]"
2015-12-29 14:48:49,866 [main] DEBUG org.apache.http.wire[72] - http-outgoing-3 >> "Accept-Encoding: gzip,deflate[\r][\n]"
无限加入:User-Agent 的信息。
MediaApi类
方法:public MediaDownloadResult downloadMedia(String mediaId, boolean isMaterial)
提交已失效的mediaId,没抛WeixinException
返回Filename mediaId.plain
内容为微信出错的JSON内容:
{"errcode":40007,"errmsg":"invalid media_id hint: [fnNMbA0216e298]"}
有时候因为各种其他的原因,可能让AccessToken提前失效,调用接口会出现40001错误,故建议提供手动刷新AccessToken的机制。
楼主,wx.getLocation这个接口有实现吗?
我看JSSDK中有描述,不过没找到相关实现和调用
配置weixin4j.properties token的路径后,例如:/tmp/token, 第一次接入微信后,会在token文件夹下产生一个token文件,之后,如果我把tmp或者token文件夹删掉后,会报“系统找不到指定的路径”,我直接把产生的token文件删掉,不会报这个错,会重新生成一个token缓存文件
public String[] massByOpenIds(MassTuple tuple, String... openIds)
throws WeixinException {
if (tuple instanceof MpNews) {
MpNews _news = (MpNews) tuple;
List _articles = _news.getArticles();
if (StringUtil.isBlank(_news.getMediaId())) {
if (_articles.isEmpty()) {
throw new WeixinException(
"mass fail:mediaId or articles is required");
}
tuple = new MpNews(uploadArticle(_articles));
}
}
哈哈哈
没有找到微信支付notify解析api,就是解析post回来的xml的,有没有例子可以看一下,谢谢。
服务包weixin4j-server能否提供servlet版本?
我有碰到如下错误,是否是因为我服务器没有配置 hostname ?
java.lang.NullPointerException
at com.foxinmy.weixin4j.http.factory.HttpComponent4$CustomHostnameVerifier.verify(HttpComponent4.java:123)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:461)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:395)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at com.foxinmy.weixin4j.http.factory.HttpComponent4_2.execute(HttpComponent4_2.java:81)
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.doRequest(WeixinRequestExecutor.java:96)
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.get(WeixinRequestExecutor.java:52)
at com.foxinmy.weixin4j.mp.api.OauthApi.getOauthToken(OauthApi.java:90)
at com.caimei.hehe.controller.OauthController.oauth(OauthController.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
PayUtil.createPrePay(PayPackageV3 payPackage) post后返回xml解释为json
需要在解释之前硬设置:
response.setJsonResult(false);
response.setXmlResult(true);
否则报错,将xml解释为json。
还有微信支付生成json后,在js调用时老是报签名错误,不知道是程序的问题,还是微信的问题。
https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5
退款查询接口,会包含每一笔退款的详细信息,但是在RefundRecord 的refundList 字段中,保存的仅仅有
out_refund_no_0 、out_refund_no_1 这些原始微信返回的字段信息缺失。
生成native支付时,如何生成product,没有找到api,里边的参数productId,是不是需要把订单包装成商品,有没有api可以生成,生成后,可不可以删除。
您好!1.6.6 有没有解决下面这个问题呢?
相似帖子:http://blog.csdn.net/zhang168/article/details/27567053
java 62953 root *310w FIFO 0,8 0t0 9630083 pipe
java 62953 root *311u REG 0,9 0 4158 [eventpoll]
java 62953 root *312r FIFO 0,8 0t0 9630084 pipe
java 62953 root *313w FIFO 0,8 0t0 9630084 pipe
java 62953 root *314u REG 0,9 0 4158 [eventpoll]
java 62953 root *315r FIFO 0,8 0t0 9630085 pipe
java 62953 root *316w FIFO 0,8 0t0 9630085 pipe
java 62953 root *317u REG 0,9 0 4158 [eventpoll]
java 62953 root *318r FIFO 0,8 0t0 9630086 pipe
java 62953 root *319w FIFO 0,8 0t0 9630086 pipe
java 62953 root *320u REG 0,9 0 4158 [eventpoll]
java 62953 root *321r FIFO 0,8 0t0 9630087 pipe
java 62953 root *322w FIFO 0,8 0t0 9630087 pipe
java 62953 root *323u REG 0,9 0 4158 [eventpoll]
java 62953 root *324r FIFO 0,8 0t0 9630088 pipe
java 62953 root *325w FIFO 0,8 0t0 9630088 pipe
java 62953 root *326u REG 0,9 0 4158 [eventpoll]
java 62953 root *327r FIFO 0,8 0t0 9630089 pipe
java 62953 root *328w FIFO 0,8 0t0 9630089 pipe
java 62953 root *329u REG 0,9 0 4158 [eventpoll]
java 62953 root *330r FIFO 0,8 0t0 9630090 pipe
java 62953 root *331w FIFO 0,8 0t0 9630090 pipe
java 62953 root *332u REG 0,9 0 4158 [eventpoll]
java 62953 root *333r FIFO 0,8 0t0 9630091 pipe
java 62953 root *334w FIFO 0,8 0t0 9630091 pipe
java 62953 root *335u REG 0,9 0 4158 [eventpoll]
java 62953 root *336r FIFO 0,8 0t0 9630092 pipe
java 62953 root *337w FIFO 0,8 0t0 9630092 pipe
java 62953 root *338u REG 0,9 0 4158 [eventpoll]
java 62953 root *339r FIFO 0,8 0t0 9630093 pipe
java 62953 root *340w FIFO 0,8 0t0 9630093 pipe
java 62953 root *341u REG 0,9 0 4158 [eventpoll]
java 62953 root *342r FIFO 0,8 0t0 9630094 pipe
java 62953 root *343w FIFO 0,8 0t0 9630094 pipe
java 62953 root *344u REG 0,9 0 4158 [eventpoll]
java 62953 root *345r FIFO 0,8 0t0 9630095 pipe
java 62953 root *346w FIFO 0,8 0t0 9630095 pipe
java 62953 root *347u REG 0,9 0 4158 [eventpoll]
java 62953 root *348r FIFO 0,8 0t0 9630096 pipe
java 62953 root *349w FIFO 0,8 0t0 9630096 pipe
java 62953 root *350u REG 0,9 0 4158 [eventpoll]
java 62953 root *351r FIFO 0,8 0t0 9630097 pipe
java 62953 root *352w FIFO 0,8 0t0 9630097 pipe
java 62953 root *353u REG 0,9 0 4158 [eventpoll]
java 62953 root *354r FIFO 0,8 0t0 9630098 pipe
java 62953 root *355w FIFO 0,8 0t0 9630098 pipe
java 62953 root *356u REG 0,9 0 4158 [eventpoll]
[root@caimei365web10 ~]# lsof -p 62953 | grep pipe | wc -l
14848
[root@caimei365web10 ~]# lsof -p 62953 | grep eventpoll | wc -l
7424
scene_id 场景值ID,临时二维码时为32位非0整型,该数值的最大值为:4294967295。这个值已经超出了 Integer 最大值。
java.lang.IllegalArgumentException: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXException: FWK005 parse may not be called while parsing.]
at com.foxinmy.weixin4j.xml.XmlStream.fromXML(XmlStream.java:87) ~[weixin4j-base-1.6.5.jar:na]
at com.foxinmy.weixin4j.token.FileTokenStorager.lookup(FileTokenStorager.java:34) ~[weixin4j-base-1.6.5.jar:na]
at com.foxinmy.weixin4j.token.FileTokenStorager.lookup(FileTokenStorager.java:20) ~[weixin4j-base-1.6.5.jar:na]
at com.foxinmy.weixin4j.token.TokenHolder.getToken(TokenHolder.java:47) ~[weixin4j-base-1.6.5.jar:na]
at com.foxinmy.weixin4j.qy.api.NotifyApi.sendNotifyMessage(NotifyApi.java:84) ~[weixin4j-qy-1.6.5.jar:na]
at com.foxinmy.weixin4j.qy.WeixinProxy.sendNotifyMessage(WeixinProxy.java:174) ~[weixin4j-qy-1.6.5.jar:na]
在批量推送消息的时候出现以上问题,每个推送一个线程。就会出现这个错误。5个消息成功3个,我查了下,线程问题。
文章在此,希望参考http://www.blogjava.net/wilesun/archive/2012/05/09/377723.html
我看你代码中Unmarshaller是单例的,可能引发这个问题。希望解决。
阿里云CentOS上OpenJDK的环境就不行。
[root@iZ25pwy5tqpZ logs]# java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (rhel-2.6.2.2.el6_7-x86_64 u91-b00)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
控制台报错如下
如果阿里云CentOS上 OpenJdk换成普通oracle jdk测试没有问题
[root@iZ25pwy5tqpZ ~]# java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Server VM (build 24.71-b01, mixed mode)
[root@iZ25pwy5tqpZ ~]#
作者 看能重代码上来处理吗??
我需不需要自己实现token的维护,还是当发现token过期时自动完成token的获取和缓存,我觉得这个点作者有必要特殊说明一下,因为毕竟token是请求的凭证。
如题
http://mp.weixin.qq.com/wiki/10/c7bad9a463db20ff8ccefeedeef51f9e.html
修改永久素材只能通过 ibdex 修改,并且提交的数据是一个图文项的具体内容,而不是一个list。
接口调用请求说明
http请求方式: POST
https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=ACCESS_TOKEN
调用示例
{
"media_id":MEDIA_ID,
"index":INDEX,
"articles": {
"title": TITLE,
"thumb_media_id": THUMB_MEDIA_ID,
"author": AUTHOR,
"digest": DIGEST,
"show_cover_pic": SHOW_COVER_PIC(0 / 1),
"content": CONTENT,
"content_source_url": CONTENT_SOURCE_URL
}
}
您好!我有碰到如下Bug,也许对您有帮助。
Caused by: io.netty.channel.ChannelException: failed to open a new selector
at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:128)
at io.netty.channel.nio.NioEventLoop.(NioEventLoop.java:120)
at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:87)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:64)
... 51 more
Caused by: java.io.IOException: Too many open files
at sun.nio.ch.IOUtil.makePipe(Native Method)
at sun.nio.ch.EPollSelectorImpl.(EPollSelectorImpl.java:65)
at sun.nio.ch.EPollSelectorProvider.openSelector(EPollSelectorProvider.java:36)
at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:126)
... 54 more
java.lang.IllegalStateException: failed to create a child event loop
at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:68)
at io.netty.channel.MultithreadEventLoopGroup.(MultithreadEventLoopGroup.java:49)
at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:61)
at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:52)
at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:44)
at com.foxinmy.weixin4j.http.factory.Netty4HttpClientFactory.newInstance(Netty4HttpClientFactory.java:47)
at com.foxinmy.weixin4j.http.factory.HttpClientFactory.getInstance(HttpClientFactory.java:80)
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.(WeixinRequestExecutor.java:46)
at com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor.(WeixinRequestExecutor.java:42)
at com.foxinmy.weixin4j.api.BaseApi.(BaseApi.java:31)
at com.foxinmy.weixin4j.mp.api.MpApi.(MpApi.java:17)
at com.foxinmy.weixin4j.mp.api.OauthApi.(OauthApi.java:26)
at com.caimei.hehe.controller.OauthController.oauth(OauthController.java:52)
at sun.reflect.GeneratedMethodAccessor1260.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: io.netty.channel.ChannelException: failed to open a new selector
at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:128)
at io.netty.channel.nio.NioEventLoop.(NioEventLoop.java:120)
at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:87)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:64)
... 51 more
我使用的版本是:1.6.5
此错误会导致服务器打开文件数过多,我服务器是centos6.5 的,windows对进程代开文件数貌似没有限制,linux对进程的打开文件数是有限制。所以隔一会就报错。
初步怀疑是使用NIO不当导致,没有深入研究您的源代码,说的不对,请原谅。
base的那个test...运行一次之后不关闭..不太懂nio这块...不需要关么..?
然后...我循环访问1w次 helloworld 界面....HttpComponent4Factory在5k左右报错..Netty4HttpClientFactory在4k左右报错
OauthApi类的getAuthorizeURL方法中的sns_user_auth_uri有误,应该使用user_auth_uri
WeiXin4JUtils.getWeixinProxy().downloadMedia(mediaId, false);
此方法下载媒体图片,为什么下载下来的Content-Type是text/plain? Content-disposition也是空,以至于MediaDownloadResult中获取到的文件名是XXXXXX.plain,应该是jpg或者jpeg格式的图片
我自己大概是这样写的,就可以正常获取:
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()).setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
HttpGet httpget = new HttpGet(URL);
CloseableHttpResponse response = null;
ContentBody reponseContentBody = null;
try {
httpget.setConfig(requestConfig);
response = httpClient.execute(httpget);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
return null;
}
String fileNameHeader = response.getHeaders("Content-disposition")[0].getValue();
//能正常获取到Content-disposition值,里面含有filename
} catch (Exception e) {
e.prin
clone你的框架 作为新人 觉得文档有些不足,不知道如何去入手。看了你的wiki还是有些不太明白。请问有没有一个入门简单demo
1、getFollowing 方法中 每次拉去一个user 的信息。可以改为getUsers(Lang lang, String... openIds) 每次批量拉取(最多一百个)。
2、建议再创建一个仅仅拉去openid的方法【当一个公众号的粉丝数量超过10000+,getFollowing 会拉去10000个User,并且这个是常驻内存的,对于应用来说,这是高耗内存的对象,不建议这样使用,getAllFollowing 会更恐怖】。
quick start 才拿到想快速入手,不知道从哪里入手 呢
创建个性化菜单,微信会将个性化菜单的menuId返回给用户,现在返回的结果却是空。
在单元测试中发现,仅仅判断了code值,并没有对JsonResult对象中的text属性做判断。
发送图文消息(点击跳转到图文消息页面) 图文消息条数限制在8条以内,注意,如果图文数超过8,则将会无响应。
{
"touser":"OPENID",
"msgtype":"mpnews",
"mpnews":
{
"media_id":"MEDIA_ID"
}
}
客服接口可以发送MPnews 了
public JsonResult sendNotify(NotifyMessage notify, String kfAccount)
throws WeixinException {
NotifyTuple tuple = notify.getTuple();
String msgtype = tuple.getMessageType();
if ("mpnews".equals(msgtype)) {
throw new WeixinException("only support news message");
}
JSONObject obj = new JSONObject();
obj.put("touser", notify.getTouser());
obj.put("msgtype", msgtype);
obj.put(msgtype, tuple);
if (StringUtil.isNotBlank(kfAccount)) {
JSONObject kf = new JSONObject();
kf.put("kf_account", kfAccount);
obj.put("customservice", kf);
}
所以这里可以不用抛出异常了。
你好:
在github 关注您的 weixin4j工具, 最近刚开始接触这块 正在学习。
在使用最新版本的工具过程中 直接初始化Weixin4jSuiteSettings,默认读取配置文件并将其转换成WeixinQyAccount实体时候,报空指针错误。
后续发现可能是WeixinQyAccount这个实体的代码中的问题,
将 /**
* 多个应用套件信息
*/
private List suiteAccounts 换成 suites 就可以了 是否我有什么地方出问题了 ? 新手学习 还望解答 ,多谢。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.