chore: 支持切换云引擎环境

oneRain 2020-06-29 11:28:21 +08:00
parent 41abc2e4ff
commit 08ed1c240c
1 changed files with 17 additions and 0 deletions

View File

@ -7,6 +7,15 @@ namespace LeanCloud.Storage {
/// 云引擎
/// </summary>
public static class LCCloud {
private const string PRODUCTION_KEY = "X-LC-Prod";
/// <summary>
/// 是否是生产环境,默认为 true
/// </summary>
public static bool IsProduction {
get; set;
} = true;
/// <summary>
/// 调用云函数
/// </summary>
@ -16,8 +25,12 @@ namespace LeanCloud.Storage {
public static async Task<Dictionary<string, object>> Run(string name,
Dictionary<string, object> parameters = null) {
string path = $"functions/{name}";
Dictionary<string, object> headers = new Dictionary<string, object> {
{ PRODUCTION_KEY, IsProduction ? 1 : 0 }
};
object encodeParams = LCEncoder.Encode(parameters);
Dictionary<string, object> response = await LCApplication.HttpClient.Post<Dictionary<string, object>>(path,
headers: headers,
data: encodeParams);
return response;
}
@ -30,8 +43,12 @@ namespace LeanCloud.Storage {
/// <returns>返回类型为 LCObject 容器类型</returns>
public static async Task<object> RPC(string name, object parameters = null) {
string path = $"call/{name}";
Dictionary<string, object> headers = new Dictionary<string, object> {
{ PRODUCTION_KEY, IsProduction ? 1 : 0 }
};
object encodeParams = LCEncoder.Encode(parameters);
Dictionary<string, object> response = await LCApplication.HttpClient.Post<Dictionary<string, object>>(path,
headers: headers,
data: encodeParams);
return LCDecoder.Decode(response["result"]);
}