Ejemplo n.º 1
0
        private string getSignature(PhyLocation.Location loc)
        {
            JObject jb = new JObject
            {
                { "systemName", client.Info.SystemName },
                { "systemVersion", client.Info.SystemVersion },
                { "model", client.Info.DeviceModel },
                { "deviceId", client.Info.DeviceId.ToString() },
                { "appVersion", client.Info.AppVersion },
                { "lat", loc.lat },
                { "lon", loc.lon },
                { "userId", client.Login.StudentId }
            };
            string str = jb.ToString();

            return(Encrypt.Des.Encrypt(str, Client.ENCODE_KEY));
        }
Ejemplo n.º 2
0
        public void FetchMore()
        {
            var jb = new JObject();

            jb.Add("signInstanceWid", signInstanceWid.ToString());
            jb.Add("signWid", signWid.ToString());
            JObject result = null;
            string  CAS    = client.Login.MOD_AUTH_CAS("https://njit.campusphere.net/wec-counselor-sign-apps/stu/sign/detailSignInstance");

retry:
            try
            {
                result = client.HTTP_POST("https://njit.campusphere.net/wec-counselor-sign-apps/stu/sign/detailSignInstance", jb, CAS: CAS);
            }
            catch (System.Net.WebException ex)
            {
                var resp = (System.Net.HttpWebResponse)ex.Response;
                if (
                    (resp.StatusCode == System.Net.HttpStatusCode.Found ||
                     resp.StatusCode == System.Net.HttpStatusCode.MovedPermanently
                    )//是跳转
                    &&
                    (resp.Headers["Location"] != null &&
                     Regex.IsMatch(resp.Headers["Location"], ".*authserver/login\\?service=.*")
                    )//跳转地址正确
                    )
                {
                    Console.WriteLine("\t\tCAS失效,试图更新...");
                    Match  match      = Regex.Match(resp.Headers["Location"], "\\?service=(.{1,})");
                    string serviceurl = HttpUtility.UrlDecode(match.Groups[1].Value);
                    client.ResetCookieContainer();
                    CAS = client.Login.MOD_AUTH_CAS(serviceurl, true);
                    if (CAS.Length < 1)
                    {
                        throw new Exception("无法获取签到信息:认证失败");
                    }
                    Console.WriteLine("\t\t已更新,重新发送请求...");
                    goto retry;
                }
                else
                {
                    throw;//不应被处理的错误
                }
            }
            if (result == null)
            {
                throw new Exception("无法获取签到信息:认证失败");
            }
            if (result.Value <int>("code") != 0)
            {
                return;
            }
            result = (JObject)result["datas"];
            Center = new PhyLocation.Location(result["signPlaceSelected"][0].Value <double>("latitude"),
                                              result["signPlaceSelected"][0].Value <double>("longitude"))
            {
                locName = result["signPlaceSelected"][0].Value <string>("address")
            };
            r = result["signPlaceSelected"][0].Value <double>("radius");

            var fields = (JArray)result["extraField"];

            List <FormItem> itemList = new List <FormItem>();

            foreach (JObject jba in fields)
            {
                FormItem item = new FormItem
                {
                    title = jba.Value <string>("title"),
                    wid   = jba.Value <int>("wid")
                };
                List <FormSelection> selections = new List <FormSelection>();
                foreach (JObject jbb in jba["extraFieldItems"])
                {
                    selections.Add(new FormSelection()
                    {
                        content  = jbb.Value <string>("content"),
                        wid      = jbb.Value <int>("wid"),
                        abNormal = jbb.Value <bool>("isAbnormal")
                    });
                }
                item.selections = selections.ToArray();
                itemList.Add(item);
            }
            form          = itemList.ToArray();
            Title         = result.Value <string>("taskName");
            isFetchedMore = true;
        }
Ejemplo n.º 3
0
        public JObject Sign(FormSelection[] selections, PhyLocation.Location location)
        {
            if (!isFetchedMore)
            {
                return(null);
            }
            JObject jb = new JObject
            {
                { "longitude", location.lon },
                { "latitude", location.lat },
                { "isMalposition", location - Center > r ? 1 : 0 },
                { "abnormalReason", "" },
                { "signPhotoUrl", "" },
                { "isNeedExtra", 1 },
                { "position", location.locName },
                { "uaIsCpadaily", "true" },
                { "signInstanceWid", signInstanceWid.ToString() },
                { "signVersion", "1.0.0" }
            };

            var fieldItems = new JArray();

            foreach (FormSelection sel in selections)
            {
                var jobj = new JObject
                {
                    { "extraFieldItemValue", sel.content },
                    { "extraFieldItemWid", sel.wid }
                };
                fieldItems.Add(jobj);
            }

            jb.Add("extraFieldItems", fieldItems);
            string CAS = client.Login.MOD_AUTH_CAS("https://njit.campusphere.net/wec-counselor-sign-apps/stu/sign/submitSign");

retry:
            try
            {
                var result = client.HTTP_POST("https://njit.campusphere.net/wec-counselor-sign-apps/stu/sign/submitSign",
                                              jb, CpdCrypt: getSignature(location), CAS: CAS);
                return(result);
            }
            catch (System.Net.WebException ex)
            {
                var resp = (System.Net.HttpWebResponse)ex.Response;
                if (
                    (resp.StatusCode == System.Net.HttpStatusCode.Found ||
                     resp.StatusCode == System.Net.HttpStatusCode.MovedPermanently
                    )//是跳转
                    &&
                    (resp.Headers["Location"] != null &&
                     Regex.IsMatch(resp.Headers["Location"], ".*authserver/login\\?service=.*")
                    )//跳转地址正确
                    )
                {
                    Console.WriteLine("\t\tCAS失效,试图更新...");
                    Match  match      = Regex.Match(resp.Headers["Location"], "\\?service=(.{1,})");
                    string serviceurl = HttpUtility.UrlDecode(match.Groups[1].Value);
                    client.ResetCookieContainer();
                    CAS = client.Login.MOD_AUTH_CAS(serviceurl, true);
                    if (CAS.Length < 1)
                    {
                        throw new Exception("无法获取签到信息:认证失败");
                    }
                    Console.WriteLine("\t\t已更新,重新发送请求...");
                    goto retry;
                }
                else
                {
                    throw;//不应被处理的错误
                }
            }
        }