Skip to content

Commit

Permalink
🆕 #1952 增加腾讯企点子模块,用于对接企点开放平台。
Browse files Browse the repository at this point in the history
  • Loading branch information
fanxiayang12 authored Dec 30, 2020
1 parent a8232f6 commit e7f2bd6
Show file tree
Hide file tree
Showing 54 changed files with 3,928 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.bash
.history

*.class
test-output

Expand Down
6 changes: 2 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0"?>
<project
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"
xmlns="http://maven.apache.org/POM/4.0.0">
<project 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" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java</artifactId>
Expand Down Expand Up @@ -111,6 +108,7 @@
<module>weixin-java-pay</module>
<module>weixin-java-miniapp</module>
<module>weixin-java-open</module>
<module>weixin-java-qidian</module>
<module>spring-boot-starters</module>
<!--module>weixin-java-osgi</module-->
</modules>
Expand Down
5 changes: 2 additions & 3 deletions spring-boot-starters/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0"?>
<project 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"
xmlns="http://maven.apache.org/POM/4.0.0">
<project 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" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.binarywang</groupId>
Expand All @@ -22,6 +20,7 @@
<module>wx-java-mp-spring-boot-starter</module>
<module>wx-java-pay-spring-boot-starter</module>
<module>wx-java-open-spring-boot-starter</module>
<module>wx-java-qidian-spring-boot-starter</module>
</modules>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
*/
@Configuration
@EnableConfigurationProperties(WxMpProperties.class)
@Import({WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class})
@Import({ WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class })
public class WxMpAutoConfiguration {
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private WxMpConfigStorage jedisConfigStorage() {
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
wxMpProperties.getConfigStorage().getKeyPrefix());
wxMpProperties.getConfigStorage().getKeyPrefix());
setWxMpInfo(wxMpRedisConfig);
return wxMpRedisConfig;
}
Expand All @@ -114,7 +114,7 @@ private WxMpConfigStorage redisTemplateConfigStorage() {

WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
wxMpProperties.getConfigStorage().getKeyPrefix());
wxMpProperties.getConfigStorage().getKeyPrefix());

setWxMpInfo(wxMpRedisConfig);
return wxMpRedisConfig;
Expand Down Expand Up @@ -160,6 +160,6 @@ private JedisPoolAbstract getJedisPool() {
}

return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
redis.getDatabase());
redis.getDatabase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static com.binarywang.spring.starter.wxjava.mp.enums.StorageType.Memory;
import static com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties.PREFIX;


/**
* 微信接入相关配置属性.
*
Expand Down
45 changes: 45 additions & 0 deletions spring-boot-starters/wx-java-qidian-spring-boot-starter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# wx-java-qidian-spring-boot-starter

## 快速开始

1. 引入依赖
```xml
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java-qidian-spring-boot-starter</artifactId>
<version>${version}</version>
</dependency>
```
2. 添加配置(application.properties)
```properties
# 公众号配置(必填)
wx.mp.appId = appId
wx.mp.secret = @secret
wx.mp.token = @token
wx.mp.aesKey = @aesKey
# 存储配置redis(可选)
wx.mp.config-storage.type = Jedis # 配置类型: Memory(默认), Jedis, RedisTemplate
wx.mp.config-storage.key-prefix = wx # 相关redis前缀配置: wx(默认)
wx.mp.config-storage.redis.host = 127.0.0.1
wx.mp.config-storage.redis.port = 6379
#单机和sentinel同时存在时,优先使用sentinel配置
#wx.mp.config-storage.redis.sentinel-ips=127.0.0.1:16379,127.0.0.1:26379
#wx.mp.config-storage.redis.sentinel-name=mymaster
# http客户端配置
wx.mp.config-storage.http-client-type=httpclient # http客户端类型: HttpClient(默认), OkHttp, JoddHttp
wx.mp.config-storage.http-proxy-host=
wx.mp.config-storage.http-proxy-port=
wx.mp.config-storage.http-proxy-username=
wx.mp.config-storage.http-proxy-password=
# 公众号地址host配置
#wx.mp.hosts.api-host=http://proxy.com/
#wx.mp.hosts.open-host=http://proxy.com/
#wx.mp.hosts.mp-host=http://proxy.com/
```
3. 自动注入的类型

- `WxMpService`
- `WxMpConfigStorage`

4、参考 demo:
https://github.com/binarywang/wx-java-mp-demo
66 changes: 66 additions & 0 deletions spring-boot-starters/wx-java-qidian-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.0.1.B</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>wx-java-qidian-spring-boot-starter</artifactId>
<name>WxJava - Spring Boot Starter for QiDian</name>
<description>腾讯企点的 Spring Boot Starter</description>

<dependencies>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-qidian</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring.boot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<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,17 @@
package com.binarywang.spring.starter.wxjava.qidian.config;

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

/**
* .
*
* @author someone
*/
@Configuration
@EnableConfigurationProperties(WxQidianProperties.class)
@Import({ WxQidianStorageAutoConfiguration.class, WxQidianServiceAutoConfiguration.class })
public class WxQidianAutoConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.binarywang.spring.starter.wxjava.qidian.config;

import com.binarywang.spring.starter.wxjava.qidian.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.qidian.properties.WxQidianProperties;
import me.chanjar.weixin.qidian.api.WxQidianService;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceHttpClientImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceJoddHttpImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceOkHttpImpl;
import me.chanjar.weixin.qidian.config.WxQidianConfigStorage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* 腾讯企点相关服务自动注册.
*
* @author alegria
*/
@Configuration
public class WxQidianServiceAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public WxQidianService wxQidianService(WxQidianConfigStorage configStorage, WxQidianProperties wxQidianProperties) {
HttpClientType httpClientType = wxQidianProperties.getConfigStorage().getHttpClientType();
WxQidianService wxQidianService;
switch (httpClientType) {
case OkHttp:
wxQidianService = newWxQidianServiceOkHttpImpl();
break;
case JoddHttp:
wxQidianService = newWxQidianServiceJoddHttpImpl();
break;
case HttpClient:
wxQidianService = newWxQidianServiceHttpClientImpl();
break;
default:
wxQidianService = newWxQidianServiceImpl();
break;
}

wxQidianService.setWxMpConfigStorage(configStorage);
return wxQidianService;
}

private WxQidianService newWxQidianServiceImpl() {
return new WxQidianServiceImpl();
}

private WxQidianService newWxQidianServiceHttpClientImpl() {
return new WxQidianServiceHttpClientImpl();
}

private WxQidianService newWxQidianServiceOkHttpImpl() {
return new WxQidianServiceOkHttpImpl();
}

private WxQidianService newWxQidianServiceJoddHttpImpl() {
return new WxQidianServiceJoddHttpImpl();
}

}
Loading

0 comments on commit e7f2bd6

Please sign in to comment.