我的应用程序使外部签名者能够签署文档。——不是雇员的签名者。我的应用程序将为他们创建一个 CoSign 数字证书。然后他们将签署文件,然后应该从系统中删除用户。我希望我的应用程序以编程方式创建/删除用户。
是否有 SAPI 用户管理 API 的 C# 示例?
我的应用程序使外部签名者能够签署文档。——不是雇员的签名者。我的应用程序将为他们创建一个 CoSign 数字证书。然后他们将签署文件,然后应该从系统中删除用户。我希望我的应用程序以编程方式创建/删除用户。
是否有 SAPI 用户管理 API 的 C# 示例?
这是一个如何获取用户信息的 C# 示例
namespace UMSample
{
class Program
{
private const string ADMIN_USER = "AdminUser";
private const string ADMIN_PASS = "AdminPass";
static public int AddUser(string uid)
{
SAPIUM sapium = new SAPIUMClass();
SAPICrypt sapicrypt = new SAPICrypt();
int rc;
if ((rc = sapicrypt.Init()) != 0) return 1;
if ((rc = sapium.Init()) != 0) return 1;
UMSESHandle hSes = null;
// Handle Acquire
if ((rc = sapium.HandleAcquire(out hSes)) != 0) return 1;
// Logon as Administrator
if ((rc = sapium.Logon(hSes, ADMIN_USER, "", ADMIN_PASS)) != 0)
{
sapium.HandleRelease(hSes);
return 1;
}
string UserCN = uid + " Test User";
string UserEmail = uid+"@demo.com";
string Pwd = "12345678";
if ((rc = sapium.UserAdd(
hSes,
uid,
UserCN,
UserEmail,
Pwd,
1)) != 0)
{
sapium.Logoff(hSes);
sapium.HandleRelease(hSes);
return 1;
}
/*----------------------------------*/
// An example of how to get user info
UserHandle uh;
string s1, s2, s3, s4;
int c1, c2, c3, mask = 0, updtime = 0;
SAPI_UM_ENUM_USER_CERT_STATUS_TYPE certsts;
SAPI_UM_ENUM_USER_LOGIN_STATUS loginstat;
SAPI_UM_ENUM_USER_TYPE kind = SAPI_UM_ENUM_USER_TYPE.SAPI_UM_USER_TYPE_NONE;
SAPI_UM_ENUM_USER_ENROLLMENT_STATUS enroll = SAPI_UM_ENUM_USER_ENROLLMENT_STATUS.SAPI_UM_NONE_USER_ENROLLMENT_STATUS;
SAPI_UM_ENUM_USER_ENROLLMENT_REASON enrReason;
SAPI_UM_ENUM_PENDING_REQUEST_STATUS_TYPE certrqsts;
rc = sapium.UserGetByLoginName(hSes, uid, out uh);
rc = sapium.UserInfoGetEx(hSes, uh, out s1, out s2, out s3, ref kind, ref mask, ref updtime, out s4,
out enroll, out enrReason, out loginstat, out c1, out c2, out c3, out certsts, out certrqsts);
/*----------------------------------*/
sapium.Logoff(hSes);
sapium.HandleRelease(hSes);
return 0;
}
static public int DelUser(string uid)
{
SAPIUM sapium = new SAPIUMClass();
int rc;
if ((rc = sapium.Init()) != 0) return 1;
UMSESHandle hSes = null;
if ((rc = sapium.HandleAcquire(out hSes)) != 0) return 1;
if ((rc = sapium.Logon(hSes, ADMIN_USER, "", ADMIN_PASS)) != 0)
{
sapium.HandleRelease(hSes);
return 1;
}
if ((rc = sapium.UserDelete(hSes, uid)) != 0)
{
sapium.Logoff(hSes);
sapium.HandleRelease(hSes);
return 1;
}
sapium.Logoff(hSes);
sapium.HandleRelease(hSes);
return 0;
}
static void Main(string[] args)
{
int rc;
for (int i = 0; i < 10; i++)
{
string uid = "Test" + i;
rc = AddUser(uid);
if (rc != 0) {
Console.WriteLine ("Error adding user: " + uid);
return;
}
rc = DelUser(uid);
if (rc != 0) {
Console.WriteLine ("Error deleting user: " + uid);
return;
}
Console.WriteLine("After handling user: " + uid);
}
Console.WriteLine("Press <Enter> to end");
Console.ReadKey();
}
}
}