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("返回异常");
            }
        }
        /// <summary>
        /// 免登接口
        /// </summary>
        /// <returns></returns>
        public AutoLoginResponse AutoLogin(PingAnOrderPaid pingAnOrderPaid, Member member)
        {
            AutoLoginRequest request = new AutoLoginRequest();

            request.accNo        = pingAnOrderPaid.ClientNo;
            request.clientIdNo   = member.IDNumber;
            request.clientIdType = "1";
            request.clientName   = member.Name;
            request.mchId        = channel;
            request.redirectUrl  = redirectUrl;
            request.state        = returnUrl + pingAnOrderPaid.BankOrderNo;
            request.telNo        = member.Mobile;
            request.thirdMid     = member.Mobile;
            request.timestamp    = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString();
            request.umCode       = "";

            var response = pingAnExec.GetAutoLoginPath(request);

            return(response as AutoLoginResponse);
        }
        static bool AutoLogin(string url, Credentials c, string autoLoginUrl)
        {
            Console.WriteLine("Getting AutoLogin Link...");

            ArticulateOnline ao = new ArticulateOnline {
                Url = url
            };
            AutoLoginRequest request = new AutoLoginRequest
            {
                Credentials = c,
                Url         = autoLoginUrl
            };

            AutoLoginResponse response = ao.GetAutoLoginUrl(request);

            if (response.Success)
            {
                Console.WriteLine(response.Url);
            }
            return(response.Success);
        }