添加项目文件。
This commit is contained in:
132
XXCpzs/Helper/HttpHelper.cs
Normal file
132
XXCpzs/Helper/HttpHelper.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using XXCpzs.Models;
|
||||
|
||||
namespace XXCpzs.helper
|
||||
|
||||
{
|
||||
public class HttpHelper
|
||||
{
|
||||
public static async Task<ResultModel> RequestPost(int type, Dictionary<string, string> _body = null)
|
||||
{
|
||||
string _domain = string.Format(@"http://cpzs.xixingwl.cn/cpzs/Api/{0}.shtml", type);
|
||||
Console.WriteLine(">>>>" + _domain);
|
||||
var client = new RestClient
|
||||
{
|
||||
BaseUrl = new Uri(_domain),
|
||||
Timeout = 60000,
|
||||
//Authenticator = new HttpBasicAuthenticator("username", "password")
|
||||
};
|
||||
var request = new RestRequest
|
||||
{
|
||||
Timeout = 30000,
|
||||
Method = Method.POST
|
||||
};
|
||||
request.AddHeader("Content-Type", "application/json");
|
||||
request.AddHeader("Authorization", "Bearer123456");
|
||||
request.AddJsonBody(_body);
|
||||
var response = await client.ExecuteAsync<ResultModel>(request);
|
||||
Console.WriteLine(response.Content);
|
||||
if (response.IsSuccessful)
|
||||
{
|
||||
return response.Data;
|
||||
}
|
||||
return new ResultModel { Code = 500, Msg = "系统错误!" }; ;
|
||||
}
|
||||
|
||||
|
||||
/// send the get request based on HttpWebRequest
|
||||
/// </summary>
|
||||
/// <param name="requestUrl">the url you post</param>
|
||||
/// <param name="routeParameters">the parameters you post</param>
|
||||
/// <returns>return a response object</returns>
|
||||
public static List<T> RefreshData<T>(int type, Method method = Method.GET, Dictionary<string, string> _body = null)
|
||||
{
|
||||
string _domain = string.Format(@"http://cpzs.xixingwl.cn/cpzs/Api/{0}.shtml", type);
|
||||
Console.WriteLine(">>>>" + _domain);
|
||||
var client = new RestClient
|
||||
{
|
||||
BaseUrl = new Uri(_domain),
|
||||
Timeout = 60000,
|
||||
//Authenticator = new HttpBasicAuthenticator("username", "password")
|
||||
};
|
||||
var request = new RestRequest
|
||||
{
|
||||
Timeout = 30000,
|
||||
Method = method
|
||||
};
|
||||
request.AddHeader("Content-Type", "application/json");
|
||||
request.AddHeader("Authorization", "Bearer123456");
|
||||
request.AddJsonBody(_body);
|
||||
IRestResponse<ListModel<T>> response2 = client.Execute<ListModel<T>>(request);
|
||||
Console.WriteLine(response2.Content);
|
||||
if (response2.Data.Code == 200 && response2.Data.Data != null)
|
||||
{
|
||||
return response2.Data.Data;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static BaseModel<T> Refresh<T>(string type, Dictionary<string, string> _body = null)
|
||||
{
|
||||
string _domain = string.Format(@"http://cpzs.xixingwl.cn/addons/cpzs/Api/{0}.shtml", type);
|
||||
Console.WriteLine(">>>>" + _domain);
|
||||
var client = new RestClient
|
||||
{
|
||||
BaseUrl = new Uri(_domain),
|
||||
Timeout = 60000,
|
||||
//Authenticator = new HttpBasicAuthenticator("username", "password")
|
||||
};
|
||||
var request = new RestRequest
|
||||
{
|
||||
Timeout = 30000,
|
||||
Method = Method.POST
|
||||
};
|
||||
request.AddHeader("Content-Type", "application/json");
|
||||
request.AddHeader("Authorization", "Bearer123456");
|
||||
request.AddJsonBody(_body);
|
||||
IRestResponse<BaseModel<T>> response2 = client.Execute<BaseModel<T>>(request);
|
||||
if (response2.IsSuccessful)
|
||||
{
|
||||
Console.Write(">>>" + response2.Content);
|
||||
return response2.Data;
|
||||
}
|
||||
return new BaseModel<T>() { Code = 500, Msg = "系统错误!" };
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public enum RequestType {
|
||||
/// <summary>
|
||||
/// 授权验证
|
||||
/// </summary>
|
||||
noun,
|
||||
/// <summary>
|
||||
/// 设备软件验证
|
||||
/// </summary>
|
||||
verb,
|
||||
/// <summary>
|
||||
/// 注册接口
|
||||
/// </summary>
|
||||
reg ,//= "reg",
|
||||
/// <summary>
|
||||
/// 获取部门
|
||||
/// </summary>
|
||||
getdepartment
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
35
XXCpzs/Helper/Verification.cs
Normal file
35
XXCpzs/Helper/Verification.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace XXCpzs.helper
|
||||
{
|
||||
public class Verification
|
||||
{
|
||||
// 验证电话号码的主要代码如下:
|
||||
public static bool IsTelephone(string str_telephone)
|
||||
{
|
||||
return System.Text.RegularExpressions.Regex.IsMatch(str_telephone, @"^(\d{3,4}-)?\d{6,8}$");
|
||||
}
|
||||
//验证手机号码的主要代码如下:
|
||||
public static bool IsHandset(string str_handset)
|
||||
{
|
||||
return System.Text.RegularExpressions.Regex.IsMatch(str_handset, @"^[1]+[3,5]+\d{9}");
|
||||
}
|
||||
// 验证身份证号的主要代码如下:
|
||||
public static bool IsIDcard(string str_idcard)
|
||||
{
|
||||
return System.Text.RegularExpressions.Regex.IsMatch(str_idcard, @"(^\d{18}$)|(^\d{15}$)");
|
||||
}
|
||||
// 验证输入为数字的主要代码如下:
|
||||
public static bool IsNumber(string str_number)
|
||||
{
|
||||
return System.Text.RegularExpressions.Regex.IsMatch(str_number, @"^[0-9]*$");
|
||||
}
|
||||
// 验证邮编的主要代码如下:
|
||||
public static bool IsPostalcode(string str_postalcode)
|
||||
{
|
||||
return System.Text.RegularExpressions.Regex.IsMatch(str_postalcode, @"^\d{6}$");
|
||||
}
|
||||
}
|
||||
}
|
||||
10
XXCpzs/Helper/com.cs
Normal file
10
XXCpzs/Helper/com.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace XXCpzs.helper
|
||||
{
|
||||
class com
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user