public WxClient with(AppSetting appSetting) {
    if (!wxClients.containsKey(key(appSetting))) {
      String url = WxEndpoint.get("url.token.get");
      WxClient wxClient = new WxClient(url, appSetting.getAppId(), appSetting.getSecret());
      wxClients.putIfAbsent(key(appSetting), wxClient);
    }

    return wxClients.get(key(appSetting));
  }
示例#2
0
  public WxClient with(AppSetting appSetting) {
    if (!wxClients.containsKey(key(appSetting))) {
      String url = WxEndpoint.get("url.token.get");
      String clazz = appSetting.getTokenHolderClass();

      AccessTokenHolder accessTokenHolder = null;
      if (clazz == null || "".equals(clazz)) {
        try {
          accessTokenHolder = (AccessTokenHolder) Class.forName(clazz).newInstance();
          accessTokenHolder.setClientId(appSetting.getAppId());
          accessTokenHolder.setClientSecret(appSetting.getSecret());
          accessTokenHolder.setTokenUrl(url);
        } catch (Exception e) {
          accessTokenHolder =
              new DefaultAccessTokenHolder(url, appSetting.getAppId(), appSetting.getSecret());
        }
      } else {
        accessTokenHolder =
            new DefaultAccessTokenHolder(url, appSetting.getAppId(), appSetting.getSecret());
      }

      WxClient wxClient =
          new WxClient(appSetting.getAppId(), appSetting.getSecret(), accessTokenHolder);
      wxClients.putIfAbsent(key(appSetting), wxClient);
    }

    return wxClients.get(key(appSetting));
  }
示例#3
0
 private String key(AppSetting appSetting) {
   return appSetting.getAppId() + ":" + appSetting.getSecret();
 }
示例#4
0
 public WxClient defaultWxClient() {
   return with(AppSetting.defaultSettings());
 }