4 Star 0 Fork 0

Vikicc / 三三网

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
SendDemo.php 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
Vikicc 提交于 2020-05-25 10:02 . '新建项目';
<?php
/**
* 启瑞云短信接口Demo(utf-8)
*/
class SendDemo
{
const SENDURL = 'http://api.qirui.com:7891/mt';
private $apiKey;
private $apiSecret;
/**
* 构造方法
* @param string $apiKey 接口账号
* @param string $apiSecret 接口密码
*/
public function __construct($apiKey, $apiSecret)
{
$this->apiKey = $apiKey;
$this->apiSecret = $apiSecret;
}
/**
* 短信发送
* @param string $phone 手机号码
* @param string $content 短信内容
* @param integer $isreport 是否需要状态报告
* @return void
*/
public function send($phone, $content, $isreport = 1)
{
$requestData = array(
'un' => $this->apiKey,
'pw' => $this->apiSecret,
'sm' => $content,
'da' => $phone,
'rd' => $isreport,
'dc' => 15,
'rf' => 2,
'tf' => 3,
);
$url = self::SENDURL . '?' . http_build_query($requestData);
return $this->request($url);
}
/**
* 请求发送
* @return string 返回发送状态
*/
private function request($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
//end
// 发送验证码
public function send(){
$phone = input('post.member_phone');
if(!preg_match("/^1[34578]\d{9}$/", $phone)){
return json_fail_return('手机号格式不正确');
}
//接口账号
$apiKey = '2286290010';
//接口密码
$apiSecret='887e45f4adbc87399e88';
$code=mt_rand(999,9999);//生成四位随机数
$session = new Session();
$session->set('code',$code);
//短信内容(【签名】+短信内容),系统提供的测试签名和内容,如需要发送自己的短信内容请在启瑞云平台申请签名和模板
$content = '【山陆久】你好,你的验证码是'.$code.',请在3分钟内验证完毕。';
vendor ('code.SendDemo');
$sms = new \SendDemo($apiKey, $apiSecret);
$result = $sms->send($phone, $content);
$list_code=json_decode($result,true);
if($list_code["success"]=='true'){
return json_success_return('发送成功');
}else{
return json_fail_return('发送失败');
}
}
1
https://gitee.com/1031066280/sansanwang.git
git@gitee.com:1031066280/sansanwang.git
1031066280
sansanwang
三三网
master

搜索帮助