164 lines
7.4 KiB
C#
164 lines
7.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Collections.Concurrent;
|
||
using Kingdee.BOS.Authentication;
|
||
using Kingdee.BOS.JSON;
|
||
using Kingdee.BOS.ServiceFacade.KDServiceFx;
|
||
using Kingdee.BOS.ServiceFacade.ServicesStub;
|
||
using Kingdee.BOS.Resource;
|
||
using System.Web;
|
||
namespace Kingdee.BOS.ServiceFacade.StartApp
|
||
{
|
||
public class MacVerify : StartAppVerifyServiceBase
|
||
{
|
||
/// <summary>
|
||
/// 客制化参数映射到用户信息,或域签名串映射到用户信息存储池,也可以是数据库
|
||
/// </summary>
|
||
static ConcurrentDictionary<string, string> customArgsMapUser = new ConcurrentDictionary<string, string>();
|
||
static MacVerify()
|
||
{
|
||
customArgsMapUser["testautologinwithdemo"] = "demo|123qwe!@#|金蝶蓝海实业集团";
|
||
}
|
||
/// <summary>
|
||
/// 随机测试标识,仅用于模拟各种启动校验结果的返回判定
|
||
/// </summary>
|
||
static int randomFlag = 0;
|
||
/// <summary>
|
||
/// 实现登录服务处理接口,在程序启动界面加入参数 "ud=TestAutoLoginWithDemo" 即可实现自动用Demo用户登录CPDEMOV5数据中心
|
||
/// 例如:
|
||
/// WEB的Silverlight: http://xxxx/k3cloud/silverlight/index.aspx?ud=TestAutoLoginWithDemo
|
||
/// WEB的HTML5:http://xxxx/k3cloud/html5/index.aspx?ud=TestAutoLoginWithDemo
|
||
/// </summary>
|
||
public override StartAppResult Verify(KDServiceContext context, string ipmac)
|
||
{
|
||
var ret = this.Verify(ipmac);
|
||
if (ret.ResultType == StartAppResultType.Success)
|
||
{
|
||
var data = JSONObject.Parse(ipmac);
|
||
VerifyLogin(context, ret, data);
|
||
}
|
||
return ret;
|
||
}
|
||
/// <summary>
|
||
/// 实现登录校验的例子的私有函数
|
||
/// </summary>
|
||
private void VerifyLogin(KDServiceContext context, StartAppResult ret, JSONObject data)
|
||
{
|
||
//实现自动登录功能
|
||
var customArgs = data.GetValue<string>("customArgs", "");//ud用户定义参数将会传递到服务端插件的customArgs中
|
||
var isAutoLogin = !string.IsNullOrWhiteSpace(customArgs);
|
||
if (isAutoLogin && context != null)
|
||
{
|
||
try
|
||
{
|
||
//不一定非得从data中传进来这些信息,
|
||
//也可以通过Mac映射到数据库中的某个记录,从中读取登录信息,
|
||
//包括用户名、密码和数据库id,已经对应的语种id
|
||
//这里只是Demo而已
|
||
var userInfoStr = "";
|
||
var key = customArgs.ToLowerInvariant();
|
||
customArgsMapUser.TryGetValue(key, out userInfoStr);
|
||
if (string.IsNullOrWhiteSpace(userInfoStr))
|
||
userInfoStr = "";
|
||
var userInfo = userInfoStr.Split('|');
|
||
var un = userInfo.Length > 2 ? userInfo[0] : "";
|
||
var pw = userInfo.Length > 2 ? userInfo[1] : "";
|
||
var dbname = userInfo.Length > 2 ? userInfo[2] : "";
|
||
var pluginLoginInfo = new PluginLoginInfo()
|
||
{
|
||
//AcctID = "xxxxxx", //AcctID如果传递,将不再通过AcctName查找AcctID了。
|
||
//LoginType = PluginLoginType.Common, //默认为用户名密码的通用登录方式。 //PluginLoginInfo.AuthenticateType = Kingdee.BOS.Authentication.AuthenticationType.DynamicPwdAuthentication, // 动态密码验证方式
|
||
AcctName = dbname,
|
||
Username = un,
|
||
Password = pw,
|
||
ClientInfo = GetClientInfo(context, data) //基类静态工具方法
|
||
};
|
||
//调用基类静态工具方法实现登录验证,并返回ret.UserToken,给客户端实现自动登录
|
||
DoLoginCore(context, ret, pluginLoginInfo);
|
||
//登录后的参数传入,具体使用参考【自动打开单据】
|
||
if (!string.IsNullOrWhiteSpace(ret.SessionId))
|
||
{
|
||
var isoKey = ret.SessionId + "_AutoLoginArgs";
|
||
//登陆成功后,加入自定义参数
|
||
HttpContext.Current.Application.Set(isoKey, "PUR_PurchaseOrder|100001");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ret.ResultType = StartAppResultType.Failure;
|
||
ret.FailureCallBackType = StartAppResultCallBackType.Message;
|
||
ret.Message = ex.Message + "\r\n" + ex.StackTrace;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 实现基类访问校验接口,如果没有该业务需求,可以不实现,使用基类的接口即可。
|
||
/// </summary>
|
||
public override StartAppResult Verify(string ipmac)
|
||
{
|
||
randomFlag++;
|
||
StartAppResult ret = null;
|
||
var data = JSONObject.Parse(ipmac);
|
||
var flag = randomFlag % 5;
|
||
flag = 5;
|
||
switch (flag)
|
||
{
|
||
case 4:
|
||
// 提示后退出并重定向到指定页面
|
||
ret = GetResult(StartAppResultCallBackType.ExitMsg_Redirect, ipmac);
|
||
break;
|
||
case 3:
|
||
// 退出并重定向到指定页面(不做任何提示)
|
||
ret = GetResult(StartAppResultCallBackType.Exit_Redirect, ipmac);
|
||
break;
|
||
case 2:
|
||
// 退出并提示
|
||
ret = GetResult(StartAppResultCallBackType.ExitMsg, ipmac);
|
||
break;
|
||
case 1:
|
||
// 提示信息(不退出程序)
|
||
ret = GetResult(StartAppResultCallBackType.Message, ipmac);
|
||
break;
|
||
default:
|
||
ret = new StartAppResult()
|
||
{
|
||
ResultType = StartAppResultType.Success
|
||
};
|
||
randomFlag = 0;
|
||
break;
|
||
}
|
||
return ret;
|
||
}
|
||
/// <summary>
|
||
/// 构造返回结果
|
||
/// </summary>
|
||
/// <param name="fcbType">返回回调类型</param>
|
||
/// <returns></returns>
|
||
private static StartAppResult GetResult(StartAppResultCallBackType fcbType, string attMsg)
|
||
{
|
||
var ret = new StartAppResult()
|
||
{
|
||
FailureCallBackType = fcbType,
|
||
// 成功Sucess:正常登录
|
||
ResultType = StartAppResultType.Failure,
|
||
|
||
// 外部网址:RedirectUrl = "http://www.kingdee.com"
|
||
// 空白页:RedirectUrl = "about:blank"
|
||
// 失败后重定向URL,可以是相对路径也可以是绝对路径,相对路径已K3Cloud为基地址,例如:http://xxxx/k3cloud/
|
||
RedirectUrl = "help/clienthelp.htm",
|
||
ExitType = StartAppResultExitType.Shutdown,
|
||
|
||
Title = "温馨提示" + "0022883030028663",
|
||
Message = "网站正在维护中 ... ..." + "0022883030028642" +
|
||
"\r\n" + attMsg
|
||
};
|
||
return ret;
|
||
}
|
||
}
|
||
}
|
||
|