Skip to content

Commit

Permalink
1.0.15.rc
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFound403 committed Jun 26, 2023
1 parent 97ba5c6 commit 798361f
Show file tree
Hide file tree
Showing 78 changed files with 1,836 additions and 3,782 deletions.
8 changes: 0 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot.version>2.7.9</spring-boot.version>
<retrofit.version>2.9.0</retrofit.version>
<okhttp3.version>4.10.0</okhttp3.version>
<lombok.version>1.18.26</lombok.version>
Expand All @@ -117,13 +116,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>cn.felord</groupId>
<artifactId>wecom-objects</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions rx-wecom-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
104 changes: 0 additions & 104 deletions rx-wecom-sdk/src/main/java/cn/felord/reactive/TokenInterceptor.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public interface ChatInterceptRuleApi {
* @return the intercept rule
*/
@POST("externalcontact/get_intercept_rule")
GenericResponse<InterceptRuleDetail> getInterceptRule(@Body InterceptRuleRequest request);
Single<GenericResponse<InterceptRuleDetail>> getInterceptRule(@Body InterceptRuleRequest request);

/**
* 修改敏感词规则
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import cn.felord.domain.jssdk.AgentConfigResponse;
import cn.felord.domain.jssdk.CorpConfigResponse;
import cn.felord.domain.jssdk.JSignatureResponse;
import cn.felord.utils.Algorithms;
import cn.felord.utils.AlternativeJdkIdGenerator;
import cn.felord.utils.SHA1;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Single;
import lombok.SneakyThrows;

import java.text.MessageFormat;
import java.time.Instant;
Expand Down Expand Up @@ -82,7 +81,7 @@ public Single<CorpConfigResponse> corpTicket(String url) {
public Single<AgentConfigResponse> agentTicket(String url) {
String corpId = agentDetails.getCorpId();
String agentId = agentDetails.getAgentId();
return Maybe.just(weComAgentTicketCacheable.getCorpTicket(corpId, agentId))
return Maybe.just(weComAgentTicketCacheable.getAgentTicket(corpId, agentId))
.switchIfEmpty(jsApi.agentJsApiTicket("agent_config")
.map(JsTicketResponse::getTicket)
.map(agentTicket -> weComAgentTicketCacheable.putAgentTicket(corpId, agentId, agentTicket)))
Expand All @@ -98,16 +97,14 @@ public Single<AgentConfigResponse> agentTicket(String url) {
});
}


@SneakyThrows
private JSignatureResponse sha1(String ticket, String url) {
String nonceStr = ID_GENERATOR.generateId();
String timestamp = String.valueOf(Instant.now().getEpochSecond());
String format = MessageFormat.format(SIGNATURE_FORMATTER, ticket, nonceStr, timestamp, url);
JSignatureResponse jSignature = new JSignatureResponse();
jSignature.setNonceStr(nonceStr);
jSignature.setTimestamp(timestamp);
jSignature.setSignature(SHA1.sha1Hex(format));
jSignature.setSignature(Algorithms.sha1Hex(format));
return jSignature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package cn.felord.reactive.api;

import cn.felord.AgentDetails;
import cn.felord.reactive.RetrofitFactory;
import cn.felord.WeComTokenCacheable;
import cn.felord.retrofit.AccessTokenApi;
import cn.felord.retrofit.RetrofitFactory;
import okhttp3.ConnectionPool;
import okhttp3.logging.HttpLoggingInterceptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@


import cn.felord.AgentDetails;
import cn.felord.reactive.RetrofitFactory;
import cn.felord.retrofit.RetrofitFactory;
import cn.felord.retrofit.TokenApi;
import okhttp3.ConnectionPool;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
Expand Down
5 changes: 5 additions & 0 deletions samples/spring-boot-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ void sendAgentMsg() {
.build();

DefaultAgent defaultAgent = new DefaultAgent("企微企业id", "企微应用密钥", "企微应用id");
MessageResponse send = workWeChatApi.agentMessageApi(defaultAgent)
MessageResponse send = workWeChatApi.agentApi(defaultAgent)
.agentMessageApi()
.send(cardMessageBody);
Assertions.assertTrue(send.isSuccessful());
}
Expand Down
24 changes: 22 additions & 2 deletions wecom-objects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,23 @@

<dependencies>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId>
<optional>true</optional>
</dependency>
<dependency>
Expand All @@ -71,6 +86,11 @@
<artifactId>jackson-datatype-jsr310</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import cn.felord.WeComException;
import cn.felord.domain.callback.CallbackEventBody;
import cn.felord.utils.Base64Utils;
import cn.felord.utils.SHA1;
import cn.felord.utils.Algorithms;
import cn.felord.utils.StringUtils;
import cn.felord.xml.XmlReader;

Expand Down Expand Up @@ -224,7 +224,7 @@ public String encryptJsonMsg(String agentId, String corpId, String replyMsg, Str
timeStamp = Long.toString(System.currentTimeMillis());
}
String token = callbackSettings.getToken();
String signature = SHA1.sha1Signature(token, timeStamp, nonce, encrypt);
String signature = Algorithms.sha1Signature(token, timeStamp, nonce, encrypt);
return String.format(MSG, encrypt, signature, timeStamp, nonce);
}

Expand All @@ -249,7 +249,7 @@ public String encryptXmlMsg(String agentId, String corpId, String replyMsg, Stri
timeStamp = Long.toString(Instant.now().toEpochMilli());
}
String token = callbackSettings.getToken();
String signature = SHA1.sha1Signature(token, timeStamp, nonce, encrypt);
String signature = Algorithms.sha1Signature(token, timeStamp, nonce, encrypt);
CallbackXmlResponse callbackXmlResponse = new CallbackXmlResponse(encrypt, signature, timeStamp, nonce);
return xmlReader.write(callbackXmlResponse);
}
Expand Down Expand Up @@ -325,7 +325,7 @@ private <T> T doAccept(String agentId, String corpId, String msgSignature, Strin
public String decryptMsg(String agentId, String corpId, String msgSignature, String timeStamp, String nonce, String encrypt) {
CallbackSettings callbackSettings = this.callbackSettingsService.loadAuthentication(agentId, corpId);
String token = callbackSettings.getToken();
String signature = SHA1.sha1Signature(token, timeStamp, nonce, encrypt);
String signature = Algorithms.sha1Signature(token, timeStamp, nonce, encrypt);
if (!Objects.equals(msgSignature, signature)) {
throw new WeComException("callback signature not matched");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package cn.felord.reactive.api;
package cn.felord.retrofit;


import cn.felord.AgentDetails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,34 @@
* limitations under the License.
*/

package cn.felord.reactive.api;
package cn.felord.retrofit;

import cn.felord.WeComException;
import cn.felord.domain.authentication.AccessTokenResponse;
import cn.felord.AgentDetails;
import cn.felord.reactive.RetrofitFactory;
import cn.felord.WeComException;
import cn.felord.WeComTokenCacheable;
import cn.felord.domain.authentication.AccessTokenResponse;

/**
* 获取 access_token
*
* @author felord.cn
*/
public class AccessTokenApi extends AbstractTokenApi {
private static final ReactiveAccessTokenApi API = RetrofitFactory.RETROFIT_.create(ReactiveAccessTokenApi.class);
private static final RetrofitAccessTokenApi TOKEN_API = RetrofitFactory.RETROFIT_.create(RetrofitAccessTokenApi.class);

/**
* Instantiates a new Access token api.
*
* @param wecomCacheable the wecom cacheable
* @param agentDetails the agent details
*/
AccessTokenApi(WeComTokenCacheable wecomCacheable, AgentDetails agentDetails) {
public AccessTokenApi(WeComTokenCacheable wecomCacheable, AgentDetails agentDetails) {
super(wecomCacheable, agentDetails);
}

@Override
protected String doGetToken(AgentDetails agentDetails) {
AccessTokenResponse tokenResponse = API.getTokenResponse(agentDetails.getCorpId(), agentDetails.getSecret());
AccessTokenResponse tokenResponse = TOKEN_API.getTokenResponse(agentDetails.getCorpId(), agentDetails.getSecret());
if (tokenResponse == null || tokenResponse.isError()) {
String errorMsg = tokenResponse == null ? "token response is null" : tokenResponse.getErrmsg();
throw new WeComException("failed to obtain access token,reason: " + errorMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.felord.reactive;
package cn.felord.retrofit;


import cn.felord.WeComException;
Expand Down Expand Up @@ -54,7 +54,7 @@ private ResponseBodyCallAdapterFactory() {
*
* @param <R> the type parameter
*/
static final class ResponseBodyCallAdapter<R extends WeComResponse> implements CallAdapter<R, R> {
static final class ResponseBodyCallAdapter<R> implements CallAdapter<R, R> {

private final Type returnType;

Expand Down Expand Up @@ -91,13 +91,14 @@ public R adapt(Call<R> call) {
}

if (response.isSuccessful()) {
R weComResponse = response.body();
if (weComResponse != null) {
R body = response.body();
if (body != null && body.getClass().isAssignableFrom(WeComResponse.class)) {
WeComResponse weComResponse = (WeComResponse) body;
if (weComResponse.isError()) {
throw new WeComException(weComResponse.getErrcode(), weComResponse.getErrmsg());
}
}
return weComResponse;
return body;
}

Converter<ResponseBody, R> responseBodyRConverter = retrofit.responseBodyConverter(responseType(), annotations);
Expand Down
Loading

0 comments on commit 798361f

Please sign in to comment.