public static String send(SmsInfo s, String mobile, String content) { try { //String url = s.url+"?account=" + s.account + "&pswd=" + s.pswd + "&mobile=" + mobile + "&msg=" + System.Web.HttpUtility.UrlEncode(content) + "&needstatus=" + s.needstatus; String newContent = SmsSend.toUrlString(content); String url = s.url + "?account=" + s.account + "&pswd=" + s.pswd + "&mobile=" + mobile + "&msg=" + newContent + "&needstatus=" + s.needstatus; Uri uri = new Uri(url); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); log.write(mobile + "--" + content.Trim()); log.write(retString); return(retString.Split(',')[1]); } catch { return("wrong"); } }
private void button3_Click(object sender, EventArgs e) { if (contentTxt.Text.Length > 0) { if (mobiles.Count > 0) { DialogResult dr = MessageBox.Show(msgLab.Text + "\n\n短信内容如下:\n" + contentTxt.Text + "\n\n确定吗?", "发送确认", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { int sc = 0, fc = 0; foreach (String mobile in mobiles) { String r = SmsSend.send(smsInfo, mobile, contentTxt.Text); if (r.Equals("0")) { sc++; log.write(mobile + "," + 0 + " " + "成功"); } else { fc++; log.write(mobile + "," + 0 + " " + "失败"); } } snum += sc; num += sc + fc; string b = "发送成功:" + sc + "人\n发送失败:" + fc + "人"; log.write(b); MessageBox.Show(b, "发送状态"); } else { MessageBox.Show("短信未发送!"); } } else { MessageBox.Show("没有用户,请检查后重试!"); } } else { MessageBox.Show("请输入短信内容!"); } sumLab.Text = "登录成功后,你已发送了 " + num + " 条信息,成功了 " + snum + " 条"; log.write(sumLab.Text); }