Skip to content

Commit 9815e25

Browse files
committed
add im sdk
1 parent f5cc9f6 commit 9815e25

20 files changed

+58
-787
lines changed

config/robot.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
robot.im_id=FireRobot
22
robot.im_name=小火
3-
robot.im_url=http://localhost:18080
3+
robot.im_url=http://localhost
44
robot.im_secret=123456
55

66
robot.use_tuling=true

pom.xml

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>cn.wildfirechat</groupId>
77
<artifactId>robot</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
8+
<version>0.21</version>
99
<packaging>jar</packaging>
1010

1111
<name>robot</name>
@@ -41,24 +41,6 @@
4141
<scope>test</scope>
4242
</dependency>
4343

44-
<dependency>
45-
<groupId>com.google.code.gson</groupId>
46-
<artifactId>gson</artifactId>
47-
<version>2.8.2</version>
48-
</dependency>
49-
50-
<dependency>
51-
<groupId>commons-io</groupId>
52-
<artifactId>commons-io</artifactId>
53-
<version>2.5</version>
54-
</dependency>
55-
56-
<dependency>
57-
<groupId>com.googlecode.json-simple</groupId>
58-
<artifactId>json-simple</artifactId>
59-
<version>1.1.1</version>
60-
</dependency>
61-
6244
<dependency>
6345
<groupId>org.slf4j</groupId>
6446
<artifactId>slf4j-api</artifactId>
@@ -71,6 +53,11 @@
7153
<version>1.7.5</version>
7254
</dependency>
7355

56+
<dependency>
57+
<groupId>com.google.code.gson</groupId>
58+
<artifactId>gson</artifactId>
59+
<version>2.8.2</version>
60+
</dependency>
7461

7562
<dependency>
7663
<groupId>commons-httpclient</groupId>
@@ -79,31 +66,38 @@
7966
</dependency>
8067

8168
<dependency>
82-
<groupId>uk.org.lidalia</groupId>
83-
<artifactId>slf4j-test</artifactId>
84-
<version>1.0.0-jdk6</version>
85-
<scope>test</scope>
69+
<groupId>org.apache.httpcomponents</groupId>
70+
<artifactId>httpclient</artifactId>
71+
<version>4.5.3</version>
8672
</dependency>
8773

8874
<dependency>
89-
<groupId>com.google.code.findbugs</groupId>
90-
<artifactId>annotations</artifactId>
91-
<version>2.0.3</version>
92-
<scope>provided</scope>
75+
<groupId>commons-codec</groupId>
76+
<artifactId>commons-codec</artifactId>
77+
<version>1.11</version>
78+
<scope>compile</scope>
9379
</dependency>
9480

9581
<dependency>
96-
<groupId>org.mockito</groupId>
97-
<artifactId>mockito-all</artifactId>
98-
<version>1.9.5</version>
99-
<type>jar</type>
100-
<scope>test</scope>
82+
<groupId>com.google.protobuf</groupId>
83+
<artifactId>protobuf-java</artifactId>
84+
<version>2.5.0</version>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>cn.wildfirechat</groupId>
89+
<artifactId>sdk</artifactId>
90+
<version>${project.version}</version>
91+
<scope>system</scope>
92+
<systemPath>${project.basedir}/src/lib/sdk-${project.version}.jar</systemPath>
10193
</dependency>
10294

10395
<dependency>
104-
<groupId>com.github.qcloudsms</groupId>
105-
<artifactId>qcloudsms</artifactId>
106-
<version>1.0.5</version>
96+
<groupId>cn.wildfirechat</groupId>
97+
<artifactId>common</artifactId>
98+
<version>${project.version}</version>
99+
<scope>system</scope>
100+
<systemPath>${project.basedir}/src/lib/common-${project.version}.jar</systemPath>
107101
</dependency>
108102

109103
</dependencies>
@@ -113,6 +107,9 @@
113107
<plugin>
114108
<groupId>org.springframework.boot</groupId>
115109
<artifactId>spring-boot-maven-plugin</artifactId>
110+
<configuration>
111+
<includeSystemScope>true</includeSystemScope>
112+
</configuration>
116113
</plugin>
117114
</plugins>
118115
</build>

robot.iml

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/lib/common-0.21.jar

787 KB
Binary file not shown.

src/lib/sdk-0.21.jar

32.2 KB
Binary file not shown.

src/main/java/cn/wildfirechat/app/Controller.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cn.wildfirechat.app;
22

