using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
using System.Text;
using System.Drawing;
using System.Xml;

public partial class etw_c_m_mobilemessage : System.Web.UI.Page
{
    public string senddate = string.Empty;
    public string usernameid = string.Empty;
    public string alluser = string.Empty;
    public string alltel = string.Empty;
    public string telcontent = string.Empty;
    public string url = "http://www.smsadmin.cn/smsmarketing/wwwroot/api/get_send/";
    public string uid = "guomeng";
    public string pwd = "888888";
    protected void Page_Load(object sender, EventArgs e)
    {
        get_user();
        DataUser();
    }
    public void get_user()
    {
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load("http://center.etwservice.com:8080/reset_order_xml_etw/user.xml");
        XmlNodeList topM = xmldoc.SelectNodes("//channel");

        foreach (XmlElement element in topM)
        {
            if (element.Name.ToLower() == "channel")
            {
                XmlNodeList nodelist = element.ChildNodes;
                for (int i = 0; i < nodelist.Count; i++)
                {
                    senddate = element.GetElementsByTagName("senddate")[i].InnerText;
                    usernameid = usernameid + "," + element.GetElementsByTagName("usernameid")[i].InnerText;
                }
                alluser = usernameid.Trim(",".ToCharArray());
                
            }

        }
    }
    public void DataUser()
    {
        string tel=string.Empty;
        DataSet ds = DbHelperSQL.Query("select userid,company,tel from etw_user where id in(" + alluser + ") and tel!='0' and tel!='' and tel is not null ");
        if (ds.Tables[0].Rows.Count > 0)
        {
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (i%50==0)
            {
                tel = tel + "|" + ds.Tables[0].Rows[i]["tel"];
            }
            else
            {
             tel = tel + ";" + ds.Tables[0].Rows[i]["tel"];
            }
        }
        alltel = tel.Trim("|".ToCharArray());
    }
    public void step_sendmobile()
    {
        string sendtel = string.Empty;
        string yestoday=DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
        string today = DateTime.Now.ToString("yyyy-MM-dd");
        telcontent = "ETW国际温馨提示:" + yestoday + "上午10点至" + today + "上午10点,收到采购商一对一的询盘,请注意及时,有效的处理";


        try
        {
            string[] strArray = alltel.Split(new char[] { '|' });
            for (int i = 0; i < strArray.Length; i++)
            {
                //string str = "uid="+uid+"&pwd=" + pwd + "&mobile=" + strArray[i] + "&msg=" + telcontent;
                string str = "uid=" + uid + "&pwd=" + pwd + "&mobile=13817971496&msg=" + telcontent.Trim();
                Fun.curl(url + "?" + str, "", "GB2312");
            }
        }
        catch
        {
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        step_sendmobile();
    }
}
