-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9433f5e
commit 7b4929a
Showing
600 changed files
with
1,009 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.7.9</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>cn.felord.wecom</groupId> | ||
<artifactId>spring-boot-sample</artifactId> | ||
<version>1.0.12</version> | ||
<name>wecom-sdk-spring-boot-sample</name> | ||
<description>wecom-sdk-spring-boot-sample</description> | ||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>cn.felord</groupId> | ||
<artifactId>wecom-sdk</artifactId> | ||
<version>1.0.12</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.sf.ehcache</groupId> | ||
<artifactId>ehcache</artifactId> | ||
<version>2.10.9.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-cache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
samples/spring-boot-sample/src/main/java/cn/felord/wecom/WecomSdkApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.felord.wecom; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class WecomSdkApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(WecomSdkApplication.class, args); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
samples/spring-boot-sample/src/main/java/cn/felord/wecom/api/CallbackController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package cn.felord.wecom.api; | ||
|
||
import cn.felord.callbacks.CallbackCrypto; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* 通用回调,这里照搬即可,记得权限放行,过滤器拦截器也放行 | ||
* <p> | ||
* 所有配置回调的地方都可以配置成一个接口,格式/wecom/callback/企微企业id/企微应用id | ||
* <p> | ||
* 企微企业id去企业微信控制台找 | ||
* 企微应用id,如果是自建的应用去应用管理查看agentid,如果是企微内置的应用查看{@link cn.felord.enumeration.NativeAgent} | ||
* | ||
* @author felord.cn | ||
* @since 1.0.14.RELEASE | ||
*/ | ||
@AllArgsConstructor | ||
@RestController | ||
@RequestMapping("/wecom/callback") | ||
public class CallbackController { | ||
private final CallbackCrypto callbackCrypto; | ||
|
||
/** | ||
* 验证回调URL | ||
* | ||
* @param msgSignature the msg signature | ||
* @param timestamp the timestamp | ||
* @param nonce the nonce | ||
* @param echostr the echostr | ||
* @param corpId the corp id | ||
* @param agentId the agent id | ||
* @return the long | ||
*/ | ||
@GetMapping("/{corpId}/{agentId}") | ||
public String verifyUrl(@RequestParam("msg_signature") String msgSignature, | ||
@RequestParam String timestamp, | ||
@RequestParam String nonce, | ||
@RequestParam String echostr, | ||
@PathVariable String corpId, | ||
@PathVariable String agentId) { | ||
return callbackCrypto.decryptMsg(agentId, corpId, msgSignature, timestamp, nonce, echostr); | ||
} | ||
|
||
/** | ||
* 消费回调数据 | ||
* | ||
* @param msgSignature the msg signature | ||
* @param timestamp the timestamp | ||
* @param nonce the nonce | ||
* @param xmlBody the xml body | ||
* @param corpId the corp id | ||
* @param agentId the agent id | ||
* @return the string | ||
*/ | ||
@PostMapping("/{corpId}/{agentId}") | ||
public String consume(@RequestParam("msg_signature") String msgSignature, | ||
@RequestParam String timestamp, | ||
@RequestParam String nonce, | ||
@RequestBody String xmlBody, | ||
@PathVariable String corpId, | ||
@PathVariable String agentId) { | ||
return callbackCrypto | ||
.accept(agentId, corpId, msgSignature, timestamp, nonce, xmlBody); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...es/spring-boot-sample/src/main/java/cn/felord/wecom/cache/EhcacheWeComTokenCacheable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cn.felord.wecom.cache; | ||
|
||
import cn.felord.WeComTokenCacheable; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.cache.annotation.CachePut; | ||
import org.springframework.cache.annotation.Cacheable; | ||
|
||
/** | ||
* @author dax | ||
* @since 2023/5/30 | ||
*/ | ||
public class EhcacheWeComTokenCacheable implements WeComTokenCacheable { | ||
private static final String QYWX_TOKEN_CACHE = "token::qywx"; | ||
private static final String QYWX_CORP_TICKET_CACHE = "ticket::qywx::corp"; | ||
private static final String QYWX_AGENT_TICKET_CACHE = "ticket::qywx::agent"; | ||
|
||
@CachePut(value = {QYWX_TOKEN_CACHE}, key = "#corpId.concat('::').concat(#agentId)") | ||
@Override | ||
public String putAccessToken(@NotNull String corpId, @NotNull String agentId, @NotNull String accessToken) { | ||
return accessToken; | ||
} | ||
|
||
@Cacheable(value = {QYWX_TOKEN_CACHE}, key = "#corpId.concat('::').concat(#agentId)") | ||
@Override | ||
public String getAccessToken(@NotNull String corpId, @NotNull String agentId) { | ||
return null; | ||
} | ||
|
||
@CachePut(value = {QYWX_CORP_TICKET_CACHE}, key = "#corpId.concat('::').concat(#agentId)") | ||
@Override | ||
public String putCorpTicket(@NotNull String corpId, @NotNull String agentId, @NotNull String corpTicket) { | ||
return corpTicket; | ||
} | ||
|
||
@Cacheable(value = {QYWX_TOKEN_CACHE}, key = "#corpId.concat('::').concat(#agentId)") | ||
@Override | ||
public String getCorpTicket(@NotNull String corpId, @NotNull String agentId) { | ||
return null; | ||
} | ||
|
||
@CachePut(value = {QYWX_AGENT_TICKET_CACHE}, key = "#corpId.concat('::').concat(#agentId)") | ||
@Override | ||
public String putAgentTicket(@NotNull String corpId, @NotNull String agentId, @NotNull String agentTicket) { | ||
return agentTicket; | ||
} | ||
|
||
@Cacheable(value = {QYWX_TOKEN_CACHE}, key = "#corpId.concat('::').concat(#agentId)") | ||
@Override | ||
public String getAgentTicket(@NotNull String corpId, @NotNull String agentId) { | ||
return null; | ||
} | ||
} | ||
|
79 changes: 79 additions & 0 deletions
79
...les/spring-boot-sample/src/main/java/cn/felord/wecom/configure/WecomSdkConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cn.felord.wecom.configure; | ||
|
||
import cn.felord.WeComTokenCacheable; | ||
import cn.felord.api.WorkWeChatApi; | ||
import cn.felord.callbacks.CallbackAsyncConsumer; | ||
import cn.felord.callbacks.CallbackCrypto; | ||
import cn.felord.callbacks.CallbackCryptoBuilder; | ||
import cn.felord.callbacks.CallbackSettingsService; | ||
import cn.felord.domain.callback.CallbackEventBody; | ||
import cn.felord.domain.callback.CallbackSettings; | ||
import cn.felord.enumeration.CallbackEvent; | ||
import cn.felord.wecom.cache.EhcacheWeComTokenCacheable; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Wecom Sdk 配置 | ||
* | ||
* @author dax | ||
* @since 2023 /5/30 | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
public class WecomSdkConfiguration { | ||
|
||
/** | ||
* 企微token,ticket 缓存中继,这里使用ehcache作为例子,你可以无缝替换为redis等缓存中间件 | ||
* | ||
* @return the we com token cacheable | ||
*/ | ||
@Bean | ||
WeComTokenCacheable weComTokenCacheable() { | ||
return new EhcacheWeComTokenCacheable(); | ||
} | ||
|
||
/** | ||
* 初始化 企微API客户端,这个是平常我们发起调用的入口 | ||
* <p> | ||
* 例子参见 test 测试包下的 SpringBootWecomSdkTests | ||
* | ||
* @param weComTokenCacheable the we com token cacheable | ||
* @return the work we chat api | ||
*/ | ||
@Bean | ||
WorkWeChatApi workWeChatApi(WeComTokenCacheable weComTokenCacheable) { | ||
return new WorkWeChatApi(weComTokenCacheable); | ||
} | ||
|
||
/** | ||
* 回调配置 | ||
* | ||
* @return the callback crypto | ||
*/ | ||
@Bean | ||
public CallbackCrypto callbackCrypto() { | ||
return new CallbackCryptoBuilder(new Consumer<CallbackEventBody>() { | ||
// 消费 被解密的回调消息 已达到动态处理企微事件业务的能力 这里还有其它高级操作 自行去看底层实现 | ||
@Override | ||
public void accept(CallbackEventBody callbackEventBody) { | ||
// 获取事件类型 建议每个类型的处理逻辑抽成接口 统一实现 | ||
CallbackEvent event = callbackEventBody.getEvent(); | ||
|
||
} | ||
}) | ||
.build(new CallbackSettingsService() { | ||
// 这里你可以通过实现该接口来持久化 根据 企微应用id 和企业id 查询对应应用的回调 token encodingAesKey 等回调参数, | ||
@Override | ||
public CallbackSettings loadAuthentication(String agentId, String corpId) { | ||
return new CallbackSettings("", "", ""); | ||
} | ||
}); | ||
} | ||
|
||
|
||
|
||
|
||
} |
6 changes: 6 additions & 0 deletions
6
samples/spring-boot-sample/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
spring: | ||
application: | ||
name: wecom-sdk-springboot | ||
cache: | ||
ehcache: | ||
config: |
Oops, something went wrong.