<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>企业快信</title>
<link rel="stylesheet" type="text/css" href="css/font.css">
<script type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<style type="text/css">
<!--
body {
	background-color: #EBEBEB;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.STYLE1 {
	font-size: 12px;
	color: #575757;
}
.STYLE2 {
	color: #000000;
	font-weight: bold;
}
-->
</style>
</head>
<script language="javascript">
  function chkinput(form){
    if(form.ip.value==""){
	  alert("请输入短信网关的地址!");
	  form.ip.select();
	  return(false);
	}
	
	  if(form.port.value==""){
	  alert("请输端口号!");
	  form.port.select();
	  return(false);
	}
	
	 if(isNaN(form.port.value)==true){
	  alert("端口只能由数字组成!");
	  form.port.select();
	  return(false);
	 }
	
	
	
	 if(form.username.value==""){
	  alert("请输入用户名!");
	  form.username.select();
	  return(false);
	}
	  if(form.userpwd.value==""){
	  alert("请输入用于密码!");
	  form.userpwd.select();
	  return(false);
	}
	  if(form.telnumber.value==""){
	  alert("请输入您的手机号!");
	  form.telnumber.select();
	  return(false);
	}
	
	 if(isNaN(form.telnumber.value)==true){
	  alert("手机号只能由数字组成!");
	  form.telnumber.select();
	  return(false);
	 }
	 
	 if(form.receivenumber.value==""){
	  alert("请输入接收方手机号!");
	  form.receivenumber.select();
	  return(false);
	}
	
	 if(isNaN(form.receivenumber.value)==true){
	  alert("手机号只能由数字组成!");
	  form.receivenumber.select();
	  return(false);
	 }
	 
	  if(form.content.value==""){
	  alert("请输入短信内容!");
	  form.content.select();
	  return(false);
	}
    return(true);
  }
</script>
<body>
<center>
<table width="785" height="134" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="images/bgs (2).gif" width="785" height="134" border="0"></td>
  </tr>
</table>
<table width="785" border="0" cellpadding="0" cellspacing="0">
  <tr bgcolor="#FCFEFD">
    <td width="290" height="8" align="center" valign="top" bgcolor="#FCFEFD"></td>
    <td width="580" align="center" valign="top" bgcolor="#FCFEFD"><table width="580" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="3"><img src="images/bgs (3).gif" width="580" height="45"></td>
        </tr>
      <tr>
        <td colspan="3"><img src="images/bgs5.gif" width="580" height="25"></td>
        </tr>
      <tr>
        <td width="24" height="64" background="images/bgs6.gif"></td>
        <td width="526">
		
		<table width="520" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#B5D7EF">
      <form name="form1" method="post" action="index.php" onSubmit="return chkinput(this)">
	  <tr>
        <td height="30" colspan="4" align="center" bgcolor="#FFFFFF"><span class="STYLE2">通过socket编程发送短信</span></td>
      </tr>
      <tr>
        <td width="78" height="25" bgcolor="#FFFFFF"><div align="right" class="STYLE1">网关地址：</div></td>
        <td width="232">&nbsp;
          <input type="text" name="ip" class="inputcss" size="30" value="192.168.1.59" readonly="no"></td>
        <td width="59" align="right" bgcolor="#FFFFFF"><span class="STYLE1">端口：</span></td>
        <td width="128"><input type="text" name="port" size="10" class="inputcss" value="25" readonly="no"></td>
      </tr>
      <tr>
        <td height="20" bgcolor="#FFFFFF"><div align="right" class="STYLE1">用户名：</div></td>
        <td height="20">&nbsp;<input type="text" name="username" class="inputcss" size="30"></td>
        <td height="20" colspan="2" bgcolor="#FFFFFF">&nbsp;</td>
      </tr>
      <tr>
        <td height="20" bgcolor="#FFFFFF"><div align="right" class="STYLE1">密码：</div></td>
        <td height="20">&nbsp;<input type="password" name="userpwd" class="inputcss" size="30"></td>
        <td height="20" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" name="submit" class="buttoncss" value="发送" /></td>
      </tr>
      <tr>
        <td height="20" bgcolor="#FFFFFF"><div align="right" class="STYLE1">发送手机号：</div></td>
        <td height="20">&nbsp;<input type="text" name="telnumber" class="inputcss" size="30"></td>
        <td height="20" colspan="2" align="center" bgcolor="#FFFFFF"><input type="reset" name="reset" class="buttoncss" value="重写" /></td>
      </tr>
	  <tr>
        <td height="20" bgcolor="#FFFFFF"><div align="right" class="STYLE1">接收手机号：</div></td>
        <td height="20">&nbsp;<input type="text" name="receivenumber" class="inputcss" size="30"></td>
        <td height="20" colspan="2" bgcolor="#FFFFFF">&nbsp;</td>
	  </tr>
      <tr>
        <td height="72" bgcolor="#FFFFFF"><div align="right" class="STYLE1">短信内容：</div></td>
        <td colspan="3">&nbsp;<textarea name="content" cols="50" rows="5" class="inputcss"></textarea></td>
      </tr>
  </form>
    </table>
		
		
		
		
		</td>
        <td width="30" background="images/bgs (11).gif"></td>
      </tr>
      <tr>
        <td colspan="3"><img src="images/bgs (1).gif" width="580" height="25"></td>
        </tr>
   
    </table></td>
    <td width="290" align="center" valign="top" bgcolor="#FCFEFD"></td>
  </tr>
