基本信息
源码名称:HISWebInterface(webserver开发)
源码大小:2.17M
文件格式:.rar
开发语言:C#
更新时间:2021-07-19
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using HISWebInterface.Model;
using Newtonsoft.Json;
using RDH.Data;
using RDH.Data.Access;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
namespace HISWebInterface
{
/// <summary>
/// Service 的摘要说明
/// </summary>
public class Service : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
try
{
Stream stream = context.Request.InputStream;
if (stream.Length > 0)
{
StreamReader reader = new StreamReader(stream);
string str = reader.ReadToEnd();
if (VerifySignature(str))
{
Json json = JsonConvert.DeserializeObject<Json>(str);
if (json.InterfaceUserId == ConfigHellper.InterfaceUserId)
{
switch (json.Method)
{
case "ruidaheng_get_userInfo":
context.Response.Write(ToJson(json.Method, 0, "", 0, "", GetUserInfo()));
break;
case "ruidaheng_get_deptInfo":
context.Response.Write(ToJson(json.Method, 0, "", 0, "", GetDeptInfo()));
break;
default:
context.Response.Write(ToJson(json.Method, -1, "没有相应接口", -1, "", ""));
break;
}
}
else
{
context.Response.Write(ToJson(json.Method, -1, "用户错误", -1, "", ""));
}
}
else
{
context.Response.Write(ToJson("", -1, "验证失败", -1, "", ""));
}
}
else
{
context.Response.Write(ToJson("", -1, "请求的数据不能为空!", -1, "", ""));
}
}
catch (Exception ex)
{
context.Response.Write(ToJson("", -1, ex.Message, -1, "", ""));
}
}
public bool IsReusable
{
get
{
return false;
}
}
//将结果转化为JSON格式
private String ToJson(string Method, int ReturnCode, string ReturnMess, int ResultCode, string ResultMess, String items)
{
Dictionary<string, string> dics = new Dictionary<string, string>();
dics.Add("ReturnCode", ReturnCode.ToString());
dics.Add("ReturnMess", ReturnMess);
if (ReturnCode == 0)
{
dics.Add("InterfaceUserId", ConfigHellper.InterfaceUserId);
dics.Add("NonceStr", GenerateMD5("ruidaheng_get_deptInfo" DateTime.Now));
dics.Add("ResultCode", ResultCode.ToString());
dics.Add("ResultMess", ResultMess);
dics.Add("Items", items);
string str = getParamSrc(dics);
str = str "&key=" ConfigHellper.WebKey;
string sign = GenerateMD5(str).ToUpper();
dics.Add("Sign", sign);
dics.Remove("Items");
dics.Add("Items", items.Replace("\"", "\\\""));
}
string result = "{\"" String.Join("\",\"", dics.Select(x => string.Join("\":\"", x.Key, x.Value))) "\"}";
return result;
}
/// <summary>
/// 查询用户信息
/// </summary>
/// <returns>JSON格式的字符串</returns>
private String GetUserInfo()
{
List<UserInfo> users = null;
using (CommonConnnectionSessionScope scope = new CommonConnnectionSessionScope(ConfigHellper.SateServerConnection))
{
string strsql =
"select * from UserInfo_V ";
users = SqlMapper.Query<UserInfo>(ConnectionFactory.Current.GetSessionConnection(), strsql)
.ToList();
}
return JsonConvert.SerializeObject(users);
}
/// <summary>
/// 查询部门信息
/// </summary>
/// <returns>JSON格式的字符串</returns>
private String GetDeptInfo()
{
List<DeptInfo> depts = null;
using (CommonConnnectionSessionScope scope = new CommonConnnectionSessionScope(ConfigHellper.SateServerConnection))
{
string strsql =
"select * from OrganizeInfo_V t";
depts = SqlMapper.Query<DeptInfo>(ConnectionFactory.Current.GetSessionConnection(), strsql)
.ToList();
}
return JsonConvert.SerializeObject(depts);
}
/// <summary>
/// 验证签名,确保数据准确
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private bool VerifySignature(string str)
{
Dictionary<string, string> dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(str);
string resultSign = "";
dict.TryGetValue("Sign", out resultSign);
dict.Remove("Sign");
string resultStr = getParamSrc(dict);// String.Join("&", dict.Select(x => string.Join("=", x.Key, x.Value)));
resultStr = resultStr "&key=" ConfigHellper.WebKey;
string sign = GenerateMD5(resultStr).ToUpper();
return resultSign == sign;
}
/// <summary>
/// 将字典转化为需要的字符串
/// </summary>
/// <param name="paramsMap"></param>
/// <returns></returns>
private string getParamSrc(Dictionary<string, string> paramsMap)
{
var vDic = (from objDic in paramsMap orderby objDic.Key ascending select objDic);
StringBuilder str = new StringBuilder();
foreach (KeyValuePair<string, string> kv in vDic)
{
string key = kv.Key;
string value = kv.Value;
if (!string.IsNullOrEmpty(value))
str.Append(key "=" value "&");
}
String result = str.ToString().Substring(0, str.ToString().Length - 1);
return result;
}
/// <summary>
/// MD5字符串加密
/// </summary>
/// <param name="txt"></param>
/// <returns>加密后字符串</returns>
private string GenerateMD5(string strText)
{
using (var md5 = MD5.Create())
{
var signDataBytes = md5.ComputeHash(Encoding.GetEncoding("utf-8").GetBytes(strText));
return BitConverter.ToString(signDataBytes).Replace("-", "");
}
}
}
}