Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
im-common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈永峰
im-common
Commits
4fb1d062
Unverified
Commit
4fb1d062
authored
Oct 26, 2021
by
Yang Libin
Committed by
GitHub
Oct 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: user sig in IMClient (#35)
* fix: user sig in IMClient * fix: synchronized block * fix #34
parent
4c203690
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
26 deletions
+38
-26
README.md
README.md
+1
-1
pom.xml
pom.xml
+1
-1
IMClient.java
src/main/java/io/github/doocs/im/IMClient.java
+35
-23
GenericResult.java
...java/io/github/doocs/im/model/response/GenericResult.java
+1
-1
No files found.
README.md
View file @
4fb1d062
...
@@ -22,7 +22,7 @@ Add the Maven dependency:
...
@@ -22,7 +22,7 @@ Add the Maven dependency:
<dependency>
<dependency>
<groupId>
io.github.doocs
</groupId>
<groupId>
io.github.doocs
</groupId>
<artifactId>
im-server-sdk-java
</artifactId>
<artifactId>
im-server-sdk-java
</artifactId>
<version>
0.0.
8
</version>
<version>
0.0.
9
</version>
</dependency>
</dependency>
```
```
...
...
pom.xml
View file @
4fb1d062
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<groupId>
io.github.doocs
</groupId>
<groupId>
io.github.doocs
</groupId>
<artifactId>
im-server-sdk-java
</artifactId>
<artifactId>
im-server-sdk-java
</artifactId>
<version>
0.0.
8
</version>
<version>
0.0.
9
</version>
<packaging>
jar
</packaging>
<packaging>
jar
</packaging>
<name>
qcloud-im-server-sdk-java
</name>
<name>
qcloud-im-server-sdk-java
</name>
...
...
src/main/java/io/github/doocs/im/IMClient.java
View file @
4fb1d062
...
@@ -17,42 +17,40 @@ public class IMClient {
...
@@ -17,42 +17,40 @@ public class IMClient {
/**
/**
* core methods
* core methods
*/
*/
public
Account
account
;
public
final
Account
account
;
public
Message
message
;
public
final
Message
message
;
public
Member
member
;
public
final
Member
member
;
public
Profile
profile
;
public
final
Profile
profile
;
public
Group
group
;
public
final
Group
group
;
public
SNS
sns
;
public
final
SNS
sns
;
public
Operation
operation
;
public
final
Operation
operation
;
public
RecentContact
recentContact
;
public
final
RecentContact
recentContact
;
/**
/**
* init property
* init property
*/
*/
private
final
String
version
=
"v4"
;
private
String
userSig
;
private
long
userSigExpireTs
;
private
final
Long
sdkAppId
;
private
final
Long
sdkAppId
;
private
final
String
userId
;
private
final
String
userId
;
private
final
String
userSig
;
private
final
String
key
;
public
static
IMClient
getInstance
(
Long
sdkAppId
,
String
userId
,
String
key
,
Long
expire
)
{
private
static
final
String
VERSION
=
"v4"
;
String
identify
=
sdkAppId
+
"_"
+
userId
;
private
static
final
long
EXPIRE_TIME
=
24
*
60
*
60L
;
if
(
IM_CLIENT
.
get
(
identify
)
==
null
)
{
IM_CLIENT
.
putIfAbsent
(
identify
,
new
IMClient
(
sdkAppId
,
userId
,
key
,
expire
));
}
return
IM_CLIENT
.
get
(
identify
);
}
public
static
IMClient
getInstance
(
Long
sdkAppId
,
String
userId
,
String
key
)
{
public
static
IMClient
getInstance
(
Long
sdkAppId
,
String
userId
,
String
key
)
{
String
identify
=
sdkAppId
+
"_"
+
userId
;
String
identify
=
sdkAppId
+
"_"
+
userId
;
if
(
IM_CLIENT
.
get
(
identify
)
==
null
)
{
if
(
!
IM_CLIENT
.
containsKey
(
identify
)
)
{
IM_CLIENT
.
putIfAbsent
(
identify
,
new
IMClient
(
sdkAppId
,
userId
,
key
,
24
*
60
*
60L
));
IM_CLIENT
.
putIfAbsent
(
identify
,
new
IMClient
(
sdkAppId
,
userId
,
key
));
}
}
return
IM_CLIENT
.
get
(
identify
);
return
IM_CLIENT
.
get
(
identify
);
}
}
public
IMClient
(
Long
sdkAppId
,
String
userId
,
String
key
,
Long
expire
)
{
public
IMClient
(
Long
sdkAppId
,
String
userId
,
String
key
)
{
this
.
sdkAppId
=
sdkAppId
;
this
.
sdkAppId
=
sdkAppId
;
this
.
userId
=
userId
;
this
.
userId
=
userId
;
this
.
userSig
=
SigUtil
.
genUserSig
(
sdkAppId
,
key
,
userId
,
expire
);
this
.
key
=
key
;
this
.
userSig
=
SigUtil
.
genUserSig
(
sdkAppId
,
key
,
userId
,
EXPIRE_TIME
);
this
.
userSigExpireTs
=
System
.
currentTimeMillis
()
/
1000
+
EXPIRE_TIME
-
100
;
account
=
new
Account
(
this
);
account
=
new
Account
(
this
);
message
=
new
Message
(
this
);
message
=
new
Message
(
this
);
member
=
new
Member
(
this
);
member
=
new
Member
(
this
);
...
@@ -66,8 +64,22 @@ public class IMClient {
...
@@ -66,8 +64,22 @@ public class IMClient {
public
String
getUrl
(
String
serviceName
,
String
command
)
{
public
String
getUrl
(
String
serviceName
,
String
command
)
{
// 随机生成32位无符号整数
// 随机生成32位无符号整数
long
random
=
ThreadLocalRandom
.
current
().
nextLong
(
0
,
0x100000000
L
);
long
random
=
ThreadLocalRandom
.
current
().
nextLong
(
0
,
0x100000000
L
);
return
String
.
format
(
FORMAT_URL
,
this
.
version
,
serviceName
,
command
,
String
sig
=
getUserSig
();
this
.
sdkAppId
,
this
.
userId
,
this
.
userSig
,
random
);
return
String
.
format
(
FORMAT_URL
,
VERSION
,
serviceName
,
command
,
sdkAppId
,
userId
,
sig
,
random
);
}
private
String
getUserSig
()
{
long
currentTs
=
System
.
currentTimeMillis
()
/
1000
;
if
(
currentTs
>=
userSigExpireTs
)
{
synchronized
(
this
)
{
if
(
currentTs
>=
userSigExpireTs
)
{
userSig
=
SigUtil
.
genUserSig
(
sdkAppId
,
key
,
userId
,
EXPIRE_TIME
);
userSigExpireTs
=
currentTs
+
EXPIRE_TIME
-
100
;
}
}
}
return
userSig
;
}
}
@Override
@Override
...
...
src/main/java/io/github/doocs/im/model/response/GenericResult.java
View file @
4fb1d062
...
@@ -51,7 +51,7 @@ public abstract class GenericResult {
...
@@ -51,7 +51,7 @@ public abstract class GenericResult {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"
Generic
Result{"
+
return
"Result{"
+
"actionStatus='"
+
actionStatus
+
'\''
+
"actionStatus='"
+
actionStatus
+
'\''
+
", errorInfo='"
+
errorInfo
+
'\''
+
", errorInfo='"
+
errorInfo
+
'\''
+
", errorCode='"
+
errorCode
+
'\''
+
", errorCode='"
+
errorCode
+
'\''
+
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment