Ejemplo n.º 1
0
        protected Dictionary <string, string> createParam(ZaloOaInfo oaInfo, JObject data)
        {
            long timestamp = (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;

            StringBuilder macContent = new StringBuilder();

            macContent.Append(oaInfo.oaId);

            Dictionary <string, string> param = new Dictionary <string, string>();

            if (data["file"] == null)
            {
                foreach (var item in data)
                {
                    macContent.Append(item.Value);
                    param.Add(item.Key, item.Value.ToString());
                }
            }
            macContent.Append(timestamp);
            macContent.Append(oaInfo.secretKey);
            string mac = MacUtils.buildMac(macContent.ToString());

            param.Add("oaid", oaInfo.oaId.ToString());
            param.Add("timestamp", timestamp.ToString());
            param.Add("mac", mac);

            return(param);
        }
Ejemplo n.º 2
0
        protected Dictionary <string, string> createOnbehalfParam(Zalo3rdAppInfo appInfo, JObject data)
        {
            long timestamp = (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;

            StringBuilder macContent = new StringBuilder();

            macContent.Append(appInfo.appId);

            Dictionary <string, string> param = new Dictionary <string, string>();

            foreach (var item in data)
            {
                macContent.Append(item.Value);
                param.Add(item.Key, item.Value.ToString());
            }
            macContent.Append(timestamp);
            macContent.Append(appInfo.secretKey);
            string mac = MacUtils.buildMac(macContent.ToString());

            param.Add("appid", appInfo.appId.ToString());
            param.Add("timestamp", timestamp.ToString());
            param.Add("mac", mac);

            return(param);
        }
Ejemplo n.º 3
0
        public JObject excuteRequest(string endPoint, string method, Dictionary <string, string> param)
        {
            string url = "";
            Dictionary <string, string> sortedMap = new Dictionary <string, string>();

            if (param == null)
            {
                param = new Dictionary <string, string>();
            }
            foreach (KeyValuePair <string, string> entry in param)
            {
                string key   = entry.Key;
                string value = entry.Value;
                if (key.Equals("url"))
                {
                    url = value.ToString();
                }
                else
                {
                    sortedMap.Add(key, value);
                }
            }
            StringBuilder macContent = new StringBuilder();

            macContent.Append(OaInfo.oaId);
            foreach (KeyValuePair <string, string> entry in sortedMap)
            {
                string key   = entry.Key;
                string value = entry.Value;
                if (!key.Contains("oaid") && !key.Contains("timestamp"))
                {
                    macContent.Append(value);
                }
            }
            long timestamp = (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;

            macContent.Append(timestamp);
            macContent.Append(OaInfo.secretKey);
            string mac = MacUtils.buildMac(macContent.ToString());

            sortedMap.Add("oaid", OaInfo.oaId.ToString());
            sortedMap.Add("timestamp", timestamp.ToString());
            sortedMap.Add("mac", mac);
            string response;

            if (!url.Contains(""))
            {
                response = sendHttpUploadRequest(endPoint, url, sortedMap, APIConfig.DEFAULT_HEADER);
            }
            else
            {
                if ("GET".Equals(method.ToUpper()))
                {
                    response = sendHttpGetRequest(endPoint, sortedMap, APIConfig.DEFAULT_HEADER);
                }
                else
                {
                    response = sendHttpPostRequest(endPoint, sortedMap, APIConfig.DEFAULT_HEADER);
                }
            }
            JObject result = null;

            try
            {
                result = JObject.Parse(response);
            }
            catch (Exception e)
            {
                throw new APIException("Response is not json: " + response);
            }
            return(result);
        }