Exemple #1
0
        public bool EncodeApply(int amount, out string applyKey, out string messages)
        {
            bool succeed = false;

            applyKey = string.Empty;
            messages = string.Empty;
            string baseUrl   = inputParameters["InterfaceAddress"];
            string clientId  = inputParameters["ClientId"];
            long   timeStamp = (long)(DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1))).TotalMilliseconds;
            string sign      = Tools.AESEncode(clientId + timeStamp, inputParameters["AESKey"]);
            Gather gather    = new Gather();

            gather.Url = $@"{baseUrl}{ApplySubAddress}/clientId={clientId}/num={amount}/timeStamp={timeStamp}/sign={sign}";
            string resultHtml = gather.GetHtml();

            if (resultHtml == string.Empty)
            {
                messages = gather.TraceInfo;
            }
            else
            {
                ResultObject jsonResult = JsonConvert.DeserializeObject <ResultObject>(resultHtml);
                if (jsonResult.status == 200)
                {
                    applyKey = jsonResult.fileid;
                    succeed  = true;
                }
                else
                {
                    messages = jsonResult.msg;
                }
            }
            return(succeed);
        }
Exemple #2
0
        /// <summary>
        /// 码激活。
        /// </summary>
        /// <param name="ecodes">码集合</param>
        /// <param name="messages">提示信息</param>
        public bool EcodeActivate(List <string> ecodes, CodeActive codeActive, out string messages)
        {
            bool succeed = false;

            messages = string.Empty;
            string baseUrl   = inputParameters["InterfaceAddress"];
            string clientId  = inputParameters["ClientId"];
            long   timeStamp = (long)(DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1))).TotalMilliseconds;
            string sign      = Tools.AESEncode(clientId + timeStamp, inputParameters["AESKey"]);
            Gather gather    = new Gather();

            gather.Url    = $@"{baseUrl}{ActivateSubAddress}/clientId={clientId}/timeStamp={timeStamp}/sign={sign}";
            gather.Method = "POST";

            gather.PostData = "[{\"ecode\":\"" + string.Join(",", ecodes.ToArray()) + "\",\"photo\":\"\",\"datas\":[{\"key\":\"ProductName\",\"value\":\"" + codeActive.ProductName + "\"},{\"key\":\"ProductCode\",\"value\":\"" + codeActive.ProductCode + "\"},{\"key\":\"CorpName\",\"value\":\"" + codeActive.CorpName + "\"},{\"key\":\"ProductionDate \",\"value\":\"" + codeActive.UploadDate + "\"},{\"key\":\"ProduceWorkline\",\"value\":\"" + codeActive.ProduceWorkline + "\"}]}]";
            //gather.PostData = "[{\"ecode\":\"123,123\",\"photo\":\"\",\"datas\":[{\"key\":\"产品名称\",\"value\":\"康师傅矿泉水\"},{\"key\":\"生产厂家\",\"value\":\"1\"},{\"key\":\"生产地址\",\"value\":\"1\"},{\"key\":\"生产日期\",\"value\":\"1525737600000\"},{\"key\":\"产品类型\",\"value\":\"\"},{\"key\":\"产品批次\",\"value\":\"0002\"},{\"key\":\"生产数量\",\"value\":\"1\"}]}]";
            gather.ContentType = "application/json";
            string       resultHtml = gather.GetHtml();
            ResultObject jsonResult = JsonConvert.DeserializeObject <ResultObject>(resultHtml);

            if (jsonResult != null && jsonResult.status == 200)
            {
                succeed = true;
            }
            else
            {
                if (jsonResult == null)
                {
                    messages = "码激活操作对方接口平台无结果反馈";
                }
                else
                {
                    messages = jsonResult.msg;
                }
            }

            return(succeed);
        }
Exemple #3
0
        public List <string> EncodeDownload(string applyKey, out byte[] originalCodeData)
        {
            originalCodeData = null;
            List <string> keyList = new List <string>();
            //bool succeed = false;
            string messages  = string.Empty;
            string baseUrl   = inputParameters["InterfaceAddress"];
            string clientId  = inputParameters["ClientId"];
            long   timeStamp = (long)(DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1))).TotalMilliseconds;
            string sign      = Tools.AESEncode(clientId + timeStamp, inputParameters["AESKey"]);
            Gather gather    = new Gather();

            gather.Url = $@"{baseUrl}{DownloadCodeSubAddress}/clientId={clientId}/fileId={applyKey}/timeStamp={timeStamp}/sign={sign}";

            using (System.IO.Stream resultStream = gather.GetStream())
            {
                if (resultStream == null)
                {
                    throw new Exception($"码下载失败!\n对方平台提示信息:{gather.TraceInfo}");
                }
                else
                {
                    if (resultStream.Length < 500)
                    {
                        using (System.IO.StreamReader streamReader = new System.IO.StreamReader(resultStream, System.Text.Encoding.UTF8, true, 1000, true))
                        {
                            string codesStr   = streamReader.ReadToEnd();
                            bool   errorState = false;
                            try
                            {
                                ResultObject jsonResult = JsonConvert.DeserializeObject <ResultObject>(codesStr);
                                if (jsonResult.status != 200)
                                {
                                    errorState = true;
                                    messages   = jsonResult.msg;
                                }
                            }
                            catch
                            {
                            }
                            if (errorState)
                            {
                                throw new Exception($"码下载失败!\n对方平台提示信息:{messages}");
                            }
                        }
                    }
                    string content = string.Empty;
                    originalCodeData = new byte[resultStream.Length];
                    resultStream.Read(originalCodeData, 0, (int)resultStream.Length);
                    if (Tools.UnZipGetFirstText(resultStream, out content))
                    {
                        keyList = ConvertToCodeList(content);
                    }
                    else
                    {
                        throw new Exception($"码下载失败!\n码文件解压失败!");
                    }
                }
            }
            return(keyList);
        }