Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9023df6

Browse files
author
zhanq
committed
update jiguang-common version to 1.2.3.
1 parent 4e15661 commit 9023df6

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<dependency>
5252
<groupId>cn.jpush.api</groupId>
5353
<artifactId>jiguang-common</artifactId>
54-
<version>1.2.2</version>
54+
<version>1.2.3</version>
5555
</dependency>
5656
<dependency>
5757
<groupId>org.apache.httpcomponents</groupId>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package cn.jpush.api.files;
2+
3+
import cn.jiguang.common.ClientConfig;
4+
import cn.jiguang.common.ServiceHelper;
5+
import cn.jiguang.common.connection.HttpProxy;
6+
import cn.jiguang.common.connection.IHttpClient;
7+
import cn.jiguang.common.connection.NativeHttpClient;
8+
import cn.jiguang.common.resp.APIConnectionException;
9+
import cn.jiguang.common.resp.APIRequestException;
10+
import cn.jiguang.common.resp.ResponseWrapper;
11+
import cn.jiguang.common.utils.Preconditions;
12+
import cn.jiguang.common.utils.StringUtils;
13+
import cn.jpush.api.file.model.FileModel;
14+
import cn.jpush.api.file.model.FileModelPage;
15+
import cn.jpush.api.file.model.FileType;
16+
import cn.jpush.api.file.model.FileUploadResult;
17+
import com.google.gson.Gson;
18+
import com.google.gson.reflect.TypeToken;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
25+
/**
26+
* @author daixuan
27+
* @version 2020年2月23日 19:38
28+
*/
29+
public class FileClient2 {
30+
31+
protected static final Logger LOG = LoggerFactory.getLogger(FileClient2.class);
32+
33+
private IHttpClient _httpClient;
34+
private String _baseUrl;
35+
private String _filesPath;
36+
private Gson _gson = new Gson();
37+
38+
public FileClient2(String masterSecret, String appKey) {
39+
this(masterSecret, appKey, null, ClientConfig.getInstance());
40+
}
41+
42+
public FileClient2(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) {
43+
_baseUrl = (String) conf.get(ClientConfig.PUSH_HOST_NAME);
44+
_filesPath = (String) conf.get(ClientConfig.V3_FILES_PATH);
45+
String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
46+
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
47+
}
48+
49+
public String uploadFile(FileType type, String filename, Integer ttl)
50+
throws APIConnectionException, APIRequestException {
51+
Preconditions.checkArgument(type != null, "type should not be null");
52+
Preconditions.checkArgument(StringUtils.isNotEmpty(filename), "filename should not be null");
53+
Preconditions.checkArgument(ttl >= 1 && ttl <= 720,"TTL is not in the range of 1 to 720");
54+
NativeHttpClient client = (NativeHttpClient) _httpClient;
55+
String typeStr = type.value();
56+
String url = _baseUrl + _filesPath + "/" + typeStr;
57+
Map<String, String> fileMap = new HashMap<String,String>();
58+
fileMap.put("filename", filename);
59+
Map<String, String> textMap = new HashMap<String,String>();
60+
textMap.put("ttl",String.valueOf(ttl));
61+
String response = client.formUploadByPost(url, textMap, fileMap, null);
62+
LOG.info("uploadFile:{}", response);
63+
return response;
64+
}
65+
66+
public String uploadFile(FileType type, String filename) throws APIConnectionException, APIRequestException {
67+
return uploadFile(type,filename,720);
68+
}
69+
70+
public String queryEffectFiles() throws APIConnectionException, APIRequestException {
71+
String url = _baseUrl + _filesPath + "/";
72+
ResponseWrapper response = _httpClient.sendGet(url);
73+
LOG.info("queryEffFiles:{}", response);
74+
return response.responseContent;
75+
}
76+
77+
public String queryFile(String fileId) throws APIConnectionException, APIRequestException {
78+
Preconditions.checkArgument(StringUtils.isNotEmpty(fileId), "fileId should not be null");
79+
String url = _baseUrl + _filesPath + "/" + fileId;
80+
ResponseWrapper response = _httpClient.sendGet(url);
81+
LOG.info("queryFile:{}", response);
82+
return response.responseContent;
83+
}
84+
85+
public ResponseWrapper deleteFile(String fileId) throws APIConnectionException, APIRequestException {
86+
Preconditions.checkArgument(StringUtils.isNotEmpty(fileId), "fileId should not be null");
87+
String url = _baseUrl + _filesPath + "/" + fileId;
88+
ResponseWrapper response = _httpClient.sendDelete(url);
89+
LOG.info("deleteFile:{}", response);
90+
return response;
91+
}
92+
}

‎src/test/java/cn/jpush/api/files/FileClientTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public void testQueryFile() {
7979
@Test
8080
public void testDeleteFile() {
8181
FileClient fileClient = new FileClient(MASTER_SECRET, APP_KEY);
82+
83+
8284
try {
8385
fileClient.deleteFile(fileId);
8486
} catch (APIConnectionException e) {
@@ -91,4 +93,8 @@ public void testDeleteFile() {
9193
LOG.info("Msg ID: " + e.getMsgId());
9294
}
9395
}
96+
97+
98+
99+
94100
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /