Skip to content

Commit

Permalink
🆕 #2991【视频号】增加视频号模块,实现视频号大部分相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
lixize authored May 11, 2023
1 parent 899ea65 commit 583e1a0
Show file tree
Hide file tree
Showing 420 changed files with 20,931 additions and 1 deletion.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<module>weixin-java-miniapp</module>
<module>weixin-java-open</module>
<module>weixin-java-qidian</module>
<module>weixin-java-channel</module>
<module>spring-boot-starters</module>
<!--module>weixin-java-osgi</module-->
</modules>
Expand Down
1 change: 1 addition & 0 deletions spring-boot-starters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>wx-java-open-spring-boot-starter</module>
<module>wx-java-qidian-spring-boot-starter</module>
<module>wx-java-cp-spring-boot-starter</module>
<module>wx-java-channel-spring-boot-starter</module>
</modules>

<dependencies>
Expand Down
60 changes: 60 additions & 0 deletions spring-boot-starters/wx-java-channel-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>wx-java-spring-boot-starters</artifactId>
<groupId>com.github.binarywang</groupId>
<version>4.4.9.B</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>wx-java-channel-spring-boot-starter</artifactId>
<name>WxJava - Spring Boot Starter for Channel</name>
<description>微信视频号开发的 Spring Boot Starter</description>

<dependencies>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-channel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring.boot.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.binarywang.spring.starter.wxjava.channel.config;

import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
* 自动配置
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@EnableConfigurationProperties(WxChannelProperties.class)
@Import({
WxChannelStorageAutoConfiguration.class,
WxChannelServiceAutoConfiguration.class
})
public class WxChannelAutoConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.binarywang.spring.starter.wxjava.channel.config;


import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.channel.api.WxChannelService;
import me.chanjar.weixin.channel.api.impl.WxChannelServiceImpl;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* 微信小程序平台相关服务自动注册
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@AllArgsConstructor
public class WxChannelServiceAutoConfiguration {
private final WxChannelProperties properties;

/**
* Channel Service
*
* @return Channel Service
*/
@Bean
@ConditionalOnMissingBean(WxChannelService.class)
@ConditionalOnBean(WxChannelConfig.class)
public WxChannelService wxChannelService(WxChannelConfig wxChannelConfig) {
WxChannelService wxChannelService = new WxChannelServiceImpl();
wxChannelService.setConfig(wxChannelConfig);
return wxChannelService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.binarywang.spring.starter.wxjava.channel.config;

import com.binarywang.spring.starter.wxjava.channel.config.storage.WxChannelInJedisConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.channel.config.storage.WxChannelInMemoryConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.channel.config.storage.WxChannelInRedisTemplateConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.channel.config.storage.WxChannelInRedissonConfigStorageConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
* 微信小程序存储策略自动配置
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@Import({
WxChannelInMemoryConfigStorageConfiguration.class,
WxChannelInJedisConfigStorageConfiguration.class,
WxChannelInRedisTemplateConfigStorageConfiguration.class,
WxChannelInRedissonConfigStorageConfiguration.class
})
public class WxChannelStorageAutoConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.binarywang.spring.starter.wxjava.channel.config.storage;

import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import me.chanjar.weixin.channel.config.impl.WxChannelDefaultConfigImpl;
import org.apache.commons.lang3.StringUtils;

/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
public abstract class AbstractWxChannelConfigStorageConfiguration {

protected WxChannelDefaultConfigImpl config(WxChannelDefaultConfigImpl config, WxChannelProperties properties) {
config.setAppid(StringUtils.trimToNull(properties.getAppid()));
config.setSecret(StringUtils.trimToNull(properties.getSecret()));
config.setToken(StringUtils.trimToNull(properties.getToken()));
config.setAesKey(StringUtils.trimToNull(properties.getAesKey()));
config.setMsgDataFormat(StringUtils.trimToNull(properties.getMsgDataFormat()));

WxChannelProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}

int maxRetryTimes = configStorageProperties.getMaxRetryTimes();
if (configStorageProperties.getMaxRetryTimes() < 0) {
maxRetryTimes = 0;
}
int retrySleepMillis = configStorageProperties.getRetrySleepMillis();
if (retrySleepMillis < 0) {
retrySleepMillis = 1000;
}
config.setRetrySleepMillis(retrySleepMillis);
config.setMaxRetryTimes(maxRetryTimes);
return config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.binarywang.spring.starter.wxjava.channel.config.storage;


import com.binarywang.spring.starter.wxjava.channel.properties.RedisProperties;
import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import me.chanjar.weixin.channel.config.impl.WxChannelRedisConfigImpl;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@ConditionalOnProperty(prefix = WxChannelProperties.PREFIX + ".config-storage", name = "type", havingValue = "jedis")
@ConditionalOnClass({JedisPool.class, JedisPoolConfig.class})
@RequiredArgsConstructor
public class WxChannelInJedisConfigStorageConfiguration extends AbstractWxChannelConfigStorageConfiguration {
private final WxChannelProperties properties;
private final ApplicationContext applicationContext;

@Bean
@ConditionalOnMissingBean(WxChannelConfig.class)
public WxChannelConfig wxChannelConfig() {
WxChannelRedisConfigImpl config = getWxChannelRedisConfig();
return this.config(config, properties);
}

private WxChannelRedisConfigImpl getWxChannelRedisConfig() {
RedisProperties redisProperties = properties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
jedisPool = getJedisPool();
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
return new WxChannelRedisConfigImpl(redisOps, properties.getConfigStorage().getKeyPrefix());
}

private JedisPool getJedisPool() {
WxChannelProperties.ConfigStorage storage = properties.getConfigStorage();
RedisProperties redis = storage.getRedis();

JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);

return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), redis.getDatabase());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.binarywang.spring.starter.wxjava.channel.config.storage;


import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import me.chanjar.weixin.channel.config.impl.WxChannelDefaultConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@ConditionalOnProperty(prefix = WxChannelProperties.PREFIX + ".config-storage", name = "type",
matchIfMissing = true, havingValue = "memory")
@RequiredArgsConstructor
public class WxChannelInMemoryConfigStorageConfiguration extends AbstractWxChannelConfigStorageConfiguration {
private final WxChannelProperties properties;

@Bean
@ConditionalOnMissingBean(WxChannelProperties.class)
public WxChannelConfig wxChannelConfig() {
WxChannelDefaultConfigImpl config = new WxChannelDefaultConfigImpl();
return this.config(config, properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.binarywang.spring.starter.wxjava.channel.config.storage;

import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import me.chanjar.weixin.channel.config.impl.WxChannelRedisConfigImpl;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@ConditionalOnProperty(prefix = WxChannelProperties.PREFIX + ".config-storage", name = "type", havingValue = "redistemplate")
@ConditionalOnClass(StringRedisTemplate.class)
@RequiredArgsConstructor
public class WxChannelInRedisTemplateConfigStorageConfiguration extends AbstractWxChannelConfigStorageConfiguration {
private final WxChannelProperties properties;
private final ApplicationContext applicationContext;

@Bean
@ConditionalOnMissingBean(WxChannelConfig.class)
public WxChannelConfig wxChannelConfig() {
WxChannelRedisConfigImpl config = getWxChannelInRedisTemplateConfig();
return this.config(config, properties);
}

private WxChannelRedisConfigImpl getWxChannelInRedisTemplateConfig() {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
return new WxChannelRedisConfigImpl(redisOps, properties.getConfigStorage().getKeyPrefix());
}
}
Loading

0 comments on commit 583e1a0

Please sign in to comment.