User-Profile-Image
hankin
  • 5
  • 首页
  • Dedecms
  • Notes
  • php
  • Tools
  • Music
  • 分类
    • Tools
    • php
    • Notes
    • Music
    • Dedecms
  • 页面
  • 友链
      请到[后台->主题设置->友情链接]中设置。
Help?

Please contact us on our email for need any support

Support
  • 首页
  • Dedecms
  • Notes
  • php
  • Tools
  • Music
    首页   ›   Dedecms   ›   正文
Dedecms

Dedecms自定义表单短信通知功能

2014-03-07 19:31:12
4141  0 0

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自定义表单短信通知功能到此就完毕了。

评论 (0)

点击这里取消回复。

欢迎您 游客  

Archives
  • 2019年4月
  • 2018年10月
  • 2018年5月
  • 2018年2月
  • 2016年7月
  • 2015年12月
  • 2014年9月
  • 2014年3月
  • 2014年1月
  • 2013年12月
  • 2013年11月
Categories
  • Dedecms
  • Music
  • Notes
  • php
  • Tools
标签
Dedecms Dedecms短信 Dedecms自定义表单 dedecms自定义表单必填字段 dede_fieldshash showmsg sitemap 织梦 网站地图 自定义表单短信
其他操作
  • 登录
  • 条目feed
  • 评论feed
  • WordPress.org
Copyright © 2025
smarty_hankin 主题. Designed by hankin
主页
页面
博主
Alvin 管理员
14 文章 0 评论 57377 浏览
测试
测试