216 lines
8.8 KiB
C#
216 lines
8.8 KiB
C#
|
|
using System;
|
|||
|
|
using AlibabaCloud.OpenApiClient.Models;
|
|||
|
|
using AlibabaCloud.SDK.AliGenieip_1_0;
|
|||
|
|
using AlibabaCloud.SDK.AliGenieip_1_0.Models;
|
|||
|
|
|
|||
|
|
namespace AliAPI
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 阿里api处理类
|
|||
|
|
/// </summary>
|
|||
|
|
public static class AliOpenApiHelper
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 创建访问客户端
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="accessKeyId"></param>
|
|||
|
|
/// <param name="accessKeySecret"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private static Client CreateClient(string accessKeyId, string accessKeySecret)
|
|||
|
|
{
|
|||
|
|
Config config = new Config
|
|||
|
|
{
|
|||
|
|
AccessKeyId = accessKeyId,
|
|||
|
|
AccessKeySecret = accessKeySecret,
|
|||
|
|
};
|
|||
|
|
config.Endpoint = "openapi.aligenie.com";//访问的域名
|
|||
|
|
return new Client(config);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 自定义场景上报
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="accessKeyId"></param>
|
|||
|
|
/// <param name="accessKeySecret"></param>
|
|||
|
|
/// <param name="jsonData"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static APIResultEntity PostCustomScene(string accessKeyId, string accessKeySecret, string jsonData)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(accessKeyId))
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, "accessKeyId不能为空");
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(accessKeySecret))
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, "accessKeySecret不能为空");
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(jsonData))
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, "jsonData不能为空");
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Client client = CreateClient(accessKeyId, accessKeySecret);
|
|||
|
|
ImportHotelConfigRequest req = Newtonsoft.Json.JsonConvert.DeserializeObject<ImportHotelConfigRequest>(jsonData);
|
|||
|
|
ImportHotelConfigResponse resp = client.ImportHotelConfig(req);
|
|||
|
|
return ReturnResult((bool)resp.Body.Result, resp.Body.Message, Newtonsoft.Json.JsonConvert.SerializeObject(resp.Body));
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, ex.Message, ex.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 退房重置
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="accessKeyId"></param>
|
|||
|
|
/// <param name="accessKeySecret"></param>
|
|||
|
|
/// <param name="jsonData"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static APIResultEntity CheckoutWithAK(string accessKeyId, string accessKeySecret, string jsonData)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(accessKeyId))
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, "accessKeyId不能为空");
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(accessKeySecret))
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, "accessKeySecret不能为空");
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(jsonData))
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, "jsonData不能为空");
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Client client = CreateClient(accessKeyId, accessKeySecret);
|
|||
|
|
CheckoutWithAKRequest req = Newtonsoft.Json.JsonConvert.DeserializeObject<CheckoutWithAKRequest>(jsonData);
|
|||
|
|
CheckoutWithAKResponse resp = client.CheckoutWithAK(req);
|
|||
|
|
return ReturnResult((bool)resp.Body.Result, resp.Body.Message, Newtonsoft.Json.JsonConvert.SerializeObject(resp.Body));
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, ex.Message, ex.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 推送并直接播报欢迎词
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="accessKeyId"></param>
|
|||
|
|
/// <param name="accessKeySecret"></param>
|
|||
|
|
/// <param name="jsonData"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static APIResultEntity PushWelcome(string accessKeyId, string accessKeySecret, string jsonData)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(accessKeyId))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "accessKeyId不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(accessKeySecret))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "accessKeySecret不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(jsonData))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "jsonData不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Client client = CreateClient(accessKeyId, accessKeySecret);
|
|||
|
|
PushWelcomeRequest req = Newtonsoft.Json.JsonConvert.DeserializeObject<PushWelcomeRequest>(jsonData);
|
|||
|
|
PushWelcomeResponse resp = client.PushWelcome(req);
|
|||
|
|
return ReturnResult((bool)resp.Body.Result, resp.Body.Message, Newtonsoft.Json.JsonConvert.SerializeObject(resp.Body));
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, ex.Message, ex.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置欢迎词
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="accessKeyId"></param>
|
|||
|
|
/// <param name="accessKeySecret"></param>
|
|||
|
|
/// <param name="jsonData"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static APIResultEntity AddOrUpdateWelcomeText(string accessKeyId, string accessKeySecret, string jsonData)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(accessKeyId))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "accessKeyId不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(accessKeySecret))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "accessKeySecret不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(jsonData))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "jsonData不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Client client = CreateClient(accessKeyId, accessKeySecret);
|
|||
|
|
AddOrUpdateWelcomeTextRequest req = Newtonsoft.Json.JsonConvert.DeserializeObject<AddOrUpdateWelcomeTextRequest>(jsonData);
|
|||
|
|
AddOrUpdateWelcomeTextResponse resp = client.AddOrUpdateWelcomeText(req);
|
|||
|
|
return ReturnResult((bool)resp.Body.Result, resp.Body.Message, Newtonsoft.Json.JsonConvert.SerializeObject(resp.Body));
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, ex.Message, ex.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 播报欢迎词
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="accessKeyId"></param>
|
|||
|
|
/// <param name="accessKeySecret"></param>
|
|||
|
|
/// <param name="jsonData"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static APIResultEntity PushWelcomeTextAndMusic(string accessKeyId, string accessKeySecret, string jsonData)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(accessKeyId))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "accessKeyId不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(accessKeySecret))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "accessKeySecret不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(jsonData))
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = false, msg = "jsonData不能为空", data = "" };
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Client client = CreateClient(accessKeyId, accessKeySecret);
|
|||
|
|
PushWelcomeTextAndMusicRequest req = Newtonsoft.Json.JsonConvert.DeserializeObject<PushWelcomeTextAndMusicRequest>(jsonData);
|
|||
|
|
PushWelcomeTextAndMusicResponse resp = client.PushWelcomeTextAndMusic(req);
|
|||
|
|
return ReturnResult((bool)resp.Body.Result, resp.Body.Message, Newtonsoft.Json.JsonConvert.SerializeObject(resp.Body));
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return ReturnResult(false, ex.Message, ex.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static APIResultEntity ReturnResult(bool result, string msg, string data = "")
|
|||
|
|
{
|
|||
|
|
return new APIResultEntity() { result = result, msg = msg, data = data };
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public class APIResultEntity
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 结果:true成功,false失败
|
|||
|
|
/// </summary>
|
|||
|
|
public bool result { get; set; }
|
|||
|
|
/// <summary>
|
|||
|
|
/// 提示信息
|
|||
|
|
/// </summary>
|
|||
|
|
public string msg { get; set; }
|
|||
|
|
/// <summary>
|
|||
|
|
/// 返回数据
|
|||
|
|
/// </summary>
|
|||
|
|
public string data { get; set; }
|
|||
|
|
}
|
|||
|
|
}
|