cn.binarywang.wx.miniapp.config.WxMaConfig Java Examples

The following examples show how to use cn.binarywang.wx.miniapp.config.WxMaConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiTestModule.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(Binder binder) {
  try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) {
    if (inputStream == null) {
      throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
    }
    TestConfig config = TestConfig.fromXml(inputStream);
    config.setAccessTokenLock(new ReentrantLock());

    WxMaService wxService = new cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl();
    wxService.setWxMaConfig(config);

    binder.bind(WxMaService.class).toInstance(wxService);
    binder.bind(WxMaConfig.class).toInstance(config);
  } catch (IOException e) {
    this.log.error(e.getMessage(), e);
  }
}
 
Example #2
Source File: WxMaServiceImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void initHttp() {
  WxMaConfig configStorage = this.getWxMaConfig();
  ApacheHttpClientBuilder apacheHttpClientBuilder = configStorage.getApacheHttpClientBuilder();
  if (null == apacheHttpClientBuilder) {
    apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
  }

  apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost())
    .httpProxyPort(configStorage.getHttpProxyPort())
    .httpProxyUsername(configStorage.getHttpProxyUsername())
    .httpProxyPassword(configStorage.getHttpProxyPassword());

  if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
    this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
  }

  this.httpClient = apacheHttpClientBuilder.build();
}
 
Example #3
Source File: WxMaConfiguration.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaService wxMaService(WxMaConfig maConfig) {
    WxMaService service = new WxMaServiceImpl();
    service.setWxMaConfig(maConfig);
    return service;
}
 
Example #4
Source File: WechatMiniAppAutoConfiguration.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaConfig maConfig() {
    WxMaInMemoryConfig config = new WxMaInMemoryConfig();
    config.setAppid(this.properties.getAppId());
    config.setSecret(this.properties.getSecret());
    Optional.ofNullable(this.properties.getToken()).ifPresent(config::setToken);
    Optional.ofNullable(this.properties.getAesKey()).ifPresent(config::setAesKey);
    config.setMsgDataFormat(Optional.ofNullable(this.properties.getMsgDataFormat()).orElse("JSON"));
    return config;
}
 
Example #5
Source File: WechatMiniAppAutoConfiguration.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaService wxMaService(WxMaConfig maConfig) {
    WxMaService service = new WxMaServiceImpl();
    service.setWxMaConfig(maConfig);
    return service;
}
 
Example #6
Source File: WechatMaConfiguration.java    From cola-cloud with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaService wxMaService(WxMaConfig config) {
    WxMaService service = new WxMaServiceImpl();
    service.setWxMaConfig(config);
    return service;
}
 
Example #7
Source File: WxMaServiceImplTest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public void testRefreshAccessToken() throws WxErrorException {
  WxMaConfig configStorage = this.wxService.getWxMaConfig();
  String before = configStorage.getAccessToken();
  this.wxService.getAccessToken(false);

  String after = configStorage.getAccessToken();
  assertNotEquals(before, after);
  assertTrue(StringUtils.isNotBlank(after));
}
 
Example #8
Source File: WxConfig.java    From BigDataPlatform with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public WxMaConfig wxMaConfig() {
    WxMaInMemoryConfig config = new WxMaInMemoryConfig();
    config.setAppid(properties.getAppId());
    config.setSecret(properties.getAppSecret());
    return config;
}
 
