组织台球赛期间,看到Troy推荐的天翼应用工厂 – http://www.189works.com/
开放API接口,直接能调用电信的短信,语音,GPRS应用。
正好解决了短信通知运动员的问题。记得上次组织Baan战友聚会的时候,就想如果有一个群发短信的软件多好。
当时在网上找到了解决方案,需要短信猫。需要硬件支持,或者一次性购买多少短信的那种在线服务。想想有风险,就没做。现在有了这个解决方案,真是组织活动者的福音。
事不迟疑,立即开发,花了两个晚上,做了一个简单的页面,经过几次试验,真的很好用,给运动员群发信息,直接点一下,整个办公室的手机一起响。。。O(∩_∩)O哈哈哈~
把程序给大家贡献一下,有兴趣的也去搞个自己的垃圾短信工厂!O(∩_∩)O哈哈~,挨骂别怪我。
step 1.在数据库里做个表
USE [MESSAGE]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[m_user](
[u_id] [int] IDENTITY(1,1) NOT NULL,
[u_name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[u_gender] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[u_group] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[u_num] [numeric](18, 0) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
step 2:设计个简单的页面,像下面那样拖几个控件:
Step 3:写几行程序:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
userdata("select * from m_user order by u_group");
connection.Open();
DataSet group = new DataSet();
String grouplist = "select distinct [u_group] from m_user";
SqlDataAdapter groupad = new SqlDataAdapter(grouplist, connection);
groupad.Fill(group, "grouplist");
DropDownList_group.DataSource = group.Tables["grouplist"];
DropDownList_group.DataTextField = "u_group";
DropDownList_group.DataValueField = "u_group";
DropDownList_group.DataBind();
DropDownList_group.Items.Insert(0, "请选择用户组");
//DropDownList_user.Items.Insert(0, "请选择用户");
connection.Close();
}
}
private void userdata(String sqlstring)
{
connection.Open();
SqlDataAdapter myad = new SqlDataAdapter(sqlstring, connection);
DataSet myds = new DataSet();
myad.Fill(myds, "users");
GridView1.DataSource = myds.Tables["users"];
GridView1.DataBind();
connection.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
userdata("select * from m_user ");//重新绑定GridView数据的函数
}
protected void Button_send_Click(object sender, EventArgs e)
{
//发送方的Ap编号
decimal APID = 10011XXX;
//短信发送能力编号
decimal FuncID = 10000033;
//能力管控平台分配给AP的密钥
string APKey = "XXXXXXXXXXXXXXXXXXXXXXXX";
int j = 0;
while (j < GridView1.Rows.Count)
{
System.Web.UI.WebControls.CheckBox check = new CheckBox();
check = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[j].Cells[0].FindControl("CheckBox_select");
if (check.Checked)
{
string num = GridView1.Rows[j].Cells[4].Text.ToString().Trim();
String name = GridView1.Rows[j].Cells[1].Text.ToString().Trim();
String chenghu = GridView1.Rows[j].Cells[2].Text.ToString().Trim();
//发送的信息内容
string msg = "尊敬的" + name + chenghu + ":" + TextBox_message.Text.ToString();
//发出短信的IMS号码,可为空
string from = "";
//鉴权认证接口地址,可为空。为空时取默认值
string AuthInterfaceURL = "";
//发送短信接口地址,可为空。为空时取默认值
string SendMsgURL = "";
//发送失败时,返回的错误提示
string errMsg = "";
int ret = AMCP.PSO.SendManage.Sen
d(APID, FuncID, APKey, num, msg, from, AuthInterfaceURL, SendMsgURL, out errMsg);
if (ret == 0)
{
//短信发送成功
//在这里Ap可以写上自己的业务逻辑
}
else
{
//失败
//可以根据 errMsg 查询失败原因
}
}
j++;
}
Label_error.Visible = true;
Label_error.Text = "发送成功!";
}
protected void Button_filter_Click(object sender, EventArgs e)
{
String condition = "select * from m_user where 1 = 1 ";
if (DropDownList_group.SelectedIndex != 0)
{
condition = condition + " and u_group = ‘" + DropDownList_group.SelectedValue.ToString() + "’";
}
if (DropDownList_user.SelectedIndex != 0)
{
condition = condition + " and u_name = ‘" + DropDownList_user.SelectedValue.ToString() + "’";
}
userdata(condition);
}
protected void DropDownList_group_SelectedIndexChanged(object sender, EventArgs e)
{
connection.Open();
DataSet users = new DataSet();
String userlist = "select u_name from m_user where u_group = ‘" + DropDownList_group.SelectedValue.ToString().Trim() + "’";
SqlDataAdapter userad = new SqlDataAdapter(userlist, connection);
userad.Fill(users, "userlist");
DropDownList_user.DataSource = users.Tables["userlist"];
DropDownList_user.DataTextField = "u_name";
DropDownList_user.DataValueField = "u_name";
DropDownList_user.DataBind();
DropDownList_user.Items.Insert(0, "请选择用户");
connection.Close();
}
Step 4:在数据库里放几条数据,试验一下自己的垃圾短信工厂吧!O(∩_∩)O哈哈~,哎骂别怪我!