public static class PSWebUtils
{
private const string SIMPLECHECK_KEY_SN_PARAM_NAME = "__sk_keysn";
private const string SIMPLECHECK_KEY_ID_PARAM_NAME = "__sk_keyid";
private const string SIMPLECHECK_KEY_SN_PARAM_NAME_PS = "KeySN";
private const string SIMPLECHECK_KEY_ID_PARAM_NAME_PS = "ID";
private const string SIMPLECHECK_KEY_RETURNURL = "ReturnUrl";
private const string Request_UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36";
/// <summary>
/// 创建一个用于在第三方Web系统登录的跳转URL
/// </summary>
/// <param name="targetUrl">目的URL</param>
/// <param name="keySN">IRightCheck.GenUserKey()方法生成</param>
/// <param name="keyID">IRightCheck.GenUserKey()方法生成</param>
/// <returns>完整的跳转URL</returns>
public static string GenSkipUrl(string targetUrl, int keySN, string keyID)
{
PSBaseException.ThrowArgNullException(targetUrl, "targetUrl", true);
PSBaseException.ThrowArgOutRangeException(keySN, "keySN", 0, int.MaxValue);
PSBaseException.ThrowArgNullException(keyID, "keyID", true);
string c = targetUrl.IndexOf('?') >= 0 ? "&" : "?";
string keySN_Name = SIMPLECHECK_KEY_SN_PARAM_NAME;
string keyID_Name = SIMPLECHECK_KEY_ID_PARAM_NAME;
return string.Format("{0}{1}{2}={3}&{4}={5}", targetUrl, c, keySN_Name, keySN, keyID_Name, HttpUtility.UrlEncode(keyID));
}
//ReturnUrl
/// <summary>
/// 从由第三方系统跳转时所带的参数(用于IRightCheck.SimpleCheck()进行简单登录)
/// </summary>
/// <param name="httpRequest">当前Http请求</param>
/// <param name="keySN">获取到的参数值</param>
/// <param name="keyID">获取到的参数值</param>
/// <returns>获取成功则返回true,否则返回false.</returns>
public static bool GetSkipParam(HttpRequest httpRequest, out int keySN, out string keyID)
{
PSBaseException.ThrowArgNullException(httpRequest, "httpRequest");
keySN = 0;
keyID = "";
bool result = false;
string keysn = httpRequest[SIMPLECHECK_KEY_SN_PARAM_NAME];
string keyid = httpRequest[SIMPLECHECK_KEY_ID_PARAM_NAME];
if (!string.IsNullOrEmpty(keysn) && !string.IsNullOrEmpty(keyid))
{
result = true;
keySN = int.Parse(keysn);
keyID = keyid;
}
if (!result)
{
keysn = httpRequest[SIMPLE
发送HttpWebRequest请求工具类
最新推荐文章于 2022-02-21 08:37:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)