zoukankan      html  css  js  c++  java
  • PHP 做群发短信(短信接口连接问题)

    function sendSMS($http,$username,$password,$sendmobile,$send_content){
       $httpurl = $http;
       $data = array
        (
        'USERNAME'=>$username,     //用户账号
        'PASSWORD'=>$password, //用户密码
        'MOBILE'=>$sendmobile,    //号码
        'CONTENT'=> mb_convert_encoding($send_content,'GB2312','UTF-8'), //内容
        );
       $re= $this->postSMS($httpurl,$data);   //POST方式提交
       if(trim($re)>0)
       {
        return "success";
       }
       else
       {
        return "error";
       }
    }
     function postSMS($httpurl,$data=''){
     $row = parse_url($httpurl);
     $host = $row['host'];
     $port = isset($row['port']) ? $row['port']:80;
     $file = $row['path'];
     $post = '';
     while (list($k,$v) = each($data))
     {
      $post .= ($k)."=".($v)."&"; 
     }
     $post = substr($post,0 ,-1);
     $len = strlen($post);
     
     $fp = @fsockopen( $host ,$port, $errno, $errstr, 10);
     if (!$fp) {
      return "$errstr ($errno) ";
      }else {
      $receive = '';
      $out = "POST $file HTTP/1.1 ";
      $out .= "Host: $host ";
      $out .= "Content-type: application/x-www-form-urlencoded ";
      $out .= "Connection: Close ";
      $out .= "Content-Length: $len ";
      $out .= $post; 
      fwrite($fp, $out);
      while (!feof($fp)) {
       $receive .= fgets($fp,128);
      }
      fclose($fp);
      $receive = explode(" ",$receive);
      unset($receive[0]);
      return implode("",$receive);
     }
    }

    PHP处理页面

    $sendmobile = isset($_POST['mobile']) ? trim($_POST['mobile']) : '';
     $hm_arr = explode(',', $sendmobile);
     $sendtime = isset($time) ? strtotime($time) : $systime;
     $sendcontent = isset($_POST['contentname']) ? trim($_POST['contentname']) : '';
     $sendstatus = 1;
     $sendsign = isset($_POST['sendsign']) ? trim($_POST['sendsign']) : '';
     $send_content = $sendcontent.'  --'.$sendsign;
     $httpurl = $sms_config['httpurl'];
     $username = $sms_config['username'];
     $password = $sms_config['password'];
     $balance_info = $balance->GetBlanceInfo($uid);
     $balance_sy = $balance_info['balance_info']-$balance_info['rate'];
     $rate = $balance_info['rate'];
     if($balance_sy > $rate){
     $hp = $balance->sendSMS($httpurl,$username,$password,$sendmobile,preg_replace('/s+/','%20',$send_content));
     if($hp == 'success'){
        $sql_c = "update {$tablepre}sms_info set balance_info = '$balance_sy',amount = amount+'1' where userid = '$uid'";
        $rs = $db->query($sql_c);
        $sql_s = "update {$tablepre}company set corpname = '$sendsign' where userid = '$uid'";
        $rs_s = $db->query($sql_s);
        $sql = "insert into {$tablepre}sms_log (sendmobile,userid,sendtime,sendcontent,sendtype,sendstatus,sendmoney) values ('$sendmobile','$uid','$sendtime','$sendcontent','$sendtype','$sendstatus','$rate')";
        $rs = $db->query($sql);
        header("location:index.php?c=sigle_send_mess&s=1");
        }else{
        header("location:index.php?c=sigle_send_mess&s=2");
     }
       }else{
         header("location:index.php?c=sigle_send_mess&s=3");
        }

  • 相关阅读:
    JavaScript之arguments对象讲解
    JavaScript之工厂方式 构造函数方式 原型方式讲解
    JavaScript之常用方法讲解
    JavaScript之引用类型讲解
    JavaScript之数据类型讲解
    JavaScript之Cookie讲解
    __cdecl __stdcall __fastcall之函数调用约定讲解
    xp/2003开关3389指令
    php源码安装常用配置参数和说明
    用yum查询想安装的软件
  • 原文地址:https://www.cnblogs.com/xiongsd/p/3166211.html
Copyright © 2011-2022 走看看