</table>
<table width="785" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="images/bgs.gif" width="785" height="70"></td>
  </tr>
</table>
</center>
<?php
 if($_POST[submit]!="")
 {
    $smsUID=$_POST[username];  //短信网关分配的用户名和密码  
    $smsPWD=$_POST[userpwd];  
    $smsSocket=$_POST[id];   //短信网关的IP  
    $smsPost=$_POST[port];     //短信网关的端口  
    $fp=fsockopen($smsSocket,$smsPost,$errno,$errstr,30);  
     if(!$fp)  
      {  
         echo  "<script>alert('与短信网关连接失败!');</script>";  
      }  
     else  
      {  
         //登录到短信中心服务器  
        fputs($fp,"login\n");  
        fputs($fp,$smsUID."\n");  
        fputs($fp,$smsPWD."\n");  
        fputs($fp,"\n");  
        $MessageContent=trim($_POST[content]);  
        $MobileNo=trim($_POST[telnumber]);
		$ReceiveNo=trim($_POST[receivenumber]);  
        $ServiceType="MFFW"; 			  //计费代码TP0.5按条收费  
        $Priority="0";       			  //发送优先级  
        $AgentFlag="0";  				  //代收费标志  
        $MoFlag="2";           			  //点播号  
        $ExpireTime="";   //短信失效时间  
        $ScheduleTime="";   //定时发送时间  
        $ReportFlag="1";      //状态报告  
        $status="255";       //都要返回状态报告  
        $MessageType="TEXT";       //短信类型,文本信息  
        $FreeTerminalNo=$MobileNo;    //记费手机号码,本实例采用收短信方收费 
        $TargetTerminalNo=$ReceiveNo;     //接收方手机号码  
        $SourceTerminalNo=$MobileNo;       //发送方手机号码  
        $MessageId="123";  
        print(fgets($fp,4096));  
        print(fgets($fp,4096));  
        fputs($fp,"submit"."\n");  
        fputs($fp,$MessageId."\n");  
        fputs($fp,$FreeTerminalNo."\n");  
        fputs($fp,$SourceTerminalNo."\n");  
        fputs($fp,$TargetTerminalNo."\n");  
        fputs($fp,$ServiceType."\n");  
        fputs($fp,$MoFlag."\n");  
        fputs($fp,$ReportFlag."\n");  
        fputs($fp,$ExpireTime."\n");  
        fputs($fp,$ScheduleTime."\n");  
        fputs($fp,$MessageType."\n");  
        $MessageContent=str_replace("\r","",str_replace("\n","",$MessageContent)); //不能有回车  
        fputs($fp,$MessageContent."\n");  
        fputs($fp,"\n");  
        print("<div align=center>发送成功!".$MobileNo."  :  ".$MessageContent."</div>");  
        fclose($fp);  
    }  
 }
?>
</body>
</html>
