Beispiel #1
0
        public AutoLoginResponse GetAutoLoginPath(AutoLoginRequest request)
        {
            string encryptDataInfo = "";
            var    result          = new AutoLoginResponse();
            string encryptKey      = "clientIdType;clientIdNo;clientName;telNo;accNo;thirdMid;timestamp"; //需加签加密字段key

            Dictionary <string, string> postParams = request.GetParameters();

            foreach (var m in postParams.Where(t => !string.IsNullOrWhiteSpace(t.Value)).OrderBy(t => t.Key))
            {
                if (encryptKey.ToLower().Contains(m.Key.ToLower()))
                {
                    encryptDataInfo += "&" + m.Key + "=" + m.Value;
                }
            }

            encryptDataInfo = encryptDataInfo.Substring(1);       //需加签加密字段

            try
            {
                var signature = Framework.Security.Crypt.SHA1(encryptDataInfo.ToLower() + PingAnConfig.sha1Key);

                string predata = encryptDataInfo + "&signature=" + signature.ToLower().ToLower();

                var publicKey = RSAHelper.RSAPublicKeyJava2DotNet(PingAnConfig.autoLoginPublicKey);

                string encryptData = HexHelper.byteTo16HexStr(RSAHelper.SectionEncrypt(predata, publicKey));

                result.autoLoginPath = PingAnConfig.autoLoginUrl + "?mchId=" + request.mchId + "&encryptData=" + encryptData;

                if (!string.IsNullOrWhiteSpace(request.redirectUrl))
                {
                    string redirectUrl = HttpUtility.UrlEncode(request.redirectUrl, System.Text.Encoding.UTF8);

                    result.autoLoginPath += "&redirectUrl=" + redirectUrl;
                }

                if (!string.IsNullOrWhiteSpace(request.state))
                {
                    string returnUrl = HttpUtility.UrlEncode(request.state, Encoding.UTF8);

                    string state = HttpUtility.UrlEncode("returnUrl=" + returnUrl, Encoding.UTF8);

                    result.autoLoginPath += "&state=" + state;
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("返回异常");
            }
        }