'SDK-JMR-010-00033', ////替换成您自己的序列号 'pwd'=>strtoupper(md5('SDK-JMR-010-00033'.'893025')), //此处密码需要加密 加密方式为 md5(sn+password) 32位大写 'mobile'=>$phone,//手机号 多个用英文的逗号隔开 post理论没有长度限制.推荐群发一次小于等于10000个手机号 'content'=>$content,//短信内容 'ext'=>'', 'stime'=>'',//定时时间 格式为2011-6-29 11:09:21 'rrid'=>'' ); //构造要post的字符串 $params = ""; foreach ($argv as $key=>$value) { if ($flag!=0) { $params .= "&"; $flag = 1; } $params.= $key."="; $params.= urlencode($value); $flag = 1; } $length = strlen($params); //创建socket连接 $fp = fsockopen("sdk2.entinfo.cn",8060,$errno,$errstr,10) or exit($errstr."--->".$errno); //构造post请求的头 $header = "POST /webservice.asmx/mt HTTP/1.1\r\n"; $header .= "Host:sdk2.entinfo.cn\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: ".$length."\r\n"; $header .= "Connection: Close\r\n\r\n"; //添加post的字符串 $header .= $params."\r\n"; //发送post的数据 fputs($fp,$header); $inheader = 1; while (!feof($fp)) { $line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据 if ($inheader && ($line == "\n" || $line == "\r\n")) { $inheader = 0; } if ($inheader == 0) { // echo $line; } } //-5 $line=str_replace("","",$line); $line=str_replace("","",$line); $result=explode("-",$line); // echo $line."-------------"; if(count($result)>1) { Yii::log('发送失败返回值为:'.$line.'。请查看webservice返回值对照表'); return false; } else { Yii::log('发送成功 返回值为:'.$line); return true; } } //互亿无线的接口 function Post($curlPost,$url){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); $return_str = curl_exec($curl); curl_close($curl); return $return_str; } function xml_to_array($xml){ $reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/"; if(preg_match_all($reg, $xml, $matches)){ $count = count($matches[0]); for($i = 0; $i < $count; $i++){ $subxml= $matches[2][$i]; $key = $matches[1][$i]; if(preg_match( $reg, $subxml )){ $arr[$key] = xml_to_array( $subxml ); }else{ $arr[$key] = $subxml; } } } return $arr; } function SendSMSMessage2($phone, $content) { $target = "http://106.ihuyi.com/webservice/sms.php?method=Submit"; $post_data = "account=cf_xxkj&password=hhyz122131&mobile=".$phone."&content=".rawurlencode($content); //密码可以使用明文密码或使用32位MD5加密 Yii::log("post_data:" . $post_data); $gets = xml_to_array(Post($post_data, $target)); if ($gets['SubmitResult']['code'] == 2) { return true; } else { Yii::log("SMSErrorCode:" . $gets['SubmitResult']['code'] . " SMSResult:" . $gets['SubmitResult']['msg']); return false; } } /*------------云信使的接口-------------------- 功能: HTTP接口 发送短信 修改日期: 2011-03-04 说明: http://api.sms.cn/mt/?uid=用户账号&pwd=MD5位32密码&mobile=号码&mobileids=号码编号&content=内容 状态: 100 发送成功 101 验证失败 102 短信不足 103 操作失败 104 非法字符 105 内容过多 106 号码过多 107 频率过快 108 号码内容空 109 账号冻结 110 禁止频繁单条发送 112 号码不正确 120 系统升级 --------------------------------*/ //定时发送 /* $time = '2010-05-27 12:11'; $res = sendSMS($uid,$pwd,$mobile,$content,$time); echo $res; */ function postSMS($url,$data='') { $row = parse_url($url); $host = $row['host']; $port = isset($row['port']) ? $row['port']:80; $file = $row['path']; $post = ''; while (list($k,$v) = each($data)) { $post .= rawurlencode($k)."=".rawurlencode($v)."&"; //转URL标准码 } $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); } } function SendSMSMessage3($mobile,$content,$mobileids='',$time='',$mid='') { $http = 'http://api.sms.cn/mt/'; //短信接口 $uid = 'liantongxue'; //用户账号 $pwd = 'hhyz122131'; //密码 $content = $content . "【乐外卖】"; $content = iconv("utf-8", "gb2312//TRANSLIT", $content); $data = array ( 'uid'=>$uid, //用户账号 'pwd'=>md5($pwd.$uid), //MD5位32密码,密码和用户名拼接字符 'mobile'=>$mobile, //号码 'content'=>$content, //内容 'mobileids'=>$mobileids, 'time'=>$time, //定时发送 ); $re= postSMS($http,$data); //POST方式提交 $re = substr($re, 9, 3); Yii::log("re:" . $re); if($re == '100') { return true; } else { Yii::log("发送失败! 状态:" . $re); return false; } } function GetRandomNum() { $str = '0123456789'; $rndcode = rand(0,9); $rndNum = $str[$rndcode]; return $rndNum; } function SendCaptcha($phone, $shopname) { //先生成一个随机的6位数验证码 $Char1 = GetRandomNum(); $Char2 = GetRandomNum(); $Char3 = GetRandomNum(); $Char4 = GetRandomNum(); $Char5 = GetRandomNum(); $Char6 = GetRandomNum(); $captcha = $Char1 . $Char2 . $Char3 . $Char4 . $Char5 . $Char6; $content = "验证码:" . $captcha . ",请在店铺“" . $shopname . "”微信下单页面填写该验证码。"; Yii::log("content:" . $content); $ret = SendSMSMessage($phone, $content); if ($ret == true) { return $captcha; } return false; } ?>