1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
<?php /*-------------------------------- 功能:HTTP接口 发送短信 修改日期: 2014-03-07 说明: http://xxx.xxxxxxx.xxx/Send.php?CorpID=*&Pwd=*&Mobile=*&Content=*&Cell=*&SendTime=* 状态: 0 发送成功 –1 账号未注册 –2 其他错误 –3 密码错误 –4 手机号格式不对 –5 余额不足 –6 定时发送时间不是有效的时间格式 –7 禁止10小时以内向同一手机号发送相同短信 *请自行查看你的服务商的接口文档的错误码 http://xxx.xxxxxxx.xxx/Send.php?CorpID=*&Pwd=*&Mobile=*&Content=*&Cell=*&SendTime=* --------------------------------*/ //定时发送 /* 固定14位长度字符串,比如:20140307152435代表2014年03月07日15时24分35秒,为空表示立即发送 $smstime = '20140307152435'; $res = sendSMS($smsuid,$smspwd,$smsmobile,$smscontent,$smstime); echo $res; */ header("Content-type: text/html; charset=utf-8"); function sendSMS($smsuid,$smspwd,$smsmobile,$smscontent,$smstime='',$smsmid='') { $smshttp = 'ttp://xxx.xxxxxxx.xxx/Send.php'; $smsdata = array ( 'CorpID'=>$smsuid, //用户账号 'pwd'=>$smspwd, //密码 'Mobile'=>$smsmobile, //号码 'Content'=>iconv('utf-8','gbk',$smscontent), //内容 如果对方是utf-8编码,则需转码iconv('gbk','utf-8',$smscontent); 如果是gbk则无需转码 'SendTime'=>$smstime, //定时发送 'Cell'=>$smsmid //子扩展号 ); $re= postSMS($smshttp,$smsdata); //POST方式提交 if( trim($re) == '0' ) { return " "; } else { return $re; } } function postSMS($url,$smsdata='') { $row = parse_url($url); $host = $row['host']; $port = $row['port'] ? $row['port']:80; $file = $row['path']; while (list($k,$v) = each($smsdata)) { $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); } } $smsuid = ''; //用户账号 $smspwd = ''; //密码 ?> |
以上保存为sendsms.php放在比如/plus/目录下。注意编码问题,我的编码都是utf-8,所以上面'Content'=>iconv('utf-8','gbk',$smscontent)如果你文件编码本来就是gbk用'Content'=$smscontent,不然短信会乱码。
下面是自定义表单引用方法:
找到:
1 |
$query = "INSERT INTO `{$diy->table}` (`id`, `ifcheck` $addvar) VALUES (NULL, 0 $addvalue); "; |
在这句附近看着修改吧。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
require_once("sendsms.php"); $smsmobile = $tel; //号码 $tel 是你的自定义字段 $smscontent = "恭喜您!预约成功XXX……这里是短信内容。"; //内容 $res = sendSMS($smsuid,$smspwd,$smsmobile,$smscontent); $query = "INSERT INTO `{$diy->table}` (`id`, `ifcheck` $addvar) VALUES (NULL, 0 $addvalue); "; if($dsql->ExecuteNoneQuery($query)) { $id = $dsql->GetLastID(); if($diy->public == 2) { $goto = "diy.php?action=view&diyid={$diy->diyid}&id=$id"; $bkmsg = '发布成功,现在转向表单列表页...'; } else { $goto = "diy.php?action=post&diyid=$diyid"; $bkmsg = '恭喜您!预约成功XXX,我们已经登记,稍后您会收到短信通知。'; } echo "<script language=javascript>alert('恭喜您!预约成功XXX,我们已经登记,稍后您会收到短信通知。{$res}');window.location = 'diy.php?action=post&diyid=$diyid';</script>"; |
Dedecms自定义表单短信通知功能到此就完毕了。