3-
import cn.wildfirechat.app.pojo.LoginRequest;
4-
import cn.wildfirechat.app.pojo.SendCodeRequest;
5-
import cn.wildfirechat.sdk.model.SendMessageData;
3+
import cn.wildfirechat.pojos.SendMessageData;
64
import org.springframework.beans.factory.annotation.Autowired;
75
import org.springframework.web.bind.annotation.PostMapping;
86
import org.springframework.web.bind.annotation.RequestBody;

src/main/java/cn/wildfirechat/sdk/HttpUtils.java renamed to src/main/java/cn/wildfirechat/app/HttpUtils.java

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cn.wildfirechat.sdk;
1+
package cn.wildfirechat.app;
22

33
import cn.wildfirechat.sdk.model.IMResult;
44
import com.google.gson.Gson;
@@ -10,7 +10,6 @@
1010
import org.apache.http.client.methods.HttpPost;
1111
import org.apache.http.entity.StringEntity;
1212
import org.apache.http.impl.client.HttpClientBuilder;
13-
import org.apache.http.params.CoreConnectionPNames;
1413
import org.slf4j.Logger;
1514
import org.slf4j.LoggerFactory;
1615

@@ -23,87 +22,7 @@
2322
public class HttpUtils {
2423
private static final Logger LOG = LoggerFactory.getLogger(HttpUtils.class);
2524

26-
private static String robotId;
27-
private static String adminUrl;
28-
private static String adminSecret;
29-
30-
static void init(String rid, String url, String secret) {
31-
robotId = rid;
32-
adminUrl = url;
33-
adminSecret = secret;
34-
}
35-
36-
static <T> IMResult<T> IMPost(String path, Object object, Class<T> clazz) throws Exception{
37-
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(path)) {
38-
LOG.error("Not init IM SDK correctly. Do you forget init it?");
39-
throw new Exception("SDK url or secret lack!");
40-
}
41-
42-
String url = adminUrl + path;
43-
HttpPost post = null;
44-
try {
45-
HttpClient httpClient = HttpClientBuilder.create().build();
46-
47-
int nonce = (int)(Math.random() * 100000 + 3);
48-
long timestamp = System.currentTimeMillis();
49-
String str = nonce + "|" + adminSecret + "|" + timestamp;
50-
String sign = DigestUtils.sha1Hex(str);
51-
52-
53-
post = new HttpPost(url);
54-
post.setHeader("Content-type", "application/json; charset=utf-8");
55-
post.setHeader("Connection", "Keep-Alive");
56-
post.setHeader("nonce", nonce + "");
57-
post.setHeader("timestamp", "" + timestamp);
58-
post.setHeader("sign", sign);
59-
post.setHeader("rid", robotId);
60-
61-
String jsonStr = new Gson().toJson(object);
62-
LOG.info("http request content: {}", jsonStr);
63-
64-
StringEntity entity = new StringEntity(jsonStr, Charset.forName("UTF-8"));
65-
entity.setContentEncoding("UTF-8");
66-
entity.setContentType("application/json");
67-
post.setEntity(entity);
68-
HttpResponse response = httpClient.execute(post);
69-
70-
int statusCode = response.getStatusLine().getStatusCode();
71-
if(statusCode != HttpStatus.SC_OK){
72-
LOG.info("Request error: "+statusCode);
73-
throw new Exception("Http request error with code:" + statusCode);
74-
}else{
75-
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity()
76-
.getContent(),"utf-8"));
77-
StringBuffer sb = new StringBuffer();
78-
String line;
79-
String NL = System.getProperty("line.separator");
80-
while ((line = in.readLine()) != null) {
81-
sb.append(line + NL);
82-
}
83-
84-
in.close();
85-
86-
String content = sb.toString();
87-
LOG.info("http request response content: {}", content);
88-
89-
return fromJsonObject(content, clazz);
90-
}
91-
} catch (Exception e) {
92-
e.printStackTrace();
93-
throw e;
94-
}finally{
95-
if(post != null){
96-
post.releaseConnection();
97-
}
98-
}
99-
}
100-
10125
static public <T> T post(String url, Object object, Class<T> clazz) throws Exception{
102-
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(url)) {
103-
LOG.error("Not init IM SDK correctly. Do you forget init it?");
104-
throw new Exception("SDK url or secret lack!");
105-
}
106-
10726

10827
HttpPost post = null;
10928
try {

src/main/java/cn/wildfirechat/app/Service.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cn.wildfirechat.app;
22

33

4-
import cn.wildfirechat.sdk.model.SendMessageData;
4+
import cn.wildfirechat.pojos.SendMessageData;
55

66
public interface Service {
77
RestResult onReceiveMessage(SendMessageData messageData);

0 commit comments

Comments
 (0)