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)\n";
}else {
$receive = '';
$out = "POST $file HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Content-Length: $len\r\n\r\n";
$out .= $post;
fwrite($fp, $out);
while (!feof($fp)) {
$receive .= fgets($fp,128);
}
fclose($fp);
$receive = explode("\r\n\r\n",$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");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值