如何让系统支持使用阿里大鱼短信服务:
第一步,将阿里大鱼官方提供的PHP版SDK下载下来,更改目录名为alidayu,并放入/framework/library/目录中,如图,
屏幕快照 2016-07-14 下午6.22.18
第二步,在/framework/function/global.func.php中,添加如下方法代码:
/**
* 阿里大鱼短信-用户注册验证码
* 模板内容:验证码${code},您正在注册成为${product}用户,感谢您的支持!
* @param string $mobile 接收短信的手机号,11位
* @param string $subject 项目名称
* @return mixed 发送成功则返回数字验证码,发送失败则返回false
* */
function alidayu_sms_reg($mobile, $subject){
if(empty($mobile) || (strlen($mobile) != 11) || empty($subject)){
return false;
}
include IA_ROOT . '/framework/library/alidayu/TopSdk.php';
date_default_timezone_set('Asia/Shanghai');
$client = new ClusterTopClient("23408308","1d12186f9f670a8d215c5501c64f7534");//appkey, secret
$client->format = 'json';
$httpdns = new AlibabaAliqinFcSmsNumSendRequest;
$httpdns->setExtend( "" );
$httpdns->setSmsType( "normal" );
//2.用户注册:
$num_random = mt_rand(1000, 9999);
$httpdns->setSmsFreeSignName( "注册验证" );//短信签名
$httpdns->setSmsTemplateCode( "SMS_12365205" );//短信模板ID
$httpdns->setSmsParam( "{code:'{$num_random}',product:'$subject'}" );//模板参数
$httpdns->setRecNum( "{$mobile}" );//接收短信的手机号
$result = $client->execute($httpdns);
if($result->result->success === true){
return $num_random;
}
return false;
}
/**
* 阿里大鱼短信-身份验证:
* 模板内容:验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!
* @param string $mobile 接收短信的手机号,11位
* @param string $subject 项目名称
* @return mixed 发送成功则返回数字验证码,发送失败则返回false
* */
function alidayu_sms_check($mobile, $subject){
if(empty($mobile) || (strlen($mobile) != 11) || empty($subject)){
return false;
}
include IA_ROOT . '/framework/library/alidayu/TopSdk.php';
date_default_timezone_set('Asia/Shanghai');
$client = new ClusterTopClient("23408308","1d12186f9f670a8d215c5501c64f7534");//appkey, secret
$client->format = 'json';
$httpdns = new AlibabaAliqinFcSmsNumSendRequest;
$httpdns->setExtend( "" );
$httpdns->setSmsType( "normal" );
//3.身份验证:
$num_random = mt_rand(1000, 9999);
$httpdns->setSmsFreeSignName( "身份验证" );//短信签名
$httpdns->setSmsTemplateCode( "SMS_12365209" );//短信模板ID
$httpdns->setSmsParam( "{code:'$num_random',product:'$subject'}" );//模板参数
$httpdns->setRecNum( "{$mobile}" );//接收短信的手机号
$result = $client->execute($httpdns);
if($result->result->success === true){
return $num_random;
}
return false;
}
第三步,在模块中测试:
在模块的site.php中添加如下代码,
public function doWebTest(){
$captcha = alidayu_sms_check('15262519666', '爱笑俱乐部');
if($captch){
echo '验证码:'.$captcha;
}else{
echo '大鱼验证码发送失败';
}
}
SDK下载:alidayu
【参考:】
https://api.alidayu.com/doc2/apiDetail?spm=a3142.8063006.3.1.lksy2e&apiId=25450
如何让系统支持使用阿里大鱼短信服务:
第一步,将阿里大鱼官方提供的PHP版SDK下载下来,更改目录名为alidayu,并放入/framework/library/目录中,如图,
屏幕快照 2016-07-14 下午6.22.18
第二步,在/framework/function/global.func.php中,添加如下方法代码:
/**
* 阿里大鱼短信-用户注册验证码
* 模板内容:验证码${code},您正在注册成为${product}用户,感谢您的支持!
* @param string $mobile 接收短信的手机号,11位
* @param string $subject 项目名称
* @return mixed 发送成功则返回数字验证码,发送失败则返回false
* */
function alidayu_sms_reg($mobile, $subject){
if(empty($mobile) || (strlen($mobile) != 11) || empty($subject)){
return false;
}
include IA_ROOT . '/framework/library/alidayu/TopSdk.php';
date_default_timezone_set('Asia/Shanghai');
$client = new ClusterTopClient("23408308","1d12186f9f670a8d215c5501c64f7534");//appkey, secret
$client->format = 'json';
$httpdns = new AlibabaAliqinFcSmsNumSendRequest;
$httpdns->setExtend( "" );
$httpdns->setSmsType( "normal" );
//2.用户注册:
$num_random = mt_rand(1000, 9999);
$httpdns->setSmsFreeSignName( "注册验证" );//短信签名
$httpdns->setSmsTemplateCode( "SMS_12365205" );//短信模板ID
$httpdns->setSmsParam( "{code:'{$num_random}',product:'$subject'}" );//模板参数
$httpdns->setRecNum( "{$mobile}" );//接收短信的手机号
$result = $client->execute($httpdns);
if($result->result->success === true){
return $num_random;
}
return false;
}
/**
* 阿里大鱼短信-身份验证:
* 模板内容:验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!
* @param string $mobile 接收短信的手机号,11位
* @param string $subject 项目名称
* @return mixed 发送成功则返回数字验证码,发送失败则返回false
* */
function alidayu_sms_check($mobile, $subject){
if(empty($mobile) || (strlen($mobile) != 11) || empty($subject)){
return false;
}
include IA_ROOT . '/framework/library/alidayu/TopSdk.php';
date_default_timezone_set('Asia/Shanghai');
$client = new ClusterTopClient("23408308","1d12186f9f670a8d215c5501c64f7534");//appkey, secret
$client->format = 'json';
$httpdns = new AlibabaAliqinFcSmsNumSendRequest;
$httpdns->setExtend( "" );
$httpdns->setSmsType( "normal" );
//3.身份验证:
$num_random = mt_rand(1000, 9999);
$httpdns->setSmsFreeSignName( "身份验证" );//短信签名
$httpdns->setSmsTemplateCode( "SMS_12365209" );//短信模板ID
$httpdns->setSmsParam( "{code:'$num_random',product:'$subject'}" );//模板参数
$httpdns->setRecNum( "{$mobile}" );//接收短信的手机号
$result = $client->execute($httpdns);
if($result->result->success === true){
return $num_random;
}
return false;
}
第三步,在模块中测试:
在模块的site.php中添加如下代码,
public function doWebTest(){
$captcha = alidayu_sms_check('15262519666', '爱笑俱乐部');
if($captch){
echo '验证码:'.$captcha;
}else{
echo '大鱼验证码发送失败';
}
}
SDK下载:alidayu
【参考:】
https://api.alidayu.com/doc2/apiDetail?spm=a3142.8063006.3.1.lksy2e&apiId=25450