Files
2024-07-22 00:43:14 +08:00

179 lines
3.9 KiB
C#

using System.Collections.Generic;
using System.Net;
using DotNet.Utilities;
namespace AppleBatch_June.SMS
{
public class SmsYun : ISms
{
private string token { get; set; }
private string host { get; } = "";
public string channel { get; } = "1";
public string project_id { get; } = "1098";
public string smsCountry { get; set; } = "CN";
public string smsName => "SmsYun";
public string smsLink { get; set; }
public SmsYun(string _token, string _project_id, string _channel)
{
token = _token;
project_id = _project_id;
channel = _channel;
}
public SmsRespon getInfo()
{
string uRL = host + "api/get_myinfo?token=" + token;
HttpResult html = new HttpHelper().GetHtml(new HttpItem
{
URL = uRL,
Timeout = 10000
});
if (html.StatusCode == HttpStatusCode.OK)
{
return new SmsRespon
{
code = "0000",
ErrMessage = "",
Data = html.Html
};
}
return new SmsRespon
{
code = "9999",
ErrMessage = html.Html,
Data = html.Html
};
}
public SmsRespon getMolieNumber(ref string phone)
{
string text = "1";
string uRL = host + "api/get_mobile?token=" + token + "&project_id=" + project_id + "&channel=" + channel + "&operation=" + text + "&phone=" + phone;
HttpResult html = new HttpHelper().GetHtml(new HttpItem
{
URL = uRL,
Timeout = 10000
});
if (html.StatusCode == HttpStatusCode.OK)
{
Dictionary<string, object> dictionary = Tools.Todejosn<Dictionary<string, object>>(html.Html);
if ((int)(dynamic)dictionary["code"] == 200)
{
dynamic val = dictionary["data"];
phone = val["phone"];
return new SmsRespon
{
code = "0000",
ErrMessage = "ok",
Data = phone
};
}
string text2 = (dynamic)dictionary["msg"];
return new SmsRespon
{
code = "9999",
ErrMessage = "获取手机号码失败:" + text2,
Data = html.Html
};
}
return new SmsRespon
{
code = "9999",
ErrMessage = "error:获取手机号码返回:" + html.StatusCode,
Data = html.Html
};
}
public SmsRespon getSms(string phone)
{
string uRL = host + "api/get_sms?token=" + token + "&project_id=" + project_id + "&channel=" + channel + "&phone=" + phone;
HttpResult html = new HttpHelper().GetHtml(new HttpItem
{
URL = uRL,
Timeout = 10000
});
if (html.StatusCode == HttpStatusCode.OK)
{
Dictionary<string, object> dictionary = Tools.Todejosn<Dictionary<string, object>>(html.Html);
if ((int)(dynamic)dictionary["code"] == 200)
{
dynamic val = dictionary["text"];
return new SmsRespon
{
code = "0000",
ErrMessage = "ok",
Data = val
};
}
}
return new SmsRespon
{
code = "9999",
ErrMessage = "未收到",
Data = html.Html
};
}
public SmsRespon releasePhone(string phone)
{
string uRL = host + "api/release_phone?token=" + token + "&project_id=" + project_id + "&channel=" + channel + "&phone=" + phone;
HttpResult html = new HttpHelper().GetHtml(new HttpItem
{
URL = uRL,
Timeout = 10000
});
if (html.StatusCode == HttpStatusCode.OK)
{
return new SmsRespon
{
code = "0000",
ErrMessage = "",
Data = html.Html
};
}
return new SmsRespon
{
code = "9999",
ErrMessage = html.Html,
Data = html.Html
};
}
public SmsRespon blackPhone(string phone)
{
string uRL = host + "api/black_phone?token=" + token + "&project_id=" + project_id + "&channel=" + channel + "&phone=" + phone;
HttpResult html = new HttpHelper().GetHtml(new HttpItem
{
URL = uRL,
Timeout = 10000
});
if (html.StatusCode == HttpStatusCode.OK)
{
return new SmsRespon
{
code = "0000",
ErrMessage = "",
Data = html.Html
};
}
return new SmsRespon
{
code = "9999",
ErrMessage = html.Html,
Data = html.Html
};
}
}
}