最近公司要做一个基于新网的API,在自己的系统中实现实时查询域名注册情况,并且要能实时注册,注册费用自动从我们的代理帐户中扣除,下面是我写的核心实现类代码:
public class XinNetApiBase
{
//默认代理编号
public readonly static string AgentID = "agent88888";
private Encoding _WebEncode = Encoding.GetEncoding("UTF-8");
private string _RequestString;
private string _Result;
private string _RequestUrl;
private WebClient _EWebClient = new WebClient();
/// <summary>
/// 处理编码
{
//默认代理编号
public readonly static string AgentID = "agent88888";
private Encoding _WebEncode = Encoding.GetEncoding("UTF-8");
private string _RequestString;
private string _Result;
private string _RequestUrl;
private WebClient _EWebClient = new WebClient();
/// <summary>
/// 处理编码
/// </summary>
public Encoding WebEncode
{
get { return _WebEncode; }
set { _WebEncode = value; }
}
/// <summary>
/// 请求的查询参数
/// </summary>
public string RequestString
{
get { return _RequestString; }
set { _RequestString = value; }
}
public Encoding WebEncode
{
get { return _WebEncode; }
set { _WebEncode = value; }
}
/// <summary>
/// 请求的查询参数
/// </summary>
public string RequestString
{
get { return _RequestString; }
set { _RequestString = value; }
}
/// <summary>
/// 请求返回的结果
/// </summary>
public string Result
{
get { return _Result; }
set { _Result = value; }
}
/// <summary>
/// 请求的URL地址
/// </summary>
public string RequestUrl
{
get { return _RequestUrl; }
set { _RequestUrl = value; }
}
/// <summary>
/// 客户端与服务器通信类
/// </summary>
public WebClient EWebClient
{
get { return _EWebClient; }
set { _EWebClient = value; }
}
public XinNetApiBase(ApiType _apitype, List<QueryParam> _list)
get { return _RequestUrl; }
set { _RequestUrl = value; }
}
/// <summary>
/// 客户端与服务器通信类
/// </summary>
public WebClient EWebClient
{
get { return _EWebClient; }
set { _EWebClient = value; }
}
public XinNetApiBase(ApiType _apitype, List<QueryParam> _list)
{
this.RequestUrl = GetApiUrl(_apitype);
this.RequestString = GetRequestString(_list);
this.GetHttp();
}
public XinNetApiBase(string _ApiUrl, List<QueryParam> _list)
{
this.RequestUrl = _ApiUrl;
this.RequestString = GetRequestString(_list);
}
public string GetRequestString(List<QueryParam> list)
{
string requestUrl = "";
this.RequestUrl = GetApiUrl(_apitype);
this.RequestString = GetRequestString(_list);
this.GetHttp();
}
public XinNetApiBase(string _ApiUrl, List<QueryParam> _list)
{
this.RequestUrl = _ApiUrl;
this.RequestString = GetRequestString(_list);
}
public string GetRequestString(List<QueryParam> list)
{
string requestUrl = "";
foreach (QueryParam q in list)
{
requestUrl += q.QueryName + "=" + HttpUtility.UrlEncode(q.QueryValue, this.WebEncode) + "&";
}
return requestUrl.TrimEnd('&');
}
public string GetHttp()
{
this.EWebClient.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
this.EWebClient.Encoding = this.WebEncode;
{
requestUrl += q.QueryName + "=" + HttpUtility.UrlEncode(q.QueryValue, this.WebEncode) + "&";
}
return requestUrl.TrimEnd('&');
}
public string GetHttp()
{
this.EWebClient.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
this.EWebClient.Encoding = this.WebEncode;
this.Result = this.EWebClient.UploadString(new Uri(this.RequestUrl), "POST", this.RequestString);
return this.Result;
}
public string GetApiUrl(ApiType _ApiType)
{
string _Url = "";
switch (_ApiType)
{
case ApiType.Check:
_Url = "api.xinnet/domain/api.gb?method=check&charset=utf-8";
return this.Result;
}
public string GetApiUrl(ApiType _ApiType)
{
string _Url = "";
switch (_ApiType)
{
case ApiType.Check:
_Url = "api.xinnet/domain/api.gb?method=check&charset=utf-8";
break;
case ApiType.Register:
_Url = "api.xinnet/domain/api.gb?method=Register&charset=utf-8";
break;
case ApiType.Status:
_Url = "api.xinnet/domain/api.gb?method=Status&charset=utf-8";
break;
case ApiType.ModDns:
_Url = "api.xinnet/domain/api.gb?method=ModDns&charset=utf-8";
break;
case ApiType.domain:
_Url = "api.xinnet/domain/api.gb?method=DomainRenew&charset=utf-8";
case ApiType.Register:
_Url = "api.xinnet/domain/api.gb?method=Register&charset=utf-8";
break;
case ApiType.Status:
_Url = "api.xinnet/domain/api.gb?method=Status&charset=utf-8";
break;
case ApiType.ModDns:
_Url = "api.xinnet/domain/api.gb?method=ModDns&charset=utf-8";
break;
case ApiType.domain:
_Url = "api.xinnet/domain/api.gb?method=DomainRenew&charset=utf-8";
break;
case ApiType.GetProductKey:
_Url = "api.xinnet/domain/api.gb?method=GetProductKey&charset=utf-8";
break;
case ApiType.ChangeProductKey:
_Url = "api.xinnet/domain/api.gb?method=ChangeProductKey&charset=utf-8";
break;
case ApiType.ModifyContactor:
_Url = "api.xinnet/domain/api.gb?method=ModifyContactor&charset=utf-8";
break;
default:
_Url = "api.xinnet/domain/api.gb?method=testmd5&charset=utf-8";
case ApiType.GetProductKey:
_Url = "api.xinnet/domain/api.gb?method=GetProductKey&charset=utf-8";
break;
case ApiType.ChangeProductKey:
_Url = "api.xinnet/domain/api.gb?method=ChangeProductKey&charset=utf-8";
break;
case ApiType.ModifyContactor:
_Url = "api.xinnet/domain/api.gb?method=ModifyContactor&charset=utf-8";
break;
default:
_Url = "api.xinnet/domain/api.gb?method=testmd5&charset=utf-8";
break;
}
return _Url;
}
/// <summary>
/// MD5加密
/// </summary>
/// <param name="_ConvertString">加密的内容</param>
/// <param name="_Len">16或32 表示16位或32位</param>
/// <returns></returns>
public static string MD5(string _ConvertString, int _Len)
{
using (System.Security.Cryptography.MD5CryptoServiceProvider provider = new
}
return _Url;
}
/// <summary>
/// MD5加密
/// </summary>
/// <param name="_ConvertString">加密的内容</param>
/// <param name="_Len">16或32 表示16位或32位</param>
/// <returns></returns>
public static string MD5(string _ConvertString, int _Len)
{
using (System.Security.Cryptography.MD5CryptoServiceProvider provider = new
System.Security.Cryptography.MD5CryptoServiceProvider())
{
switch (_Len)
{
case 16:
return BitConverter.ToString(provider.ComputeHash(Encoding.UTF8.GetBytes(_ConvertString)), 4, 8).Replace("-", string.Empty).ToUpper(System.Globalization.CultureInfo.CurrentCulture);
case 32:
return BitConverter.ToString(provider.ComputeHash(Encoding.UTF8.GetBytes(_ConvertString))).Replace("-", string.Empty).ToUpper(System.Globalization.CultureInfo.CurrentCulture);
{
switch (_Len)
{
case 16:
return BitConverter.ToString(provider.ComputeHash(Encoding.UTF8.GetBytes(_ConvertString)), 4, 8).Replace("-", string.Empty).ToUpper(System.Globalization.CultureInfo.CurrentCulture);
case 32:
return BitConverter.ToString(provider.ComputeHash(Encoding.UTF8.GetBytes(_ConvertString))).Replace("-", string.Empty).ToUpper(System.Globalization.CultureInfo.CurrentCulture);
default:
return BitConverter.ToString(provider.ComputeHash(Encoding.UTF8.GetBytes(_ConvertString))).Replace("-", string.Empty).ToUpper(System.Globalization.CultureInfo.CurrentCulture);
}
}
}
}
public class QueryParam
{
private string _QueryName;
return BitConverter.ToString(provider.ComputeHash(Encoding.UTF8.GetBytes(_ConvertString))).Replace("-", string.Empty).ToUpper(System.Globalization.CultureInfo.CurrentCulture);
}
}
}
}
public class QueryParam
{
private string _QueryName;
private string _QueryValue;
public string QueryName
{
set { this._QueryName = value; }
get { return this._QueryName; }
}
public string QueryValue
{
set { this._QueryValue = value; }
get { return this._QueryValue; }
}
public QueryParam(string _Name, string _Value)
public string QueryName
{
set { this._QueryName = value; }
get { return this._QueryName; }
}
public string QueryValue
{
set { this._QueryValue = value; }
get { return this._QueryValue; }
}
public QueryParam(string _Name, string _Value)
{
this.QueryName = _Name;
this.QueryValue = _Value;
}
}
public enum ApiType
{在线url网址编码解码
Check,
Register,
Status,
ModDns,
domain,
GetProductKey,
this.QueryName = _Name;
this.QueryValue = _Value;
}
}
public enum ApiType
{在线url网址编码解码
Check,
Register,
Status,
ModDns,
domain,
GetProductKey,
ChangeProductKey,
ModifyContactor
}
ModifyContactor
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论