doocs / qcloud-im-server-sdk-java Goto Github PK
View Code? Open in Web Editor NEW☁ Tencent Cloud IM Server SDK in Java | 腾讯云 IM 服务端 SDK Java 版
Home Page: https://doocs.github.io/qcloud-im-server-sdk-java
License: Apache License 2.0
☁ Tencent Cloud IM Server SDK in Java | 腾讯云 IM 服务端 SDK Java 版
Home Page: https://doocs.github.io/qcloud-im-server-sdk-java
License: Apache License 2.0
官方文档中msgRandom属性接收是用int类型,SDK代码中用的是long,但是有一个数据范围[0,4294967295]的提示,为什么不直接使用Integer呢?是有什么特殊原因吗?
@com.fasterxml.jackson.annotation.JsonProperty("MsgTime")
private java.lang.Integer msgTime;
@com.fasterxml.jackson.annotation.JsonProperty("msgSeq")
private java.lang.Long msgSeq;
中msgSeq为应该为MsgSeq
我这边通过一个模板方式,对IM的所有接口进行了包装,如果方法显性的扔出IOException,代码不太优雅。
我目前是这样写的
TxClientTemplate.call(room.getConfigId(),
(imClient) -> imClient.group.sendGroupMsg(request));
然后 TxClientTemplate.call 的代码是这样的
public static <T extends GenericResult> T call(Long configId, Function<ImClient, T> function) {
ImClient imClient = CLIENTS.get(configId);
if (imClient == null) {
throw new RuntimeException("缺少" + configId + "的imClient的配置");
}
try {
T result = function.apply(imClient);
log.info("请求腾讯云直播接口,响应:{}", JsonUtil.toJsonString(result));
if (!"OK".equals(result.getActionStatus()) || 0 != result.getErrorCode()) {
log.error("请求腾讯云失败,状态非OK");
throw BizException.create("103", result.getErrorInfo());
}
return result;
} catch (Throwable throwable) {
log.error("调用腾讯云发生异常,错误信息:{}", ExceptionUtil.getMessage(throwable), throwable);
throw BizException.create("103", "调用腾讯云接口失败");
}
}
如果显性的有IOException,那我的代码就需要每个都需要 try - catch 了就变成了,感觉很不优雅。
TxClientTemplate.call(room.getConfigId(),
(imClient) -> {
try {
return imClient.group.sendGroupMsg(request);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
目前项目中设置过期时间为1天,且无自动刷新机制(io.github.doocs.im.ClientConfiguration)。
在服务器稳定运行一天后,会出现问题。
java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_322]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_322]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_322]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_322]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_322]
at java.net.Socket.connect(Socket.java:607) ~[?:1.8.0_322]
at okhttp3.internal.platform.Platform.connectSocket(Platform.java:130) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:167) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.13.1.jar!/:?]
at com.tencent.im.v2.util.RetryInterceptor.intercept(HttpUtil.java:111) ~[tencent-im-sdk-v2-1.0.4.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:264) ~[okhttp-3.13.1.jar!/:?]
at okhttp3.RealCall.execute(RealCall.java:93) ~[okhttp-3.13.1.jar!/:?]
`
public class ClientConfiguration {
/**
* 默认 UA
*/
public static final String DEFAULT_USER_AGENT = VersionInfoUtil.getDefaultUserAgent();
/**
* 默认最大重试次数
*/
public static final int DEFAULT_MAX_RETRIES = 3;
/**
* 默认自动更新签名
*/
public static final boolean DEFAULT_RENEW_SIG = true;
/**
* 默认超时时间(毫秒)
*/
public static final long DEFAULT_CONNECT_TIMEOUT = 3000L;
public static final long DEFAULT_READ_TIMEOUT = 3000L;
public static final long DEFAULT_WRITE_TIMEOUT = 3000L;、
...
//其他code
`
"MsgList": [
{
"From_Account": "user1",
"To_Account": "user2",
"MsgSeq": 549396494,
"MsgRandom": 2578554,
"MsgTimeStamp": 1584669680,
"MsgFlagBits": 0,
"IsPeerRead": 0,
"MsgKey": "549396494_2578554_1584669680",
"MsgBody": [
{
"MsgType": "TIMTextElem",
"MsgContent": {
"Text": "msg 1"
}
}
],
"CloudCustomData": "your cloud custom data"
}
]
设置用户资料接口现在情况是设置昵称,头像,自定义字段等数据时调用接口返回成功,然后调用拉取资料查询,昵称,头像是更新成功的,但是自定义字段更新未成功,自定义字段是正确的key,因为有时候自定义字段是更新成功的,查看了入参都没发现啥问题
okhttp request:
Request{method=POST, url=https://console.tim.qq.com/v4/profile/portrait_set?sdkappid=xxxxx&identifier=administrator&usersig=xxxxx&random=2136887377&contenttype=json, headers=[User-Agent:qcloud-im-server-sdk-java/null(Mac OS X/13.0/aarch64;11.0.14.1)]}
okhttp requestString: {"From_Account":"xxxxxx","ProfileItem":[{"Tag":"Tag_Profile_IM_Nick","Value":"对对对"},{"Tag":"Tag_Profile_IM_Image","Value":"https:/xxxx.oss-cn-shanghai.aliyuncs.com/dams/47ed6184c7ee4ffeb9b6cabd7.png"},{"Tag":"Tag_Profile_Custom_Data","Value":"{"mobileNo":"13311111111","roleNameList":["SA"]}"}]}
okhttp response:
Response{protocol=http/1.1, code=200, message=OK, url=https://console.tim.qq.com/v4/profile/portrait_set?sdkappid=dddd&identifier=administrator&usersig=ddddd*&random=2136887377&contenttype=json}
多次调用接口都是返回成功的,自定义字段实际未生效, 查看入参都没问题,费解 是有什么要注意的吗 im后台设置的用户自定义字段key是 : Tag_Profile_Custom_Data 大小写是注意到了 没啥问题
IOS离线推送参数io.github.doocs.im.model.request.ApnsInfo#badgeMode字段应该是Integer类型,但是现在是String类型,序列化时会报错
Calling method:
io.github.doocs.im.core.Group#getMembers(io.github.doocs.im.model.request.GetMembersRequest)
Error while process response JSON.
at io.github.doocs.im.core.Group.getMembers(Group.java:503) \
at io.github.doocs.im.util.HttpUtil.post(HttpUtil.java:76) \
at io.github.doocs.im.util.JsonUtil.str2Obj(JsonUtil.java:34) \
com.fasterxml.jackson.core.exc.InputCoercionException: \
Numeric value (1718192416797) out of range of int (-2147483648 - 2147483647)
我翻了一下代码,sdk中提供了回调的接受参数,但没有找到验签相关的内容及单元测试,是我没找到吗
BeforeCreateGroupCallback.java
@JsonProperty("CreatedGroupNum")
private Integer createdGroupNum;
callback body
{
"CallbackCommand": "Group.CallbackBeforeCreateGroup",
"CreatedGroupNum": {
"Public": 5
}
}
你好
Maven**仓库SendGroupMsgRequest类缺少toAccount属性 希望能更新下 谢谢
这里获取 client instance 后, 从 cache 中获取的 client 的话,是不会更新 userSig 的过期时间的.
public static IMClient getInstance(Long sdkAppId, String userId, String key) {
String identify = sdkAppId + "_" + userId;
if (IM_CLIENT.get(identify) == null) {
IM_CLIENT.putIfAbsent(identify, new IMClient(sdkAppId, userId, key, 24 * 60 * 60L));
}
return IM_CLIENT.get(identify);
}
您好,我这边有用到实体类作为dubbo的dto使用的场景,dubbo中的传输对象没有实现Serializable会报错的.可否将实体类实现下 Serializable 接口呢.
// tencent doc
Tag_Profile_IM_BirthDay | uint32 | 生日 | 有 | 推荐用法:20190419
// code
profiles.add(ProfileItem.builder().tag(TagProfile.IM_BIRTHDAY).value(birth).build());
tks for your work.
best wishes.
在离线推送设置中
io.github.doocs.im.model.request.AndroidInfo#googleChannelId 字段和io.github.doocs.im.model.request.AndroidInfo#oppoChannelId 字段的@JsonProperty value值一样,都是 @JsonProperty("OPPOChannelID")。
用到这两个字段会报错:
Caused by: java.lang.IllegalArgumentException: Conflicting getter definitions for property "OPPOChannelID": io.github.doocs.im.model.request.AndroidInfo#getOppoChannelId(0 params) vs io.github.doocs.im.model.request.AndroidInfo#getGoogleChannelId(0 params)
如题, 撤回群消息之后回调"的命令: "Group.CallbackAfterRecallMsg"
MemberProfile->muteUntil字段为Integer类型,当调用群成员列表功能时如果群成员被永久禁言,腾讯云的禁言时间会返回4294967295,超出了Integer的最大范围代码报错。
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Numeric value (9040992949) out of range of int (-2147483648 - 2147483647)
这是源代码
public static void init() throws IOException {
long appId = xxxxxxx;
String userId = "xxxxxxxxxx";
String key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
ClientConfiguration config = new ClientConfiguration();
config.setExpireTime(7 * 24 * 60 * 60L);
config.setAutoRenewSig(false);
ImClient client = ImClient.getInstance(appId, userId, key, config);
GetAppIdGroupListRequest request = GetAppIdGroupListRequest.builder()
.limit(50)
.groupType(GroupType.PUBLIC)
.next(0)
.build();
GetAppIdGroupListResult result = client.group.getAppIdGroupList(request);
System.out.println(request);
}
SendMsgRequest 单聊消息缺少 OnlineOnlyFlag
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.