コード例 #1
0
        /// <summary>
        /// 拼接请求体
        ///     .可以重写
        /// </summary>
        /// <remarks>
        /// DSId必须要与Cookie对应,需要通过 <see cref="_5"/> 动态获取,DSId将以字节方式替换旧的DSId;替换cityCode
        /// </remarks>
        /// <param name="param">参数列表</param>
        /// <returns></returns>
        public override byte[] MakeRequestBody(AqiParam param)
        {
            byte[] requestbody = base.MakeRequestBody(param);
            byte[] newDSId     = Encoding.ASCII.GetBytes(param["DSId"]);
            byte[] oldDSId     = Encoding.ASCII.GetBytes(param["replaceDSId"]);

            while (requestbody.FindBytes(oldDSId) >= 0)
            {
                requestbody = requestbody.ReplaceBytes(oldDSId, newDSId);
            }

            if (param.ContainsKey("stationCode"))
            {
                byte[] newCode1 = Encoding.ASCII.GetBytes(param["cityCode"]);
                byte[] newCode2 = Encoding.ASCII.GetBytes(param["stationCode"]);
                byte[] newCode  = new byte[newCode1.Length + newCode2.Length + 2];
                Array.Copy(newCode1, newCode, newCode1.Length);
                Array.Copy(newCode2, 0, newCode, newCode1.Length + 2, newCode2.Length);
                newCode[newCode1.Length]     = 0x06;
                newCode[newCode1.Length + 1] = 0x05;
                byte[] oldCode1 = Encoding.ASCII.GetBytes(param["replaceCityCode"]);
                byte[] oldCode2 = Encoding.ASCII.GetBytes("01");
                byte[] oldCode  = new byte[oldCode1.Length + oldCode2.Length + 2];
                Array.Copy(oldCode1, oldCode, oldCode1.Length);
                Array.Copy(newCode2, 0, oldCode, oldCode1.Length + 2, oldCode2.Length);
                newCode[oldCode1.Length]     = 0x06;
                newCode[oldCode1.Length + 1] = 0x05;
                requestbody = requestbody.ReplaceBytes(oldCode, newCode);
            }
            else if (param.ContainsKey("cityCode"))
            {
                byte[] newCode = Encoding.ASCII.GetBytes(param["cityCode"]);
                byte[] oldCode = Encoding.ASCII.GetBytes(param["replaceCityCode"]);
                requestbody = requestbody.ReplaceBytes(oldCode, newCode);
            }
            else if (param.ContainsKey("pollutantCode"))
            {
                byte[] arrOutput  = { 0x09, 0x03, 0x01, 0x06, 0x03, 0x38, 0x01 };
                byte[] arrOutput2 = { 0x09, 0x03, 0x01, 0x06, 0x03, 0x38, 0x01 };
                arrOutput2[5] = (byte)param["pollutantCode"].ElementAt(0);
                requestbody   = requestbody.ReplaceBytes(arrOutput, arrOutput2);
            }

            return(requestbody);
        }
コード例 #2
0
        /// <summary>
        /// 拼接请求体
        ///     .可以重写
        /// </summary>
        /// <remarks>
        /// DSId必须要与Cookie对应,需要通过 <see cref="_5"/> 动态获取,DSId将以字节方式替换旧的DSId;替换cityCode
        /// </remarks>
        /// <param name="param">参数列表</param>
        /// <returns></returns>
        public override byte[] MakeRequestBody(AqiParam param)
        {
            byte[] requestbody = base.MakeRequestBody(param);
            byte[] newDSId     = Encoding.ASCII.GetBytes(param["DSId"]);
            byte[] oldDSId     = Encoding.ASCII.GetBytes(param["replaceDSId"]);

            while (requestbody.FindBytes(oldDSId) >= 0)
            {
                requestbody = requestbody.ReplaceBytes(oldDSId, newDSId);
            }

            if (param.ContainsKey("stationCode"))
            {
                byte[] newCode1 = Encoding.ASCII.GetBytes(param["cityCode"]);
                byte[] newCode2 = Encoding.ASCII.GetBytes(param["stationCode"]);
                byte[] newCode  = new byte[newCode1.Length + newCode2.Length + 2];
                Array.Copy(newCode1, newCode, newCode1.Length);
                Array.Copy(newCode2, 0, newCode, newCode1.Length + 2, newCode2.Length);
                newCode[newCode1.Length]     = 0x06;
                newCode[newCode1.Length + 1] = 0x05;
                byte[] oldCode1 = Encoding.ASCII.GetBytes(param["replaceCityCode"]);
                byte[] oldCode2 = Encoding.ASCII.GetBytes("01");
                byte[] oldCode  = new byte[oldCode1.Length + oldCode2.Length + 2];
                Array.Copy(oldCode1, oldCode, oldCode1.Length);
                Array.Copy(oldCode2, 0, oldCode, oldCode1.Length + 2, oldCode2.Length);
                oldCode[oldCode1.Length]     = 0x06;
                oldCode[oldCode1.Length + 1] = 0x05;
                requestbody = requestbody.ReplaceBytes(oldCode, newCode);
            }
            else if (param.ContainsKey("cityCode"))
            {
                byte[] newCode = Encoding.ASCII.GetBytes(param["cityCode"]);
                byte[] oldCode = Encoding.ASCII.GetBytes(param["replaceCityCode"]);
                requestbody = requestbody.ReplaceBytes(oldCode, newCode);
            }

            return(requestbody);
        }