Example #9
Source File: WxMaMessage.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public static WxMaMessage fromEncryptedJson(InputStream inputStream, WxMaConfig config) {
  try {
    return fromEncryptedJson(IOUtils.toString(inputStream, StandardCharsets.UTF_8), config);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #10
Source File: WxMaMessage.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public static WxMaMessage fromEncryptedJson(String encryptedJson, WxMaConfig config) {
  try {
    WxMaMessage encryptedMessage = fromJson(encryptedJson);
    String plainText = new WxMaCryptUtils(config).decrypt(encryptedMessage.getEncrypt());
    return fromJson(plainText);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #11
Source File: WxMaMessage.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public static WxMaMessage fromEncryptedXml(InputStream is, WxMaConfig wxMaConfig, String timestamp,
                                           String nonce, String msgSignature) {
  try {
    return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxMaConfig,
      timestamp, nonce, msgSignature);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #12
Source File: WxConfig.java    From litemall with MIT License 5 votes vote down vote up
@Bean
public WxMaConfig wxMaConfig() {
    WxMaInMemoryConfig config = new WxMaInMemoryConfig();
    config.setAppid(properties.getAppId());
    config.setSecret(properties.getAppSecret());
    return config;
}
 
Example #13
Source File: WxMaConfiguration.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaConfig maConfig() {
    WxMaInMemoryConfig config = new WxMaInMemoryConfig();
    config.setAppid(this.properties.getAppid());
    config.setSecret(this.properties.getSecret());
    config.setToken(this.properties.getToken());
    config.setAesKey(this.properties.getAesKey());
    config.setMsgDataFormat(this.properties.getMsgDataFormat());

    return config;
}
 
Example #14
Source File: WxMaServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode) throws WxErrorException {
  final WxMaConfig config = getWxMaConfig();
  Map<String, String> params = new HashMap<>(8);
  params.put("appid", config.getAppid());
  params.put("secret", config.getSecret());
  params.put("js_code", jsCode);
  params.put("grant_type", "authorization_code");

  String result = get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
  return WxMaJscode2SessionResult.fromJson(result);
}
 
Example #15
Source File: MiniAppConfiguration.java    From springboot-seed with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaConfig maConfig() {
    WxMaInMemoryConfig config = new WxMaInMemoryConfig();
    config.setAppid(this.properties.getId());
    config.setSecret(this.properties.getSecret());
    config.setToken(this.properties.getToken());
    config.setAesKey(this.properties.getAesKey());
    config.setMsgDataFormat(this.properties.getMessageFormat());

    return config;
}
 
Example #16
Source File: MiniAppConfiguration.java    From springboot-seed with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaService wxMaService(WxMaConfig maConfig) {
    WxMaService service = new WxMaServiceImpl();
    service.setWxMaConfig(maConfig);
    return service;
}
 
Example #17
Source File: WechatMiniAppConfiguration.java    From loc-framework with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaConfig maConfig() {
  WxMiniAppInRedisTemplateConfig config = new WxMiniAppInRedisTemplateConfig(redisTemplate);
  config.setAppid(this.properties.getAppId());
  config.setSecret(this.properties.getSecret());
  Optional.ofNullable(this.properties.getToken()).ifPresent(config::setToken);
  Optional.ofNullable(this.properties.getAesKey()).ifPresent(config::setAesKey);
  config.setMsgDataFormat(Optional.ofNullable(this.properties.getMsgDataFormat()).orElse("JSON"));
  return config;
}
 
Example #18
Source File: WxConfig.java    From mall with MIT License 5 votes vote down vote up
@Bean
public WxMaConfig wxMaConfig() {
    WxMaInMemoryConfig config = new WxMaInMemoryConfig();
    config.setAppid(properties.getAppId());
    config.setSecret(properties.getAppSecret());
    return config;
}
 
Example #19
Source File: WechatMiniAppConfiguration.java    From loc-framework with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaService wxMaService(WxMaConfig maConfig) {
  WxMaService service = new WxMaServiceImpl();
  service.setWxMaConfig(maConfig);
  return service;
}
 
Example #20
Source File: WxConfig.java    From spring-microservice-exam with MIT License 5 votes vote down vote up
@Bean
public WxMaConfig wxMaConfig() {
    WxMaInMemoryConfig config = new WxMaInMemoryConfig();
    config.setAppid(wxProperties.getAppId());
    config.setSecret(wxProperties.getAppSecret());
    return config;
}
 
Example #21
Source File: WechatMiniAppConfiguration.java    From loc-framework with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaConfig maConfig() {
  WxMaInMemoryConfig config = new WxMaInMemoryConfig();
  config.setAppid(this.properties.getAppId());
  config.setSecret(this.properties.getSecret());
  Optional.ofNullable(this.properties.getToken()).ifPresent(config::setToken);
  Optional.ofNullable(this.properties.getAesKey()).ifPresent(config::setAesKey);
  config.setMsgDataFormat(Optional.ofNullable(this.properties.getMsgDataFormat()).orElse("JSON"));
  return config;
}
 
Example #22
Source File: WxConfig.java    From dts-shop with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public WxMaConfig wxMaConfig() {
	WxMaInMemoryConfig config = new WxMaInMemoryConfig();
	config.setAppid(properties.getAppId());
	config.setSecret(properties.getAppSecret());
	return config;
}
 
Example #23
Source File: WechatMiniAppConfiguration.java    From loc-framework with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public WxMaService wxMaService(WxMaConfig maConfig) {
  WxMaService service = new WxMaServiceImpl();
  service.setWxMaConfig(maConfig);
  return service;
}
 
Example #24
Source File: WxMaPortalServlet.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
WxMaPortalServlet(WxMaConfig wxMaConfig, WxMaService wxMaService,
                  WxMaMessageRouter wxMaMessageRouter) {
  this.wxMaConfig = wxMaConfig;
  this.wxMaService = wxMaService;
  this.wxMaMessageRouter = wxMaMessageRouter;
}
 
Example #25
Source File: WxConfig.java    From litemall with MIT License 4 votes vote down vote up
@Bean
public WxMaService wxMaService(WxMaConfig maConfig) {
    WxMaService service = new WxMaServiceImpl();
    service.setWxMaConfig(maConfig);
    return service;
}
 
Example #26
Source File: WxOpenInMemoryConfigStorage.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Override
public WxMaConfig getWxMaConfig(String appId) {
  return new WxOpenInnerConfigStorage(this, appId);
}
 
Example #27
Source File: WxOpenMaServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Override
public WxMaConfig getWxMaConfig() {
  return wxMaConfig;
}
 
Example #28
Source File: WxOpenMaServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxOpenMaServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMaConfig wxMaConfig) {
  this.wxOpenComponentService = wxOpenComponentService;
  this.appId = appId;
  this.wxMaConfig = wxMaConfig;
  initHttp();
}
 
Example #29
Source File: WxMaCryptUtils.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxMaCryptUtils(WxMaConfig config) {
  this.appidOrCorpid = config.getAppid();
  this.token = config.getToken();
  this.aesKey = Base64.decodeBase64(config.getAesKey() + "=");
}
 
Example #30
Source File: WxMaServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Override
public void setWxMaConfig(WxMaConfig wxConfigProvider) {
  this.wxMaConfig = wxConfigProvider;
  this.initHttp();
}