网上手机短信发送代码网上手机短信发送代码

来源:互联网 发布:js给隐藏控件赋值 编辑:程序博客网 时间:2024/04/27 16:57
[code]
<?
//手机注册函数
function mobile_register($mobile_no,$passwd)
{
   $msg="欢迎使用“中伟网络办公伙伴” 您得密码是$passwd 成都中振 028-85177035 http://www.hizz.com.cn" ;
   //调用发送短信函数
   mobile_send($mobile_no,$mobile_no,$msg);
}//End Function
//手机短信发送函数
function mobile_send($from_name,$from_mobile,$to,$msg,$expire="")
{
   if ($from_mobile=="") {
      echo "<p style=color:white><B><IMG SRC=/img/menu/8.gif WIDTH=24 HEIGHT=25 BORDER=0 ALT=>您还没有注册手机短信功能,请到系统管理里注册后再使用!<br>";
      echo "<p style=color:white>以上短信并未真实发送!</B><br>";
      return false;   
      
   }
   //$to形式为 num1,num2,num3,num4,num5...,但不能超过255个;   
   //把信息以内码ASC码16进制编码
   //expire短信过期时间,如果不填默认当前时间
   if(substr($to,-1,1)==","){
      $to = substr($to,0,strlen($to)-1);
   }
   if ($expire==""){
      $ScheduleTime=date("ymdHis",time());
      $ExpireTime="";         
   }else{
      $ScheduleTime=$expire;
      $ExpireTime=$expire;      //6小时后过期
   }
   $msg = $from_name.":".$msg;
   $msg = bin2hex($msg);
   
   //用TCP方式连接到短信网关
   $fp=fsockopen("202.99.xxx.xxx",1020,&$errno, &$errstr, 10) or die("<p style=color:white;> 不能连接到Internet,请确信您得服务器是和Internet连接的!<INPUT TYPE=button class="bigButton" onclick="javascript:history.go(-1)" value=" 返 回 " size="20"></p>");;
   
   //发送用户信息,打开连线
   fputs($fp,"login name=88444&pwd=passwd123&type=0rn");
   $return=fgets($fp,4);
   if($return!="Pass"){
      echo "<p style=color:white;>不能连接到短信网关!请梢后再试!";
      echo "<INPUT TYPE=button class="bigButton" onclick="javascript:history.go(-1)" value=" 返 回 " size="20"></p>";
      return false;
      //exit;
   }
   fputs($fp,"Submit ");                  //发送短信
   fputs($fp,"CommandID=1001");            //命令序列
   fputs($fp,"&ItemID=111001");            //节目名
   fputs($fp,"&FeeNumber=".$from_mobile);      //发送者
   fputs($fp,"&UserNumber=".$to);            //接收者
   fputs($fp,"&SpNumber=888444");            //SPnumber,发送号码
   fputs($fp,"&Msgcode=15");               //编码类型
   fputs($fp,"&FeeType=1");               //收费类型 1,免费 2,按条 3,包月
   fputs($fp,"&ScheduleTime=".$ScheduleTime);   //定时执行
   fputs($fp,"&ExpireTime=".$ExpireTime);      //报告类型
   fputs($fp,"&Msg:=$msgrn");            //发送的信息内容
//   echo fgets($fp,128);
//   fputs($fp,"Report ");
//   fputs($fp,"CommandID=1");
//   fputs($fp,"&State=0");
   fclose ($fp);
   
   return true;
}
function insert_mobile_sms($db,$CAL_ID,$TO_ID,$MOBIL_NO,$MESSAGE,$SUBMIT_TIME,$M,$ALERT){
   $sql="insert into sms_mobile (TO_ID,CAL_ID,MOBIL_NO,MESSAGE,SUBMIT_TIME,M,ALERT)values('$TO_ID','$CAL_ID','$MOBIL_NO','$MESSAGE','$SUBMIT_TIME','$M','Y')";
   $db->query($sql);
}
function update_mobile_sms($db,$CAL_ID,$TO_ID,$MOBIL_NO,$MESSAGE,$SUBMIT_TIME,$M,$ALERT){
   $sql="update sms_mobile set mobil_no='$MOBIL_NO',message='$MESSAGE',submit_time='$SUBMIT_TIME',m='$M',ALERT='$ALERT' where cal_id=$CAL_ID";
   $db->query($sql);
}
?>[/code]