コード例 #3
0
        /// <summary>
        /// 拼接请求体
        ///     .可以重写
        /// </summary>
        /// <remarks>
        /// 读取参数 amf ,将 amf.type 解析为枚举 AMFMessageParamType 进行处理
        ///     1、 AMFMessageParamType 为 UseJson,将 amf.message 作为 json 字符串解析为字节数组;
        ///     2、 AMFMessageParamType 为 UseXml,将 amf.message 作为 xml 字符串解析为字节数组;
        ///     3、 AMFMessageParamType 为 UseCode 并且本实例实现 IMakeAMFMessage 接口,
        ///         将 amf.message 作为参数调用 IMakeAMFMessage接口 MakeAMFMsg方法生成 AMFMessage对象,序列化为字节数组;
        ///     4、AMFMessageParamType 为 NoUse,使用父类 MakeRequestBody。
        /// 若无参数 amf 则使用父类 MakeRequestBody
        /// </remarks>
        /// <param name="param">参数列表</param>
        /// <returns></returns>
        public override byte[] MakeRequestBody(AqiParam param)
        {
            if (param.ContainsKey(PARAM_AMF) &&
                !String.IsNullOrEmpty(param[PARAM_AMF]))
            {
                Dictionary <string, string> map = new Dictionary <string, string>();
                JObject jo = JObject.Parse(param[PARAM_AMF]);
                JToken  jt = jo.SelectToken(PARAM_AMF_TYPE);
                map.Add(PARAM_AMF_TYPE, jt.ToString());
                jt = jo.SelectToken(PARAM_AMF_MSG);
                map.Add(PARAM_AMF_MSG, jt.ToString());

                if (map.ContainsKey(PARAM_AMF_TYPE) &&
                    !String.IsNullOrEmpty(map[PARAM_AMF_TYPE]) &&
                    map.ContainsKey(PARAM_AMF_MSG) &&
                    !String.IsNullOrEmpty(map[PARAM_AMF_MSG]))
                {
                    AMFMessageParamType ampt;
                    if (Enum.TryParse(map[PARAM_AMF_TYPE], out ampt))
                    {
                        switch (ampt)
                        {
                        case AMFMessageParamType.UseJson:
                            param.Body = _mh.GetAmfBinaryMessageAsBinary(map[PARAM_AMF_MSG]);
                            break;

                        case AMFMessageParamType.UseXml:
                            //TODO 尝试amfx
                            throw new NotSupportedException("不被支持的参数类型,amf.type=" + (int)ampt);

                        case AMFMessageParamType.UseCode:
                            if (this is IMakeAMFMessage)
                            {
                                IMakeAMFMessage iMakeAmfMsg = this as IMakeAMFMessage;
                                AMFMessage      amfmessage  = iMakeAmfMsg.MakeAMFMsg(param);
                                return(_mh.LoadAmfMessageIntoBinMessage(amfmessage));
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                            break;

                        case AMFMessageParamType.NoUse:
                            base.MakeRequestBody(param);
                            break;

                        default:
                            throw new NotSupportedException("不被支持的参数类型,amf.type=" + (int)ampt);
                        }
                    }
                    else
                    {
                        throw new NotSupportedException("参数amf.type=" + map[PARAM_AMF_TYPE] + "是不被支持的!");
                    }
                }
            }
            else
            {
                base.MakeRequestBody(param);
            }

            return(param.Body);
        }
コード例 #4
0
ファイル: semcSrcUrl.cs プロジェクト: xiaoyao9184/AQISet
        /// <summary>
        /// 拼接请求体
        ///     .可以重写
        /// </summary>
        /// <remarks>
        /// DSId必须要与Cookie对应,需要通过 <see cref="_5"/> 动态获取,DSId将以字节方式替换旧的DSId;替换cityCode
        /// </remarks>
        /// <param name="param">参数列表</param>
        /// <returns></returns>
        public override byte[] MakeRequestBody(AqiParam param)
        {
            byte[] requestbody = base.MakeRequestBody(param);
            byte[] newDSId = Encoding.ASCII.GetBytes(param["DSId"]);
            byte[] oldDSId = Encoding.ASCII.GetBytes(param["replaceDSId"]);

            while (requestbody.FindBytes(oldDSId) >= 0)
            {
                requestbody = requestbody.ReplaceBytes(oldDSId, newDSId);
            }

            if (param.ContainsKey("stationCode"))
            {
                byte[] newCode1 = Encoding.ASCII.GetBytes(param["cityCode"]);
                byte[] newCode2 = Encoding.ASCII.GetBytes(param["stationCode"]);
                byte[] newCode = new byte[newCode1.Length + newCode2.Length + 2];
                Array.Copy(newCode1,newCode,newCode1.Length);
                Array.Copy(newCode2, 0, newCode, newCode1.Length+2, newCode2.Length);
                newCode[newCode1.Length] = 0x06;
                newCode[newCode1.Length+1] = 0x05;
                byte[] oldCode1 = Encoding.ASCII.GetBytes(param["replaceCityCode"]);
                byte[] oldCode2 = Encoding.ASCII.GetBytes("01");
                byte[] oldCode = new byte[oldCode1.Length + oldCode2.Length + 2];
                Array.Copy(oldCode1, oldCode, oldCode1.Length);
                Array.Copy(newCode2, 0, oldCode, oldCode1.Length + 2, oldCode2.Length);
                newCode[oldCode1.Length] = 0x06;
                newCode[oldCode1.Length + 1] = 0x05;
                requestbody = requestbody.ReplaceBytes(oldCode, newCode);
            }
            else if (param.ContainsKey("cityCode"))
            {
                byte[] newCode = Encoding.ASCII.GetBytes(param["cityCode"]);
                byte[] oldCode = Encoding.ASCII.GetBytes(param["replaceCityCode"]);
                requestbody = requestbody.ReplaceBytes(oldCode, newCode);
            }
            else if (param.ContainsKey("pollutantCode"))
            {
                byte[] arrOutput = { 0x09, 0x03, 0x01, 0x06, 0x03, 0x38, 0x01 };
                byte[] arrOutput2 = { 0x09, 0x03, 0x01, 0x06, 0x03, 0x38, 0x01 };
                arrOutput2[5] = (byte)param["pollutantCode"].ElementAt(0);
                requestbody = requestbody.ReplaceBytes(arrOutput, arrOutput2);
            }

            return requestbody;
        }
コード例 #5
0
ファイル: henanSrcUrl.cs プロジェクト: xiaoyao9184/AQISet
        /// <summary>
        /// 拼接请求体
        ///     .可以重写
        /// </summary>
        /// <remarks>
        /// DSId必须要与Cookie对应,需要通过 <see cref="_5"/> 动态获取,DSId将以字节方式替换旧的DSId;替换cityCode
        /// </remarks>
        /// <param name="param">参数列表</param>
        /// <returns></returns>
        public override byte[] MakeRequestBody(AqiParam param)
        {
            byte[] requestbody = base.MakeRequestBody(param);
            byte[] newDSId = Encoding.ASCII.GetBytes(param["DSId"]);
            byte[] oldDSId = Encoding.ASCII.GetBytes(param["replaceDSId"]);

            while (requestbody.FindBytes(oldDSId) >= 0)
            {
                requestbody = requestbody.ReplaceBytes(oldDSId, newDSId);
            }

            if (param.ContainsKey("stationCode"))
            {
                byte[] newCode1 = Encoding.ASCII.GetBytes(param["cityCode"]);
                byte[] newCode2 = Encoding.ASCII.GetBytes(param["stationCode"]);
                byte[] newCode = new byte[newCode1.Length + newCode2.Length + 2];
                Array.Copy(newCode1,newCode,newCode1.Length);
                Array.Copy(newCode2, 0, newCode, newCode1.Length+2, newCode2.Length);
                newCode[newCode1.Length] = 0x06;
                newCode[newCode1.Length+1] = 0x05;
                byte[] oldCode1 = Encoding.ASCII.GetBytes(param["replaceCityCode"]);
                byte[] oldCode2 = Encoding.ASCII.GetBytes("01");
                byte[] oldCode = new byte[oldCode1.Length + oldCode2.Length + 2];
                Array.Copy(oldCode1, oldCode, oldCode1.Length);
                Array.Copy(oldCode2, 0, oldCode, oldCode1.Length + 2, oldCode2.Length);
                oldCode[oldCode1.Length] = 0x06;
                oldCode[oldCode1.Length + 1] = 0x05;
                requestbody = requestbody.ReplaceBytes(oldCode, newCode);
            }
            else if (param.ContainsKey("cityCode"))
            {
                byte[] newCode = Encoding.ASCII.GetBytes(param["cityCode"]);
                byte[] oldCode = Encoding.ASCII.GetBytes(param["replaceCityCode"]);
                requestbody = requestbody.ReplaceBytes(oldCode, newCode);
            }

            return requestbody;
        }