Example #1
0
        private void SendSupplierData()
        {
            ErrorLog.Write("执行了SupplierJobs -> SendSupplierData");
            try
            {
                string setdate = this.GetOrderSendCoupontime();

                SupplierQuery query = new SupplierQuery();
                query.PageIndex         = pageIndex;
                query.PageSize          = 100;
                query.DateContrastType  = dateContrastType;
                query.DateContrastValue = dateContrastValue;
                query.DataVersion       = setdate;
                query.SortBy            = "DataVersion";

                ErrorLog.Write("执行了SupplierJobs -> GetWMSSupplier");

                DataTable dt = (DataTable)SupplierHelper.GetWMSSupplier(query).Data;

                ErrorLog.Write("执行了SupplierJobs -> GetWMSSupplier 查询完成");
                if (dt != null && dt.Rows.Count > 0)
                {
                    ErrorLog.Write("执行了SupplierJobs -> GetWMSSupplier 查询结果:" + dt.Rows.Count);

                    pageIndex++;
                    flag = true;

                    string skuData = CreateSupplierData(dt);
                    //WMS 无法正常接收部分字符
                    skuData = skuData.Replace("\n", "").Replace("\t", "").Replace("\r", "").Replace("+", "+");
                    string tempdata     = appSecret + skuData + appSecret;
                    string md5tempdata  = WMSHelper.MD5(tempdata);
                    string basetempdata = WMSHelper.EncodingString(md5tempdata.ToLower(), System.Text.Encoding.UTF8);
                    sign = System.Web.HttpUtility.UrlEncode(basetempdata.ToUpper(), System.Text.Encoding.UTF8);

                    //
                    timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//YYYY-MM-DD HH:MM:SS

                    string postData = "method=putCustData&client_customerid=" + customerid + "&client_db=" + client_db + "&messageid=CUSTOMER&apptoken=" + apptoken + "&appkey=" + appkey + "&sign=" + sign + "&timestamp=" + timestamp;

                    //.NET和java UrlEncode处理机制不一样,加号"+"在java里面会被替换成空格,需要转换2次
                    skuData = System.Web.HttpUtility.UrlEncode(skuData);
                    //skuData = System.Web.HttpUtility.UrlEncode(skuData);

                    //文本日志
                    ErrorLogs("url=" + url + ";postData=" + postData + "&data=" + tempdata);
                    //数据库日志
                    WMSHelper.SaveLog("putCustData", tempdata, "调用方法", "info", "out");

                    string sendResult = WMSHelper.PostData(url, postData + "&data=" + skuData);
                    string tempResult = System.Web.HttpUtility.UrlDecode(sendResult);

                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(tempResult);
                    XmlNode node = xmlDocument.SelectSingleNode("Response/return/returnCode");

                    if (node.InnerText != "0000")
                    {
                        ErrorLogs("调用WMS推送商家失败:" + tempResult + "\n");
                        WMSHelper.SaveLog("putCustData", "", "返回结果:" + tempResult, "error", "in");

                        SmsHelper.QueueSMS(mobiles, "系统在" + DateTime.Now.ToString("yyyy年MM月HH点mm分ss秒") + "调用WMS推送商家(putCustData)接口失败,详情请查询推送日志", 3);
                    }
                    else
                    {
                        //更新最后一个推送WMS客户档案时间戳
                        this.UpdateOrderSendCoupontime(dt.Rows[dt.Rows.Count - 1]["DataVersion"].ToString());
                    }
                }
                else
                {
                    flag = false;
                }
            }
            catch (Exception ex)
            {
                ErrorLogs("出现异常:" + ex.Message);
                SmsHelper.QueueSMS(mobiles, "系统在" + DateTime.Now.ToString("yyyy年MM月HH点mm分ss秒") + "调用WMS推送商家(putCustData)接口发生异常,详情请查询推送日志", 3);
            }
            if (flag)
            {
                SendSupplierData();
            }
        }