Git Product home page Git Product logo

wechat-group / wxjava Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chanjarster/weixin-java-tools

29.4K 29.4K 8.5K 16.43 MB

微信开发 Java SDK ,支持包括微信支付,开放平台,小程序,企业微信,视频号,公众号等的后端开发

License: Apache License 2.0

Java 100.00% Shell 0.01%
cp hacktoberfest java miniapp miniprogram mp open sdk weapp wechat wechat-sdk weixin weixin-sdk wxjava wxpay

wxjava's Issues

menuCreat()可能存在的问题

在实现类中的menuCreate(String agentId, WxMenu menu)方法中agentid 应该是传进来的agentId,而不是

  • this.configStorage.getAgentId();吧

@OverRide
public void menuCreate(WxMenu menu) throws WxErrorException {
menuCreate(this.configStorage.getAgentId(), menu);
}

@OverRide
public void menuCreate(String agentId, WxMenu menu) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid="

+ this.configStorage.getAgentId();

post(url, menu.toJson());

}

路由能提供个场景值的正则匹配吗?

需求:
假设,我有多个场景值。

newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_SUBSCRIBE).eventKey("qrscene_1234")
.interceptor(this.wxRegisterInterceptor).handler(this.msgHandler).next()
                .rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_SUBSCRIBE).eventKey("qrscene_4444")
.interceptor(this.wxRegisterInterceptor).handler(this.msgHandler).end()
                .rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_SUBSCRIBE).interceptor(this.wxRegisterInterceptor).handler(this.followHandler).end();

这样写好繁琐。
1.想像rContent 这样能匹配 并 统一处理带有场景值的匹配方式。
2.不太清楚这样写是否合理。
谢谢,你们提供 SDK。:)

生成200万个二维码,每个只能扫一次就会失效

具体的需求是:用户通过扫二维码,已关注的用户直接跳转到活动页面,未关注的用户会先跳转到关注页面,关注后也同样跳转到活动页面,是扫码后直接跳转页面!!!好像目前微信只能做到扫码后推送链接消息,再点击链接消息才能跳转到页面!!!还有被扫的二维码要求被扫了一次后就不能再使用!!!要200万个!!!我看了微信的带参永久二维码接口,最多只能10万个!!!并且同一个scene_id的情况下生成的二维码是一样的,我们需要的二维码是都不一样的!!!就算我只生成10万个不同scene_id的永久带参二维码(实际还是要200万个的),那我就要设置10万个不同的scene_id,并且每个scene_id还要写两种情况的事件拦截,一个是已关注的情况下,另一个是未关注的情况下,所以最后是要拦截20万个扫码事件。不可能真的这样去写20万个消息路由去拦截这10万个不同scene_id的扫码事件吧?各位有什么好的解决方法啊?@binarywang

1.3.4版本中对httpclient的增强导致timeout,wxcp的测试用例无法通过

ApacheHttpClientBuilder 新httpclient增强部分导致所有WxCPService 中的调用api服务失败,恢复使用原代码如下是能正常跑通的:
@OverRide
public void setWxConfigStorage(WxConfigStorage wxConfigProvider) {
this.wxConfigStorage = wxConfigProvider;

    String http_proxy_host = wxConfigStorage.getHttp_proxy_host();
    int http_proxy_port = wxConfigStorage.getHttp_proxy_port();
    String http_proxy_username = wxConfigStorage.getHttp_proxy_username();
    String http_proxy_password = wxConfigStorage.getHttp_proxy_password();

    if (StringUtils.isNotBlank(http_proxy_host)) {
        // 使用代理服务器
        if (StringUtils.isNotBlank(http_proxy_username)) {
            // 需要用户认证的代理服务器
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(http_proxy_host, http_proxy_port),
                    new UsernamePasswordCredentials(http_proxy_username, http_proxy_password));
            httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
        } else {
            // 无需用户认证的代理服务器
            httpClient = HttpClients.createDefault();
        }
        httpProxy = new HttpHost(http_proxy_host, http_proxy_port);
    } else {
        httpClient = HttpClients.createDefault();
    }
}

但是总感觉还是不太稳定,因为老版本的httpclient在我一个国外的服务器上执行execute GET request就会timeout

OSGI support

将jar包打包为标准的bundle,以支持OSGI

accessToken无效可能引起死循环

` protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
if (uri.indexOf("access_token=") != -1) {
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
}
String accessToken = getAccessToken(false);

String uriWithAccessToken = uri;
uriWithAccessToken += uri.indexOf('?') == -1 ? "?access_token=" + accessToken : "&access_token=" + accessToken;

try {
  return executor.execute(getHttpclient(), this.httpProxy,
      uriWithAccessToken, data);
} catch (WxErrorException e) {
  WxError error = e.getError();
  /*
   * 发生以下情况时尝试刷新access_token
   * 40001 获取access_token时AppSecret错误,或者access_token无效
   * 42001 access_token超时
   */
  if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) {
    // 强制设置wxCpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
    this.configStorage.expireAccessToken();
   //建议这里不循环调用,直接抛出异常,累计失败次数
    return execute(executor, uri, data);
  }
  if (error.getErrorCode() != 0) {
    throw new WxErrorException(error);
  }
  return null;
} catch (ClientProtocolException e) {
  throw new RuntimeException(e);
} catch (IOException e) {
  throw new RuntimeException(e);
}

}`

https问题PKIX path building failed

