private void TestingWeb() { string path = AppDomain.CurrentDomain.BaseDirectory + "Images\\"; try { SmsMsg.SmsMsg smsg = new SmsMsg.SmsMsg(); string result = smsg.TestingWebService(); if (result == "ok") { ShowImage(this.picweb, path + "ok.png"); } else { ShowImage(this.picweb, path + "no.png"); lblerror_web.Text = "请检查配置文件 key=webservice 中的地址是否正确!"; } } catch (Exception) { ShowImage(this.picweb, path + "no.png"); lblerror_web.Text = "请检查配置文件 key=webservice 中的地址是否正确!"; } //TcpClient client = new TcpClient(); //try //{ // string hosts = _webservice.Substring(_webservice.IndexOf(":") + 3); // string host = hosts.Substring(0, hosts.IndexOf(":")); // string ports = _webservice.Substring(_webservice.LastIndexOf(":") + 1); // int port = Convert.ToInt32(ports.Substring(0, ports.IndexOf("/"))); // var ar = client.BeginConnect(host, port, null, null); // ar.AsyncWaitHandle.WaitOne(2); // if (client.Connected) // { // ShowImage(this.picweb, path + "ok.png"); // } // else // { // ShowImage(this.picweb, path + "no.png"); // lblerror_web.Text = "请检查配置文件 key=webservice 中的地址是否正确!"; // } //} //catch (Exception) //{ // ShowImage(this.picweb, path + "no.png"); // lblerror_web.Text = "请检查配置文件 key=webservice 中的地址是否正确!"; //} }
private void TestingPhone() { string path = AppDomain.CurrentDomain.BaseDirectory + "Images\\"; try { SmsMsg.MySoapHeader header = new SmsMsg.MySoapHeader(); header.loginName = this.txtUser.Text; header.loginPwd = MD5Helper.MD5Encrypt32bit(this.txtPwd.Text); SmsMsg.SmsMsg smg = new SmsMsg.SmsMsg(); smg.MySoapHeaderValue = header; bool authen = smg.TestingAuthentication(); if (authen) { StringBuilder sb = new StringBuilder(); sb.Append("?regcode=" + _regcode); sb.Append("&pwd=" + _pwd); sb.Append("&phone=" + this.txtMoblie.Text); sb.Append("&CONTENT=" + HttpUtility.UrlEncode("【和合益生】此条为接口测试短信,若收到则测试成功!", Encoding.GetEncoding("GBK"))); sb.Append("&extnum=&level=1&schtime=null&reportflag=1&url=&smstype=0&key=" + _mobileKey); string result = NetHelper.RequestGetUrl(_mobileSendPath + sb.ToString()); if (!string.IsNullOrWhiteSpace(result)) { string strTest = Regex.Match(result, @"(?<=<result>)(.*?)(?=</result>)").Value; if (strTest == "0") { ShowImage(picmobile, path + "ok.png"); LogHelper.Info("当前操作员使用账号" + this.txtUser.Text + "发送一条测试短信。"); } else { ShowImage(picmobile, path + "no.png"); lblerror_mobile.Text = "短信发送到手机端失败!检查配置key=mobileSendPath是否正确,错误代码:" + strTest; } } else { ShowImage(picmobile, path + "no.png"); lblerror_mobile.Text = "调用短信接口失败!"; } } else { ShowImage(picmobile, path + "no.png"); lblerror_mobile.Text = "调用WebService身份认证失败"; } } catch (Exception ex) { LogHelper.Error(ex); ShowImage(picmobile, path + "no.png"); lblerror_mobile.Text = "系统异常,错误原因:" + ex.Message; } //SmsMsg.SmsMsg sm = new SmsMsg.SmsMsg(); //var msg = sm.SmsSend(this.txtMoblie.Text, "此条为接口测试短信,若收到则测试成功!", _adminID, _adminName, null, null, 0, null); //string path = AppDomain.CurrentDomain.BaseDirectory + "Images\\"; //JavaScriptSerializer jss = new JavaScriptSerializer(); //SmsError error = jss.Deserialize<SmsError>(msg); //if (error != null && error.errorNum == "000") //{ // StringBuilder sb = new StringBuilder(); // sb.Append("regcode="+_regcode); // sb.Append("&pwd=" + _pwd); // sb.Append("&phone="+this.txtMoblie.Text); // sb.Append("&CONTENT=" + HttpUtility.UrlEncode("【和合益生】此条为接口测试短信,若收到则测试成功!", Encoding.GetEncoding("GBK"))); // sb.Append("&extnum=&level=1&schtime=null&reportflag=1&url=&smstype=0&key=" + _mobileKey); // string result = NetHelper.RequestGetUrl(_mobileSendPath + sb.ToString()); // if (!string.IsNullOrWhiteSpace(result)) // { // string strTest = Regex.Match(result, @"(?<=<result>)(.*?)(?=</result>)").Value; // if (strTest == "0") // { // ShowImage(picmobile, path + "ok.png"); // } // else // { // ShowImage(picmobile, path + "no.png"); // lblerror_mobile.Text = "短信发送到手机端失败!错误代码:" + strTest; // } // } //} //else //{ // ShowImage(picmobile, path + "no.png"); // lblerror_mobile.Text = "短信数据插入数据库失败!错误代码:" + error.errorNum + ",错误原因:" + error.errosMsg; //} }