Skip to content

Commit 46febff

Browse files
authored
Merge pull request #195 from jpush/feature/20220124_TS-7022
TS-7022 上传文件接口新增ttl字段,PC-5108 修复新生成JPushClinet会默认访问公有云的问题
2 parents ccef34d + 8cbd725 commit 46febff

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>cn.jpush.api</groupId>
55
<artifactId>jpush-client</artifactId>
6-
<version>3.6.0</version>
6+
<version>3.6.1</version>
77
<packaging>jar</packaging>
88
<url>https://github.com/jpush/jpush-api-java-client</url>
99
<name>JPush API Java Client</name>

src/main/java/cn/jpush/api/file/FileClient.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,28 @@ public FileClient(String masterSecret, String appKey, HttpProxy proxy, ClientCon
4646
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
4747
}
4848

49-
public FileUploadResult uploadFile(FileType type, String filename)
49+
public FileUploadResult uploadFile(FileType type, String filename, Integer ttl)
5050
throws APIConnectionException, APIRequestException {
5151
Preconditions.checkArgument(type != null, "type should not be null");
5252
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");
5354
NativeHttpClient client = (NativeHttpClient) _httpClient;
5455
String typeStr = type.value();
5556
String url = _baseUrl + _filesPath + "/" + typeStr;
5657
Map<String, String> fileMap = new HashMap<String,String>();
5758
fileMap.put("filename", filename);
59+
fileMap.put("ttl",String.valueOf(ttl));
5860
String response = client.formUploadByPost(url, null, fileMap, null);
5961
LOG.info("uploadFile:{}", response);
6062
return _gson.fromJson(response,
6163
new TypeToken<FileUploadResult>() {
6264
}.getType());
6365
}
6466

67+
public FileUploadResult uploadFile(FileType type, String filename) throws APIConnectionException, APIRequestException {
68+
return uploadFile(type,filename,720);
69+
}
70+
6571
public FileModelPage queryEffectFiles() throws APIConnectionException, APIRequestException {
6672
String url = _baseUrl + _filesPath + "/";
6773
ResponseWrapper response = _httpClient.sendGet(url);

src/main/java/cn/jpush/api/push/PushClient.java

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public PushClient(String masterSecret, String appKey) {
5757
this(masterSecret, appKey, null, ClientConfig.getInstance());
5858
}
5959

60+
public PushClient(String masterSecret, String appKey,ClientConfig clientConfig){
61+
this(masterSecret,appKey,null,clientConfig);
62+
}
63+
6064
/**
6165
* This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig} instead of this constructor.
6266
*

src/main/java/cn/jpush/api/schedule/ScheduleClient.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class ScheduleClient {
2323
private String hostName;
2424
private String schedulePath;
2525

26+
private PushClient pushClient;
27+
2628
// If not present, true by default.
2729
private int apnsProduction;
2830

@@ -81,6 +83,8 @@ public ScheduleClient(String masterSecret, String appKey, HttpProxy proxy, Clien
8183
schedulePath = (String) conf.get(ClientConfig.SCHEDULE_PATH);
8284
apnsProduction = (Integer) conf.get(ClientConfig.APNS_PRODUCTION);
8385
timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);
86+
//createSchedule接口需要用到这个类
87+
pushClient = new PushClient(masterSecret, appKey, conf);
8488

8589
String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
8690
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
@@ -104,7 +108,6 @@ public ScheduleResult createSchedule(SchedulePayload payload, String masterSecre
104108
// 调用getCidList方法来获取cid并赋值到payload中
105109
String cid = payload.getCid();
106110
if (cid == null) {
107-
PushClient pushClient = new PushClient(masterSecret, appKey);
108111
CIDResult cidResult = pushClient.getCidList(1 , "schedule");
109112
payload.setCid(cidResult.cidlist.get(0));
110113
}

src/test/java/cn/jpush/api/schedule/ScheduleClientTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ public void testGetScheduleList() {
6060
* Method: deleteSchedule(String scheduleId)
6161
*/
6262
@Test
63-
public void testScheduleMethods(String masterSecret, String appKey) {
63+
public void testScheduleMethods() {
64+
String masterSecret = MASTER_SECRET;
65+
String appKey = APP_KEY;
6466
String name = "test_schedule";
6567
TriggerPayload trigger = TriggerPayload.newBuilder()
66-
.setSingleTime("2105-07-30 12:00:00")
68+
.setSingleTime("2022-07-30 12:00:00")
6769
.buildSingle();
6870

6971
PushPayload push = PushPayload.alertAll("test schedule");

0 commit comments

Comments
 (0)