使用的短信商是:容联云通讯 网址:http://www.yuntongxun.com/
代码均亲测,可以直接使用。
1.制作步骤:
打开 /e/template/member/register.php进行修改
先把用户名,三个汉字,改成手机号
在邮箱的表单下面,多增加一个验证码的表单
*
function get_code(){ var phe=document.userinfoform.username.value; if(document.userinfoform.username.value == "") { alert("手机号不能为空"); document.userinfoform.username.focus(); return false; } $.ajax({ type: "POST", url: "/e/extend/phone/index.php", dataType: 'html', data:{ phe:phe, }, success:function(data,status){ alert("发送成功"); return false; }, error:function(){ alert("发送验证码不成功,请重试"); return false; } }) }
2.将手机短信验证代码放入e/extend/文件下
将SDK文件代码需要做部分修改:
/*
* Copyright (c) 2014 The CCP project authors. All Rights Reserved.
*
* Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
* that can be found in the LICENSE file in the root of the web site.
*
* http://www.yuntongxun.com
*
* An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
accountSid=”【云通讯–应用管理中–ACCOUNTSID:xxx的值】
a
c
c
o
u
n
t
S
i
d
=
”
【
云
通
讯
–
应
用
管
理
中
–
A
C
C
O
U
N
T
S
I
D
:
x
x
x
的
值
】
accountToken = ”【云通讯–应用管理中–AUTH TOKEN:xx的值】
appId=”【云通讯–应用管理中–AppID(默认):xx的值】【下面三个参数不变】
a
p
p
I
d
=
”
【
云
通
讯
–
应
用
管
理
中
–
A
p
p
I
D
(
默
认
)
:
x
x
的
值
】
【
下
面
三
个
参
数
不
变
】
serverIP=’app.cloopen.com’;
serverPort=′8883′;
s
e
r
v
e
r
P
o
r
t
=
′
8883
′
;
softVersion=’2013-12-26’;
class REST {
private
AccountSid;private
A
c
c
o
u
n
t
S
i
d
;
p
r
i
v
a
t
e
AccountToken;
private
AppId;private
A
p
p
I
d
;
p
r
i
v
a
t
e
ServerIP;
private
ServerPort;private
S
e
r
v
e
r
P
o
r
t
;
p
r
i
v
a
t
e
SoftVersion;
private
Batch;//时间戳private
B
a
t
c
h
;
/
/
时
间
戳
p
r
i
v
a
t
e
BodyType = “xml”;//包体格式,可填值:json 、xml
private
enabeLog=true;//日志开关。可填值:true、private
e
n
a
b
e
L
o
g
=
t
r
u
e
;
/
/
日
志
开
关
。
可
填
值
:
t
r
u
e
、
p
r
i
v
a
t
e
Filename=”./log.txt”; //日志文件
private Handle;
function __construct(
Handle; function __construct(
ServerIP,
ServerPort,
S
e
r
v
e
r
P
o
r
t
,
SoftVersion)
{
this−>Batch=date(“YmdHis”);
t
h
i
s
−
>
B
a
t
c
h
=
d
a
t
e
(
“
Y
m
d
H
i
s
”
)
;
this->ServerIP =
ServerIP;
S
e
r
v
e
r
I
P
;
this->ServerPort =
ServerPort;
S
e
r
v
e
r
P
o
r
t
;
this->SoftVersion =
SoftVersion;
S
o
f
t
V
e
r
s
i
o
n
;
this->Handle = fopen($this->Filename, ‘a’);
}
/**
* 设置主帐号
*
* @param AccountSid 主帐号
* @param AccountToken 主帐号Token
*/
function setAccount(
AccountSid,
A
c
c
o
u
n
t
S
i
d
,
AccountToken){
this−>AccountSid=
t
h
i
s
−
>
A
c
c
o
u
n
t
S
i
d
=
AccountSid;
this−>AccountToken=
t
h
i
s
−
>
A
c
c
o
u
n
t
T
o
k
e
n
=
AccountToken;
}
/**
* 设置应用ID
*
* @param AppId 应用ID
*/
function setAppId(AppId){
AppId){
this->AppId = $AppId;
}
/**
* 打印日志
*
* @param log 日志内容
*/
function showlog(log){
if(
log){ if(
this->enabeLog){
fwrite(
this−>Handle,
t
h
i
s
−
>
H
a
n
d
l
e
,
log.”\n”);
}
}
/**
* 发起HTTPS请求
*/
function curl_post($url,$data,$header,$post=1)
{
//初始化curl
$ch = curl_init();
//参数设置
$res= curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, $post);
if($post)
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
$result = curl_exec ($ch);
//连接失败
if($result == FALSE){
if($this->BodyType=='json'){
$result = "{\"statusCode\":\"172001\",\"statusMsg\":\"网络错误\"}";
} else {
$result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Response><statusCode>172001</statusCode><statusMsg>网络错误</statusMsg></Response>";
}
}
curl_close($ch);
return $result;
}
/**
* 发送模板短信
* @param to 短信接收彿手机号码集合,用英文逗号分开
* @param datas 内容数据
* @param
tempId模板Id∗/functionsendTemplateSMS(
t
e
m
p
I
d
模
板
I
d
∗
/
f
u
n
c
t
i
o
n
s
e
n
d
T
e
m
p
l
a
t
e
S
M
S
(
to,
datas,
d
a
t
a
s
,
tempId)
{
//主帐号鉴权信息验证,对必选参数进行判空。
auth=
a
u
t
h
=
this->accAuth();
if(
auth!=”“)return$auth;//拼接请求包体if(
a
u
t
h
!
=
”
“
)
r
e
t
u
r
n
$
a
u
t
h
;
/
/
拼
接
请
求
包
体
i
f
(
this->BodyType==”json”){
data=”“;for(
d
a
t
a
=
”
“
;
f
o
r
(
i=0;$i