You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
5.2 KiB
C#
146 lines
5.2 KiB
C#
using System;
|
|
using System.Web.Mvc;
|
|
using DSWeb.Common;
|
|
using DSWeb.Common.DB;
|
|
using System.Linq;
|
|
using log4net;
|
|
using System.Configuration;
|
|
using StackExchange.Redis;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace DSWeb.MvcShipping.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 系统联合跳转调用路由
|
|
/// </summary>
|
|
public class GetwayController : Controller
|
|
{
|
|
private ILog logger = LogManager.GetLogger("GetwayController");
|
|
|
|
private static string CfgGetCodeUrl = ConfigurationManager.AppSettings["GetCodeUrl"];
|
|
private static string CfgGoRouteUrl;
|
|
|
|
public ActionResult Index()
|
|
{
|
|
return Content("getweyindex");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取授权code 路由跳转
|
|
/// </summary>
|
|
/// <param name="syskey">子系统Key</param>
|
|
/// <param name="WebId">子系统的页面Id</param>
|
|
/// <returns></returns>
|
|
public ActionResult WebRoute(string syskey, string WebId, string goRouteCfg = "GoRouteUrl")
|
|
{
|
|
try
|
|
{
|
|
CfgGoRouteUrl = ConfigurationManager.AppSettings[goRouteCfg];
|
|
var Userid = Session["USERID"].ToString();
|
|
var secretkey = "2Fv6I7oV6AlCFEbN";
|
|
var GetCodeUrl = @"http://djy-identity.myshipping.net/user/code";//code获取url
|
|
var GoRouteUrl = @"http://djypaas.myshipping.net/#/getway?code={0}&webid={1}";//目标路由地址
|
|
if (!string.IsNullOrEmpty(CfgGetCodeUrl))
|
|
{
|
|
GetCodeUrl = CfgGetCodeUrl;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(CfgGoRouteUrl))
|
|
{
|
|
GoRouteUrl = CfgGoRouteUrl;
|
|
}
|
|
|
|
var times = DateTime.Now.ToTimeStamp();
|
|
var md5 = string.Format("{0}{1}{2}", Userid, times, secretkey).ToMd5();
|
|
var postdata = new { Id = Userid, Timestamp = times, md5 = md5 };
|
|
var gethtm = Common.Helper.WebRequestHelper.DoPostJson(GetCodeUrl, postdata);
|
|
if (gethtm.IsJson())
|
|
{
|
|
|
|
var json = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(gethtm, new { code = 0, status = false, data = "", message = "" });
|
|
if (json.code == 200)
|
|
{
|
|
|
|
var url = "";
|
|
if (syskey.IsNotNull())
|
|
{
|
|
var getway = new CommonDataContext().SysGateway.FirstOrDefault(w => w.SysKey == syskey);
|
|
if (getway == null)
|
|
{
|
|
return Content("没有此系统页面,请配置!");
|
|
}
|
|
url = string.Format(getway.Url, json.data, WebId);
|
|
}
|
|
else
|
|
{
|
|
url = string.Format(GoRouteUrl, json.data, WebId);
|
|
}
|
|
|
|
|
|
Response.Redirect(url);
|
|
return View(url);
|
|
}
|
|
else
|
|
{
|
|
return Content(json.message);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return Content("错误的授权请求!");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex.Message);
|
|
logger.Error(ex.StackTrace);
|
|
return Content("请求失败!");
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// session跳转
|
|
/// </summary>
|
|
/// <param name="syskey"></param>
|
|
/// <returns></returns>
|
|
public ActionResult SessRedirect(string syskey, string[] paraList = null)
|
|
{
|
|
CommonDataContext commonData = new CommonDataContext();
|
|
string uid = Session["USERID"].ToString();
|
|
if (string.IsNullOrEmpty(uid))
|
|
{
|
|
return Content("登录失效,请重新登录");
|
|
}
|
|
|
|
var getway = new CommonDataContext().SysGateway.FirstOrDefault(w => w.SysKey == syskey);
|
|
if (getway == null)
|
|
{
|
|
return Content("未配置跳转页面地址");
|
|
}
|
|
|
|
var user = commonData.Users.AsNoTracking().FirstOrDefault(u => u.GID == uid);
|
|
var comp = commonData.CompanyNew.AsNoTracking().FirstOrDefault(c => c.CompId == user.CompId);
|
|
|
|
var sessionCode = Guid.NewGuid().ToString().Replace("-", "");
|
|
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["RedisServerAddr"]);
|
|
IDatabase db = redis.GetDatabase();
|
|
var strSess = JsonConvert.SerializeObject(new { user, company = comp });
|
|
db.StringSet(sessionCode, strSess, expiry: new TimeSpan(0, 0, 20));
|
|
redis.Close();
|
|
|
|
var toUrl = getway.Url;
|
|
if (getway.Url.IndexOf("?") > -1)
|
|
{
|
|
toUrl = string.Format(toUrl, paraList);
|
|
toUrl += $"&session_code={sessionCode}";
|
|
}
|
|
else
|
|
{
|
|
toUrl += $"?session_code={sessionCode}";
|
|
}
|
|
|
|
return Redirect(toUrl);
|
|
}
|
|
}
|
|
} |