【星空-开发】获取指定用户上下文原创
金蝶云社区-雪地上的名字
雪地上的名字
65人赞赏了该文章 457次浏览 未经作者许可,禁止转载编辑于2024年04月23日 09:46:44

业务场景:多用于系统自动做单或者自动审核,以及执行计划跑单,不想把单据的创建,修改,审核的记录人记录为实际业务人员,需要标识为系统自动创建,比如admin或者自建用于自动处理单据的账号,需要注意这种中间账号需要有对应组织的权限和做单权限


using System;
using Kingdee.BOS;
using Kingdee.BOS.Authentication;
using Kingdee.BOS.Log;
using Kingdee.BOS.ServiceFacade.KDServiceClient.User;
using Newtonsoft.Json;


namespace Demo
{
    public class K3CloudLoginGetContext
    {
        public static Context getContext(string url, string id, string userName, string userPass, int userLangee)
        {
            try
            {
                UserServiceProxy userServiceProxy = new UserServiceProxy();
                LoginInfo loginInfo = new LoginInfo();
                Logger.Info("登录信息", $"网址={url};账套id={id};用户名={userName};密码={userPass};语言={userLangee}");
                loginInfo.AcctID = id;
                loginInfo.Username = userName;
                loginInfo.Password = userPass;
                loginInfo.Lcid = Convert.ToInt32(userLangee);
                LoginResult loginResult = userServiceProxy.ValidateUser(url, loginInfo);
                Logger.Info("登录信息", JsonConvert.SerializeObject(loginResult, Formatting.None, new JsonSerializerSettings()));
                return loginResult.Context;
            }
            catch (Exception ex)
            {
                Logger.Info("登录账套异常:", ex.ToString());
                return null;
            }
        }
        
        //调用方法获取特定用户的上下文
        public static Context getContext()
        {           
            //如下的信息可以记录在website下web.config中,读取配置
            string dbid = ConfigurationManager.AppSettings["数据中心Id"];
            string erpht = ConfigurationManager.AppSettings["账号"];
            string erphtpass = ConfigurationManager.AppSettings["密码"];           
            Context ctx = K3CloudLoginGetContext.getContext("http://127.0.0.1/k3cloud/", dbid, erpht, erphtpass, 2052);
            return ctx;
        }
        
    }
}


更多内容请查阅如下链接,谢谢

https://vip.kingdee.com/article/518480895951406080?productLineId=1

赞 65