/// <summary> /// 保存签名密钥 /// </summary> /// <param name="privateKey">密钥</param> /// <param name="password">签名密码</param> /// <returns>是否成功</returns> private bool SaveDigitalSignature(string privateKey, string password) { bool returnValue = false; // 01: 保存文件路径 string fileName = this.txtOutput.Text + "\\" + UserInfo.RealName + ".Key"; // 这里需要判断文件是否已经存在 if (System.IO.File.Exists(fileName)) { if (MessageBox.Show("签名密钥" + UserInfo.RealName + ".Key" + "已存在,您确认要覆盖原文件吗?", AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.OK) { // 文件已经存在,不能覆盖的为好,或者需要提醒才可以。 return(returnValue); } } XmlDocument xmlDocument = new XmlDocument(); XmlNode xmlNode = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null); xmlDocument.AppendChild(xmlNode); XmlNode root = xmlDocument.CreateElement("DigitalSignature"); xmlDocument.AppendChild(root); XmlElement xmlElement = xmlDocument.CreateElement("Key"); // 02: 当前用户的Id保存到xml文件 xmlElement.SetAttribute("Id", UserInfo.Id); // 03:当前的用户名为文件名 xmlElement.SetAttribute("UserName", UserInfo.UserName); // 04:当前的用户名签名密码(加密保存,单向加密) xmlElement.SetAttribute("SignedPassword", SecretUtil.md5(password, 32)); // 05: 当前创建日期保存到xml文件 xmlElement.SetAttribute("CreateOn", DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat)); // 06: 当前私钥保存到xml文件 xmlElement.SetAttribute("PrivateKey", privateKey); root.AppendChild(xmlElement); // 07: 这里需要加密保存 // xmlDocument.Save("C:\\DigitalSignature.xml"); // 08: 加密文件内容 string keyFile = SecretUtil.Encrypt(xmlDocument.InnerXml); try { // 09: 创建二进制加密文件 FileUtil.WriteBinaryFile(fileName, keyFile); // 10:打开生成文件所在的目录 // Process.Start(this.txtOutput.Text); // 11:记住用户参数 DotNetService.Instance.ParameterService.SetParameter(UserInfo, "User", this.UserInfo.Id, "DigitalSignatureFilePath", this.txtOutput.Text); returnValue = true; } catch { MessageBox.Show("保存签名密钥文件失败、请重新生成签名密钥。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); returnValue = false; } return(returnValue); }
/// <summary> /// 获取商家ID的可用电子面单数量 /// </summary> /// <param name="ztoElecUserInfoEntity">申通电子面单线下商家ID实体信息</param> /// <returns></returns> public static string GetElecBillCount(ZtoElecUserInfoEntity ztoElecUserInfoEntity) { // http://testpartner.zto.cn/#mail.counter var entity = new { // 已申请过的最后一个运单号码。 (如提供此单号就以此单号开始统计未使用单号, 如不提供就查询所有未使用单号)。 // lastno string 否 100000000016 已申请过的最后一个运单号码。 (如提供此单号就以此单号开始统计未使用单号, 如不提供就查询所有未使用单号)。 lastno = "" }; // 实体构建完成了,下面开始请求动作 string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(entity)); // 正式地址 http://partner.zto.cn//client/interface.php // 测试地址 http://testpartner.zto.cn/client/interface.php var webClient = new WebClient(); string date = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat); var postValues = new NameValueCollection { { "style", "json" }, { "func", "mail.counter" }, { "content", content }, { "partner", ztoElecUserInfoEntity.Kehuid }, { "datetime", date }, { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd)) } }; byte[] responseArray = webClient.UploadValues(ElecUrl, postValues); string response = Encoding.UTF8.GetString(responseArray); if (string.IsNullOrEmpty(response)) { return("请求失败,返回值为空,可以尝试重新查询。"); } if (response.Contains("非法的数据签名") || response.Contains("s04")) { return(response + Environment.NewLine + "请右击修改商家ID信息,也可以修改默认发件人的商家ID信息,密码区分大小写,一定要看清楚" + Environment.NewLine + "商家ID和密码可以从申通物料系统通过短信方式获取到,短信上面是什么就填写什么。"); } // 返回值 {"result":"true","counter":{"available":"568"}} // response = "{\"result\": \"false\" ,\"code\": \"s05\",\"remark\": \"缺少必要的参数\"}"; // response = "-Via: 1.1 jq50:88 (Cdn Cache Server V2.0)" + Environment.NewLine + "Connection: keep-alive" +Environment.NewLine + response; // 判断一下返回的是不是json格式的数据 if (JsonSplitHelper.IsJson(response)) { var ztoElecBillCountJsonEntity = JsonConvert.DeserializeObject <ZTOElecBillCountJsonEntity>(response); if (ztoElecBillCountJsonEntity != null) { if (ztoElecBillCountJsonEntity.counter != null) { return(ztoElecBillCountJsonEntity.counter.available); } return(response); } return(response); } return(response); }
/// <summary> /// 保存签名密钥 /// </summary> /// <param name="privateKey">密钥</param> /// <param name="password">签名密码</param> /// <returns>是否成功</returns> private bool SaveDigitalSignature(string privateKey, string password) { bool returnValue = false; // 01: 保存文件路径 string fileName = this.txtDigitalSignature.Text; XmlDocument xmlDocument = new XmlDocument(); XmlNode xmlNode = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null); xmlDocument.AppendChild(xmlNode); XmlNode root = xmlDocument.CreateElement("DigitalSignature"); xmlDocument.AppendChild(root); XmlElement xmlElement = xmlDocument.CreateElement("Key"); // 02: 当前用户的Id保存到xml文件 xmlElement.SetAttribute("Id", UserInfo.Id); // 03:当前的用户名为文件名 xmlElement.SetAttribute("UserName", UserInfo.UserName); // 04:当前的用户名签名密码(加密保存) xmlElement.SetAttribute("SignedPassword", SecretUtil.md5(password, 32)); // 05: 当前创建日期保存到xml文件 xmlElement.SetAttribute("CreateOn", DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat)); // 06: 当前私钥保存到xml文件 xmlElement.SetAttribute("PrivateKey", privateKey); root.AppendChild(xmlElement); // 07: 这里需要加密保存 // xmlDocument.Save("C:\\DigitalSignature.xml"); // 08: 加密文件内容 string keyFile = SecretUtil.Encrypt(xmlDocument.InnerXml); try { // 09: 创建二进制加密文件 FileUtil.WriteBinaryFile(fileName, keyFile); // 10:打开生成文件所在的目录 // Process.Start(this.txtDigitalSignature.Text); // 11:记住用户参数 // DotNetService.Instance.ParameterService.SetParameter(UserInfo, "User", this.UserInfo.Id, "DigitalSignatureFilePath", this.txtOutput.Text); // MessageBox.Show("修改签名密码成功、请妥善保管好签名密钥文件。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("修改签名密码失败、请重修改签名密码。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); returnValue = false; } return(returnValue); }
/// <summary> /// 订单取消接口 /// </summary> /// <param name="orderNumber">订单号</param> /// <param name="ztoElecUserInfoEntity">商家ID实体</param> /// <param name="msg">错误信息</param> /// <returns></returns> public static bool BackZtoElecBill(string orderNumber, ZtoElecUserInfoEntity ztoElecUserInfoEntity, ref string msg) { try { var entity = new { id = orderNumber, remark = BaseSystemInfo.SoftFullName + "取消,商家ID:" + ztoElecUserInfoEntity.Kehuid }; // 实体构建完成了,下面开始请求动作 string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(entity)); // 正式地址 http://partner.zto.cn//client/interface.php // 测试地址 http://testpartner.zto.cn/client/interface.php var webClient = new WebClient(); string date = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat); var postValues = new NameValueCollection { { "style", "json" }, { "func", "order.cancel" }, { "content", content }, { "partner", ztoElecUserInfoEntity.Kehuid }, { "datetime", date }, { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd)) } }; byte[] responseArray = webClient.UploadValues(ElecUrl, postValues); string response = Encoding.UTF8.GetString(responseArray); if (string.IsNullOrEmpty(response)) { return(false); } // {"result":"true","id":"2b102d1b3e5542c9b6ece98cdfa82b09"} dynamic resultEntity = JsonConvert.DeserializeObject(response); if (resultEntity["result"].ToString() == "true" && resultEntity["id"].ToString() == orderNumber) { msg = "取消成功"; return(true); } msg = response; return(false); } catch (Exception) { return(false); } }
/// <summary> /// 查询申通快件跟踪 /// </summary> /// <param name="billCode"></param> /// <param name="ztoElecUserInfoEntity"></param> /// <returns></returns> public static string GetBillRecord(string billCode, ZtoElecUserInfoEntity ztoElecUserInfoEntity) { var entity = new { mailno = billCode }; string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(entity)); var webClient = new WebClient(); string date = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat); var postValues = new NameValueCollection { { "style", "json" }, { "func", "mail.trace" }, { "content", content }, { "partner", ztoElecUserInfoEntity.Kehuid }, { "datetime", date }, { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd)) } }; byte[] responseArray = webClient.UploadValues(ElecUrl, postValues); string response = Encoding.UTF8.GetString(responseArray); return(response); }
/// <summary> /// 修改签名密码 /// </summary> private bool ChangeSignedPassword() { bool returnValue = false; // 1:这里判断签名文件中的签名密码是否正确? string privateKey = string.Empty; string signedPassword = string.Empty; try { signedPassword = SecretUtil.GetSignedPassword(txtDigitalSignature.Text); if (!signedPassword.Equals(SecretUtil.md5(this.txtOldPassword.Text, 32))) { MessageBox.Show(AppMessage.Format(AppMessage.MSG0040, AppMessage.MSG9961), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtOldPassword.Focus(); this.txtOldPassword.SelectAll(); return(false); } // 2:同时可以把私钥读取出来。 privateKey = SecretUtil.GetPrivateKey(this.txtDigitalSignature.Text, this.txtOldPassword.Text); } catch { MessageBox.Show("修改签名密码失败、请重修改签名密码。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } // 3:判断服务器上的签名密码是否正确? string statusCode = string.Empty; string statusMessage = string.Empty; DotNetService.Instance.LogOnService.ChangeSignedPassword(UserInfo, this.txtOldPassword.Text, this.txtNewPassword.Text, out statusCode, out statusMessage); if (statusCode == StatusCode.ChangePasswordOK.ToString()) { // 4:保存签名密钥 this.SaveDigitalSignature(privateKey, this.txtNewPassword.Text); // 修改数字签名后的方法 if (AfterChangeDigitalSignature != null) { AfterChangeDigitalSignature(this.UserInfo.Id); } else { if (BaseSystemInfo.ShowInformation) { // 提示修改成功 MessageBox.Show("修改签名密码成功、请妥善保管好签名密钥文件。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } } this.DialogResult = DialogResult.OK; returnValue = true; } else { if (statusCode == StatusCode.PasswordCanNotBeNull.ToString()) { this.ClearOldPassword(); } if (statusCode == StatusCode.OldPasswordError.ToString()) { this.ClearOldPassword(); } MessageBox.Show(statusMessage, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); returnValue = false; } return(returnValue); }
/// <summary> /// 请求电子面单单号(十条请求一次) /// </summary> /// <param name="ztoPrintBillEntities">打印实体集合</param> /// <param name="ztoElecUserInfoEntity">申通电子面单商家实体</param> /// <returns></returns> public static List <ZtoPrintBillEntity> Request(List <ZtoPrintBillEntity> ztoPrintBillEntities, ZtoElecUserInfoEntity ztoElecUserInfoEntity, ref List <object> errorList) { // http://testpartner.zto.cn/ 接口文档 // 构建订单请求实体集合(现在是10条请求一次) var orderBatchEntities = new List <ZtoOrderBatchEntity>(); // {"id":"778718821067/10/9","type":"","tradeid":"","mailno":"","seller":"王先生","buyer":"深圳机场vip","sender":{"id":"","name":"1000043696","company":"75578","mobile":null,"phone":"13726273582","area":"","city":"广东省,深圳市,宝安区","address":"广东省深圳市宝安区沙井街道","zipcode":"","email":"","im":"","starttime":"","endtime":"","isremark":"true"},"receiver":{"id":"","name":"陈小姐","company":"","mobile":"0755-27263516","phone":"0755-27263516","area":"","city":"广东省,深圳市,宝安区","address":"沙井街道南环路马鞍山耗三工业区第三栋(凯强电子)","zipcode":"","email":"","im":""},"items":null} foreach (var ztoPrintEntity in ztoPrintBillEntities) { var orderBatchEntity = new ZtoOrderBatchEntity { Id = ztoPrintEntity.OrderNumber }; ztoPrintEntity.CreateSite = orderBatchEntity.Id; orderBatchEntity.Seller = ztoPrintEntity.SendMan; orderBatchEntity.Buyer = ztoPrintEntity.ReceiveMan; // 构建订单发件人 var sender1 = new Sender { Name = ztoPrintEntity.SendMan, Mobile = ztoPrintEntity.SendPhone, Phone = ztoPrintEntity.SendPhone, City = string.Format("{0},{1},{2}", ztoPrintEntity.SendProvince, ztoPrintEntity.SendCity, ztoPrintEntity.SendCounty), Address = ztoPrintEntity.SendAddress, Isremark = "true" }; // 构建订单收件人 var receiver = new Receiver { Name = ztoPrintEntity.ReceiveMan, Phone = ztoPrintEntity.ReceivePhone, Mobile = ztoPrintEntity.ReceivePhone, City = string.Format("{0},{1},{2}", ztoPrintEntity.ReceiveProvince, ztoPrintEntity.ReceiveCity, ztoPrintEntity.ReceiveCounty), Address = ztoPrintEntity.ReceiveAddress }; orderBatchEntity.Sender = sender1; orderBatchEntity.Receiver = receiver; orderBatchEntities.Add(orderBatchEntity); } // 实体构建完成了,下面开始请求动作 string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(orderBatchEntities)); //if (string.IsNullOrEmpty(content)) //{ // LogUtil.WriteInfo("发现content内容是空的" + ztoElecUserInfoEntity.Kehuid); // //foreach (var ztoOrderBatchEntity in orderBatchEntities) // //{ // // errorList.Add(new { 订单号 = ztoOrderBatchEntity.Id, 错误信息 = "请求构建的电子面单实体信息是:" + JsonConvert.SerializeObject(ztoOrderBatchEntity) }); // //} //} //else //{ // LogUtil.WriteInfo("发现content内容不是空的" + ztoElecUserInfoEntity.Kehuid+Environment.NewLine+content); //} // 正式地址 http://partner.zto.cn//client/interface.php // 测试地址 http://testpartner.zto.cn/client/interface.php var webClient = new WebClient(); string date = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat); var postValues = new NameValueCollection { { "style", "json" }, { "func", "order.batch_submit" }, { "content", content }, { "partner", ztoElecUserInfoEntity.Kehuid }, { "datetime", date }, { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd)) } }; byte[] responseArray = webClient.UploadValues(ElecUrl, postValues); string response = Encoding.UTF8.GetString(responseArray); //if (response.Contains("s51") || response.Contains("可用单号不足")) //{ // XtraMessageBox.Show("可用单号不足,请在申通物料系统购买电子面单,点击确定跳转到物料系统。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); // ToolHelper.OpenBrowserUrl("https://sso.zt-express.com/?SystemCode=WULIAO&openId=false"); // return null; //} // 这是正常的json {"result": "true","keys": [{"result":"true","id": "91ebc0f5bb8e48bba16fba4ad47e6832","orderid": "91ebc0f5bb8e48bba16fba4ad47e6832","mailno": "530557076165","mark":"南昌转吉安县","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "a8a8e5c047304b6ea9f84cd8d87c86fa","orderid": "a8a8e5c047304b6ea9f84cd8d87c86fa","mailno": "530557076172","mark":"长沙转冷水江","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "4eb5de495ba546f6aa7563ab1cd98c8c","orderid": "4eb5de495ba546f6aa7563ab1cd98c8c","mailno": "530557076180","mark":"北京 43-04","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "d63729ba2a1640ce9d09dfa62b0b2c36","orderid": "d63729ba2a1640ce9d09dfa62b0b2c36","mailno": "530557076197","mark":"长沙转冷水江","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "6c471fafb9824a2bbb60773d3f1b020b","orderid": "6c471fafb9824a2bbb60773d3f1b020b","mailno": "530557076202","mark":"长沙转冷水江","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "07ded9b31eb4427394c71fdd970f23d6","orderid": "07ded9b31eb4427394c71fdd970f23d6","mailno": "530557076210","mark":"深圳转 03-06","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "a0f692c695054ffb833cef7b8f144445","orderid": "a0f692c695054ffb833cef7b8f144445","mailno": "530557076227","mark":"长沙转冷水江","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "93223e4330f5420fb007588183ff23ef","orderid": "93223e4330f5420fb007588183ff23ef","mailno": "530557076234","mark":"珠海香洲 02-01","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "02251d35561548319378e9e4815c8bf1","orderid": "02251d35561548319378e9e4815c8bf1","mailno": "530557076241","mark":"成都转宜宾","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "06961e5c671444cb8132d89954190083","orderid": "06961e5c671444cb8132d89954190083","mailno": "530557076259","mark":"佛山 05-06","sitecode":"41610","sitename":"锦州"}]} // 这是错误的json {"result": "true","keys": [{"result": "false","id": "2b736e2e291d49c689d80a62b693d71a","code": "s17","keys": "sender->mobile","remark": "数据内容太长"}]} var orderBatchResponseEntity = JsonConvert.DeserializeObject <ZtoOrderBatchResponseEntity>(response); if (orderBatchResponseEntity != null) { // 绑定大头笔和单号 // 整个请求的返回值是ok的(就是调用接口校验通过的意思) #region 返回值不为空,需要绑定单号到数据库 if (orderBatchResponseEntity.Result.ToUpper() == "TRUE") { var backZtoPrintBillEntities = new List <ZtoPrintBillEntity>(); foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities) { foreach (var keyse in orderBatchResponseEntity.Keys) { if (keyse.Id == ztoPrintBillEntity.OrderNumber) { if (!string.IsNullOrEmpty(keyse.Mailno)) { ztoPrintBillEntity.BigPen = keyse.Mark; ztoPrintBillEntity.BillCode = keyse.Mailno; backZtoPrintBillEntities.Add(ztoPrintBillEntity); break; } // 为什么失败需要告知给用户 errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = response }); } } } return(backZtoPrintBillEntities); } else { // 调用接口都没有通过,那么一般就是商家ID和密码不正确导致 foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities) { errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = response }); } } #endregion //var customerErrorEntity = JsonConvert.DeserializeObject<ZtoCustomerErrorEntity>(response); //if (customerErrorEntity != null) //{ // XtraMessageBox.Show(customerErrorEntity.Keys + customerErrorEntity.Remark + Environment.NewLine + "请在发件人表格中修改默认发件人的商家ID和密码,注意密码区分大小写。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); //} //else //{ // XtraMessageBox.Show(response, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); //} } else { foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities) { errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "接口返回值为空,无法获取单号,尝试重新获取,只要订单号在就可以重新获取,不会浪费单号" }); } } return(null); }
/// <summary> /// /// </summary> /// <param name="ztoPrintBillEntities"></param> /// <param name="ztoElecUserInfoEntity"></param> /// <returns></returns> public static List <ZtoPrintBillEntity> Request(List <ZtoPrintBillEntity> ztoPrintBillEntities, ZtoElecUserInfoEntity ztoElecUserInfoEntity) { // http://testpartner.zto.cn/ 接口文档 List <ZtoOrderBatchEntity> orderBatchEntities = new List <ZtoOrderBatchEntity>(); // {"id":"778718821067/10/9","type":"","tradeid":"","mailno":"","seller":"王先生","buyer":"深圳机场vip","sender":{"id":"","name":"1000043696","company":"75578","mobile":null,"phone":"13726273582","area":"","city":"广东省,深圳市,宝安区","address":"广东省深圳市宝安区沙井街道","zipcode":"","email":"","im":"","starttime":"","endtime":"","isremark":"true"},"receiver":{"id":"","name":"陈小姐","company":"","mobile":"0755-27263516","phone":"0755-27263516","area":"","city":"广东省,深圳市,宝安区","address":"沙井街道南环路马鞍山耗三工业区第三栋(凯强电子)","zipcode":"","email":"","im":""},"items":null} ZtoPrintBillManager printBillManager = new ZtoPrintBillManager(BillPrintHelper.DbHelper); foreach (var ztoPrintEntity in ztoPrintBillEntities) { ZtoOrderBatchEntity orderBatchEntity = new ZtoOrderBatchEntity(); // 订单号 特殊处理,如果没有填写需要生成一个唯一订单号给接口 if (!string.IsNullOrEmpty(ztoPrintEntity.OrderNumber)) { orderBatchEntity.Id = ztoPrintEntity.OrderNumber; } else { orderBatchEntity.Id = Guid.NewGuid().ToString("N").ToLower(); ztoPrintEntity.OrderNumber = orderBatchEntity.Id; printBillManager.SetProperty(ztoPrintEntity.OrderNumber, new KeyValuePair <string, object>(ZtoPrintBillEntity.FieldId, ztoPrintEntity.Id)); } ztoPrintEntity.CreateSite = orderBatchEntity.Id; orderBatchEntity.Seller = ztoPrintEntity.SendMan; orderBatchEntity.Buyer = ztoPrintEntity.ReceiveMan; Sender sender1 = new Sender { Name = ztoPrintEntity.SendMan, Mobile = ztoPrintEntity.SendPhone, Phone = ztoPrintEntity.SendPhone, City = string.Format("{0},{1},{2}", ztoPrintEntity.SendProvince, ztoPrintEntity.SendCity, ztoPrintEntity.SendCounty), Address = ztoPrintEntity.SendAddress, Isremark = "true" }; Receiver receiver = new Receiver { Name = ztoPrintEntity.ReceiveMan, Phone = ztoPrintEntity.ReceivePhone, Mobile = ztoPrintEntity.ReceivePhone, City = string.Format("{0},{1},{2}", ztoPrintEntity.ReceiveProvince, ztoPrintEntity.ReceiveCity, ztoPrintEntity.ReceiveCounty), Address = ztoPrintEntity.ReceiveAddress }; orderBatchEntity.Sender = sender1; orderBatchEntity.Receiver = receiver; orderBatchEntities.Add(orderBatchEntity); } // 实体构建完成了,下面开始请求动作 string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(orderBatchEntities).ToLower()); // 正式地址 http://partner.zto.cn//client/interface.php // 测试地址 http://testpartner.zto.cn/client/interface.php WebClient webClient = new WebClient(); string date = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat); NameValueCollection postValues = new NameValueCollection { { "style", "json" }, { "func", "order.batch_submit" }, { "content", content }, { "partner", ztoElecUserInfoEntity.Kehuid }, { "datetime", date }, { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd).ToLower()) } }; byte[] responseArray = webClient.UploadValues("http://partner.zto.cn//client/interface.php", postValues); string response = Encoding.UTF8.GetString(responseArray); if (response.Contains("s51") || response.Contains("可用单号不足")) { XtraMessageBox.Show("可用单号不足,请在中通物料系统购买电子面单,点击确定跳转到物料系统。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); ToolHelper.OpenIe("https://sso.zt-express.com/?SystemCode=WULIAO&openId=false"); return(null); } // {"result": "true","keys": [{"result":"true","id": "ztaa6c6dc3db3044b2b78844b73ec2013e","orderid": "ztaa6c6dc3db3044b2b78844b73ec2013e","mailno": "530253938633","mark":"长沙转常德","sitecode":"61201","sitename":"苏州园区六部"}]} ZtoOrderBatchResponseEntity orderBatchResponseEntity = JsonConvert.DeserializeObject <ZtoOrderBatchResponseEntity>(response); if (orderBatchResponseEntity != null) { // 绑定大头笔和单号 if (orderBatchResponseEntity.Result.ToUpper() == "TRUE") { List <ZtoPrintBillEntity> backZtoPrintBillEntities = new List <ZtoPrintBillEntity>(); foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities) { foreach (var keyse in orderBatchResponseEntity.Keys) { if (keyse.Id == ztoPrintBillEntity.OrderNumber) { ztoPrintBillEntity.BigPen = keyse.Mark; ztoPrintBillEntity.BillCode = keyse.Mailno; backZtoPrintBillEntities.Add(ztoPrintBillEntity); break; } } } return(backZtoPrintBillEntities); } ZtoCustomerErrorEntity customerErrorEntity = JsonConvert.DeserializeObject <ZtoCustomerErrorEntity>(response); if (customerErrorEntity != null) { XtraMessageBox.Show(customerErrorEntity.Keys + customerErrorEntity.Remark + Environment.NewLine + "请在确认默认发件人的商家ID和密码是否正确。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show(response, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { XtraMessageBox.Show(response, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } return(null); }
/// <summary> /// 用户密码加密处理功能 /// /// 用户的密码到底如何加密,数据库中如何存储用户的密码? /// 若是明文方式存储,在管理上会有很多漏洞,虽然调试时不方便,当时加密的密码相对是安全的, /// 而且最好是密码是不可逆的,这样安全性更高一些,各种不同的系统,这里适当的处理一下就饿可以了。 /// </summary> /// <param name="password">用户密码</param> /// <returns>处理后的密码</returns> public virtual string EncryptUserPassword(string password) { // 这里也可以选择不进行处理,不加密 // return password; return(SecretUtil.md5(password, 32)); }