在使用普通模式发送消息时,只设置了corpid、corpsecret、agentid三个参数:
WxCpInMemoryConfigStorage config = new WxCpInMemoryConfigStorage();
config.setCorpId("..."); // 设置微信企业号的appid
config.setCorpSecret("..."); // 设置微信企业号的app corpSecret
config.setAgentId("0"); // 设置微信企业号应用ID
报错:
Exception in thread "main" java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at me.chanjar.weixin.cp.api.WxCpServiceImpl.getAccessToken(WxCpServiceImpl.java:128)

消息加密参数

首先,在处理微信通知消息时,报了这个错误:WARN RootController:186 - 加密消息签名校验失败
发现微信的 signature是用token,timestamp和noncestr三个参数计算的,与其文档里的说明并不一致。而我们的WxCryptUtl.decrypt方法内,是按照文档里实现的。

java.text.SimpleDateFormat 线程安全问题

java.text.SimpleDateFormat 内部是有状态的,并非线程安全。

SimpleDateFormat javadoc

Synchronization

Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.

org.apache.commons.lang3.time.FastDateFormat 才是线程安全的。

FastDateFormat javadoc

FastDateFormat is a fast and thread-safe version of SimpleDateFormat.
Since FastDateFormat is thread safe, you can use a static member instance:
private static final FastDateFormat DATE_FORMATTER = FastDateFormat.getDateTimeInstance(FastDateFormat.LONG, FastDateFormat.SHORT);
This class can be used as a direct replacement to SimpleDateFormat in most formatting and parsing situations. This class is especially useful in multi-threaded server environments. SimpleDateFormat is not thread-safe in any JDK version, nor will it be as Sun have closed the bug/RFE.

这个项目的依赖可以进一步简化

fluent-hc和jodd-http我看了下项目里没用到,可以去除,guava仅在一个地方用到了Lists.newArrayList,此处可以用jdk的List代替,至于joor,不知道能不能用jdk自身的反射代替

WxMpServiceImpl.executeInternal 方法阻塞导致服务器宕机的问题

目前方法的签名是这样的:

protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {...}

里边执行了一个超耗时的https的阻塞请求,直到微信官方网站返回了执行结果,才会结束这个方法。

所以,如果有多个线程通知执行 execute (然后 executeInternal),比如通过16个线程同时发送100万个模板消息,早晚都一定会发生一大堆线程阻塞在这个方法的起始处。

我们就遇到了这个情况,用 jstack 查看我们的 jvm 的线程状况,大部分都这样:
"http-nio-8081-exec-188" #1201 daemon prio=5 os_prio=0 tid=0x00007f99f0498000 nid=0x4822 waiting for monitor entry [0x00007f99c6ef4000]
java.lang.Thread.State: BLOCKED (on object monitor)
at me.chanjar.weixin.mp.api.WxMpServiceImpl.executeInternal(WxMpServiceImpl.java:729)
- waiting to lock <0x00000000c7332ed8> (a me.chanjar.weixin.mp.api.impl.WxMpServiceImpl)
at me.chanjar.weixin.mp.api.WxMpServiceImpl.execute(WxMpServiceImpl.java:705)

于是,整个jvm的线程数量耗尽,导致tomcat假死,服务器资源消耗基本为0。

所以我的问题如下:
1、这里的这个 synchronized 关键字为什么一定要加?
2、可以去掉不?
3、如果去掉,会导致什么严重问题?

感谢。

建议修改WxCpMessage 中agentId的数据类型

最新的企业微信已经推出,经测试,cp框架依然可用,但是这次微信对一些字段的类型做了check,原来agentId在转json中使用String型是不会出异常的,现在却会因为使用了“agentid”而抛出invalid input的错误,建议修改。已测试改成int过后,并不影响原有调用sendmessage的功能。

建议增加editorconfig文件统一代码格式化规则

由于本项目的缩进方式可能和别的项目方式不同,建议增加editorconfig文件适配本项目的格式化格式.
IntelliJ IDEA默认支持,Eclipse可以使用插件支持
别的项目中的一个例子

# EditorConfig: http://editorconfig.org/

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{java,py}]
indent_size = 4

[*.md]
trim_trailing_whitespace = false

DefaultApacheHttpClientBuilder.java 这个在实际生产环境中会导致大量的thread导致机器使用完线程死机

这是亲身经历。
prepare() 这个方法写的有问题,不停的加载创建thread,建议 构建方法中的配置等用静态提到构造函数中,我就这样解决的。

还有一个 路由的问题,路由方法也是 大量创建了thread,导致 thread只增加 不消除,我就直接把 thread取消了,就是那个 check duplicate 的吧,忘记了,如果不行 就用 线程池去做,不然不能用在生产环境中。很快机器就死

获取用户列表的同时,返回用户信息

userList()方法,目前只是返回了一些openid的信息,这样如果后台有需要展示这些用户信息的话,得

`WxMpUserList list = wxMpService.userList(null);

    List<String> openIdList = list.getOpenIds();

    List<WxMpUser> listUser = new ArrayList<WxMpUser>();
    WxMpUser user ;
    if(openIdList!=null&&openIdList.size()>0){
        for(String openId:openIdList){  
            user = wxMpService.userInfo(openId, "zh_CN");
            listUser.add(user);
        }
    }`

这样了,略微麻烦,希望新增一个接口,直接返回用户列表(带用户信息)并支持分页获取。

当支付成功或失败后没有给微信系统发送信息的接口

支付成功或失败后,没有相关的方法给微信(财付通)系统发送成功或失败的信息,导致连续接收5次回调的信息。

//给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
resHandler.sendToCFT("success");

//给财付通系统发送失败信息,财付通系统收到此结果后不再进行后续通知
resHandler.sendToCFT("fail");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.