laravel操作给手机发送短信
来源:互联网 发布:在淘宝开店快递怎么弄 编辑:程序博客网 时间:2024/05/22 20:21
1.进入视图
<div class="register-main" id="redeemPrizes">
<ul class="register">
<li>
<label>手机号:</label>
<input class="ipt-box tel-bg" value="" id="regi_mobile" type="text">
</li>
<li>
<label>验证码:</label>
<input class="code" value="六位数字验证码" id="validatecode" type="text">
<input class="code" onclick='duanxin()' value="获取验证码" type="button">
</li>
</ul>
<span id="xin_top_userinfo" sname="http://www.xin.com"><div class="person-wrap" style="top:0px;"><a href="javascript:clear_invalid();show_popup('#popupLogin','#popupLogin%20.closeJs');" id="loginA" class="login">登录</a>/<a href="#" id="regA" rel="nofollow" class="register" >注册</a></div></span>
<div class="btn-div">
</div>
<script src="http://www.haoyunyun.cn/jquery.js"></script>
<script>
function duanxin(){
//获取手机ID
var iphone=$("#regi_mobile").val();
$.ajax({
url:'registers',
data:{'iphone':iphone},
type:"GET",
dataType:"Json",
success:function(msg){
if(msg['stat']=='100'){
alert('短信发送成功了');
}else{
alert('短信发送失败了');
}
}
});
}
</script>
2.填写相应的路由
Route::any('registers','LoginController@login_do');
3.写出相应的控制器
public function login_do(){
$iphone=$_GET['iphone'];
$code=rand(1000,9999);
setcookie('code',$code,time()+600);
//echo $url
$url='http://api.sms.cn/sms/?=send&uid=*********&pwd=**********&template=384859&mobile='.$iphone.'&content={"code":"'.$code.'"}';
$data=array();
$method='GET';
$res=$this->curlPost($url,$data,$method);
echo $res;
}
/*curlpost传值*/
public function curlPost($url,$data,$method){
$ch = curl_init(); //1.初始化
curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);//3.请求方式
//4.参数如下
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');//模拟浏览器
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Encoding: gzip, deflate'));//gzip解压内容
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
if($method=="POST"){//5.post方式的时候添加数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);//6.执行
if (curl_errno($ch)) {//7.如果出错
return curl_error($ch);
}
curl_close($ch);//8.关闭
return $tmpInfo;
}
4.完毕!
0 0
- laravel操作给手机发送短信
- laravel操作给手机发送短信
- laravel操作给手机发送短信
- 一个给手机发送短信的例子
- java给手机发送短信(转)
- 基于SMS短信平台给手机发送短信
- 给客户发送短信
- 手机发送短信方式
- Android 手机发送短信
- laravel中实现短信发送验证码
- Android ---模拟手机发送短信
- Android手机自动发送短信
- laravel框架手机发送验证码
- laravel框架手机发送验证码
- 手机安全卫士------手机防盗页面之发送短信&接收短信
- 给手机发送验证码
- Chawt.com 免费给全球发送短信
- 用C#通过Nokia手机发送短信
- 【Codeforces】-703A-Mishka and Game(水)
- linux安装redis
- UNITY 5.4.0发行说明中文版(不包含bug修正部分)
- 青海湖旅行总结
- java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie
- laravel操作给手机发送短信
- 消息栏通知(Notification)介绍
- Android阶段学习笔记 16.8.6 之 SharedPreferences存数据
- Linux环境常用命令
- mac创建IPv6
- c++ vector用法详解
- js 判断checkbox选中
- 数据结构实验之栈八:栈的基本操作
- thinkphp 完整配置config.php