using System; using System.Collections.Specialized; using System.Net; using System.Text; using WX.CRM.Common; using WX.CRM.CRMServices.SMS.InterfaceModel; namespace WX.CRM.CRMServices.SMS.InterfaceExec { internal class ZQZXSms : IMsgSend { string account = ""; string pwd = ""; string url = ""; public ZQZXSms(string _account = "", string _password = "") { ZQZXSmsConfig config = new ZQZXSmsConfig(); account = config.account; pwd = config.pwd; url = config.url; if (!string.IsNullOrEmpty(_account) && !string.IsNullOrEmpty(_password)) { pwd = _password; account = _account; } } public InterfaceModel.ReturnResult Execute(string[] mobiles, string msg) { return Send(mobiles, msg); } public decimal queryAmt() { throw new NotImplementedException(); } #region InterfaceModel.ReturnResult Send(string[] mobiles, string msg) { string mobilesStr = string.Join(",", mobiles); InterfaceModel.ReturnResult result = new InterfaceModel.ReturnResult(); result.SendStr = mobilesStr; try { WebClient webClient = new WebClient(); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); NameValueCollection postValues = new NameValueCollection(); webClient.Encoding = Encoding.UTF8; //postValues.Add("command", "MT_REQ"); postValues.Add("user", account); postValues.Add("pass", pwd); postValues.Add("mobile", mobilesStr);//15112168561,13416115228 msg = "【证券之星】" + msg; postValues.Add("content", msg); postValues.Add("encode", "UTF8"); byte[] responseArray = webClient.UploadValues(url, postValues); result.ReturnStr = Encoding.UTF8.GetString(responseArray); //command=MO_RES&userid=abc&mostat=ACCEPTD 成功 if (result.ReturnStr == "0") result.submitStatus = SubmitStatus.success; else result.submitStatus = SubmitStatus.fail; } catch (Exception ex) { result.submitStatus = SubmitStatus.fail; WX.CRM.Common.LogHelper.Error("EntSms.Send:" + ex.Message + ex.StackTrace); } return result; } public static string ToHex(string s, string charset, bool fenge) { if ((s.Length % 2) != 0) { s += "";//空格 } Encoding chs = Encoding.GetEncoding(charset); byte[] bytes = chs.GetBytes(s); string str = ""; for (int i = 0; i < bytes.Length; i++) { str += string.Format("{0:X}", bytes[i]); if (fenge && (i != bytes.Length - 1)) { str += string.Format("{0}", ","); } } return str.ToLower(); } #endregion public static String encodeHexStr(String realStr, int dataCoding = 15) { string strhex = ""; try { Byte[] bytSource = null; if (dataCoding == 15) { bytSource = Encoding.GetEncoding("GBK").GetBytes(realStr); } else if (dataCoding == 8) { bytSource = Encoding.BigEndianUnicode.GetBytes(realStr); } else { bytSource = Encoding.ASCII.GetBytes(realStr); } for (int i = 0; i < bytSource.Length; i++) { strhex = strhex + bytSource[i].ToString("X2"); } } catch (Exception ex) { LogHelper.Error(ex.ToString()); } return strhex; } //hex编码还原成字符 public static String decodeHexStr(String hexStr, int dataCoding = 15) { String strReturn = ""; try { int len = hexStr.Length / 2; byte[] bytSrc = new byte[len]; for (int i = 0; i < len; i++) { string s = hexStr.Substring(i * 2, 2); bytSrc[i] = Byte.Parse(s, System.Globalization.NumberStyles.AllowHexSpecifier); } if (dataCoding == 15) { strReturn = Encoding.GetEncoding("GBK").GetString(bytSrc); } else if (dataCoding == 8) { strReturn = Encoding.BigEndianUnicode.GetString(bytSrc); } else { strReturn = System.Text.ASCIIEncoding.ASCII.GetString(bytSrc); } } catch { } return strReturn; } } }