@@ -9,7 +9,19 @@ namespace Jiguang.JPush
99{
1010 public class ScheduleClient
1111 {
12- private const string BASE_URL = "https://api.jpush.cn" ;
12+ public const string BASE_URL_SCHEDULE_DEFAULT = "https://api.jpush.cn/v3/schedules" ;
13+ public const string BASE_URL_SCHEDULE_BEIJING = "https://bjapi.push.jiguang.cn/v3/push/schedules" ;
14+
15+ private string BASE_URL = BASE_URL_SCHEDULE_DEFAULT ;
16+
17+ /// <summary>
18+ /// 设置 Schedule API 的调用地址。
19+ /// </summary>
20+ /// <param name="url"><see cref="BASE_URL_SCHEDULE_DEFAULT"/> or <see cref="BASE_URL_SCHEDULE_BEIJING"/></param>
21+ public void SetBaseURL ( string url )
22+ {
23+ BASE_URL = url ;
24+ }
1325
1426 /// <summary>
1527 /// 创建定时任务。
@@ -23,9 +35,8 @@ public async Task<HttpResponse> CreateScheduleTaskAsync(string json)
2335 if ( string . IsNullOrEmpty ( json ) )
2436 throw new ArgumentNullException ( nameof ( json ) ) ;
2537
26- var url = BASE_URL + "/v3/schedules" ;
2738 HttpContent requestContent = new StringContent ( json , Encoding . UTF8 ) ;
28- HttpResponseMessage msg = await JPushClient . HttpClient . PostAsync ( url , requestContent ) . ConfigureAwait ( false ) ;
39+ HttpResponseMessage msg = await JPushClient . HttpClient . PostAsync ( BASE_URL , requestContent ) . ConfigureAwait ( false ) ;
2940 string responseContent = await msg . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
3041 return new HttpResponse ( msg . StatusCode , msg . Headers , responseContent ) ;
3142 }
@@ -124,7 +135,7 @@ public async Task<HttpResponse> GetValidScheduleTasksAsync(int page = 1)
124135 if ( page <= 0 )
125136 throw new ArgumentNullException ( nameof ( page ) ) ;
126137
127- var url = BASE_URL + "/v3/schedules ?page=" + page ;
138+ var url = BASE_URL + "?page=" + page ;
128139 HttpResponseMessage msg = await JPushClient . HttpClient . GetAsync ( url ) . ConfigureAwait ( false ) ;
129140 string responseContent = await msg . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
130141 return new HttpResponse ( msg . StatusCode , msg . Headers , responseContent ) ;
@@ -154,7 +165,7 @@ public async Task<HttpResponse> GetScheduleTaskAsync(string scheduleId)
154165 if ( string . IsNullOrEmpty ( scheduleId ) )
155166 throw new ArgumentNullException ( nameof ( scheduleId ) ) ;
156167
157- var url = BASE_URL + "/v3/schedules/" + scheduleId ;
168+ var url = BASE_URL + $ "/ { scheduleId } " ;
158169 HttpResponseMessage msg = await JPushClient . HttpClient . GetAsync ( url ) . ConfigureAwait ( false ) ;
159170 string responseContent = await msg . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
160171 return new HttpResponse ( msg . StatusCode , msg . Headers , responseContent ) ;
@@ -179,7 +190,7 @@ public async Task<HttpResponse> UpdateScheduleTaskAsync(string scheduleId, strin
179190 if ( string . IsNullOrEmpty ( json ) )
180191 throw new ArgumentNullException ( nameof ( json ) ) ;
181192
182- var url = BASE_URL + "/v3/schedules/" + scheduleId ;
193+ var url = BASE_URL + $ "/ { scheduleId } " ;
183194 HttpContent requestContent = new StringContent ( json , Encoding . UTF8 ) ;
184195 HttpResponseMessage msg = await JPushClient . HttpClient . PutAsync ( url , requestContent ) . ConfigureAwait ( false ) ;
185196 string responseContent = await msg . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
@@ -294,7 +305,7 @@ public async Task<HttpResponse> DeleteScheduleTaskAsync(string scheduleId)
294305 if ( string . IsNullOrEmpty ( scheduleId ) )
295306 throw new ArgumentNullException ( nameof ( scheduleId ) ) ;
296307
297- var url = BASE_URL + "/v3/schedules/" + scheduleId ;
308+ var url = BASE_URL + $ "/ { scheduleId } " ;
298309 HttpResponseMessage msg = await JPushClient . HttpClient . DeleteAsync ( url ) . ConfigureAwait ( false ) ;
299310 string responseContent = await msg . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
300311 return new HttpResponse ( msg . StatusCode , msg . Headers , responseContent ) ;
0 commit comments