PHP高级实例 | 使用云片短信接口发送网站验证码云片官网:https://www.yunpian.com/ 默认是有10条免费短信的 html var sends = { send:function(){ var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0,6,7,8]{1})|(18[0-9]{1}))+\d{8})$/; var n作者王明昌发布时间2018-07-17最后更新2018-07-17 云片官网:https://www.yunpian.com/ 默认是有10条免费短信的 html 复制 PHP方法 复制public function userverify() { $str = "0123456789"; // 输出字符集 $n = 6; // 输出串长度 $len = strlen($str)-1; $verify=''; for($i=0 ; $i<$n; $i++){ $verify.= $str[rand(0,$len)]; } $item= $_POST['item']; $msg = Check::rule(array( array(check::mobile($item) && check::must($item), '请填写正确的手机号码!'), )); if ($msg !== true) { $this->jserror($msg); } $type = $_GET['type']; if($item){ if(!empty($type)){ if (!empty($_SESSION['message_verify'.$item.$type])) { $this->jserror('已经发送至您手机,请稍候再试'); } }else{ if (!empty($_SESSION['message_verify'.$item])) { $this->jserror('已经发送至您手机,请稍候再试'); } } if(!empty($type)){ $_SESSION['message_verify'.$item.$type] = $verify; }else { $_SESSION['message_verify'.$item] = $verify; } $_SESSION['verify']=$verify; $sms = new sendsms(); $apikey = "b12a3c784ccc0000002bb02bc6481d7"; //请用自己的apikey代替 $mobile = $item; //请用自己的手机号代替 $text="【王明昌博客】您的验证码是".$verify."。如非本人操作,请忽略本短信"; $successsmg = $sms->send_sms($apikey,$text,$mobile); /* 这里的$text要和$apikey 申请的保持一致,短信是发不出去的*/ if($successsmg){ $this->jssuccess('已经发送至您手机'); } }else { $this->jserror('获取验证码失败!'); } } sendsms.class.php 复制sock_post($url, $post_string); } /** * 模板接口发短信 * apikey 为云片分配的apikey * tpl_id 为模板id * tpl_value 为模板值 * mobile 为接受短信的手机号 */ function tpl_send_sms($apikey, $tpl_id, $tpl_value, $mobile){ $url="http://yunpian.com/v1/sms/tpl_send.json"; $encoded_tpl_value = urlencode("$tpl_value"); //tpl_value需整体转义 $post_string="apikey=$apikey&tpl_id=$tpl_id&tpl_value=$encoded_tpl_value&mobile=$mobile"; return $this->sock_post($url, $post_string); } /** * url 为服务的url地址 * query 为请求串 */ function sock_post($url,$query){ $data = ""; $info=parse_url($url); $fp=fsockopen($info["host"],80,$errno,$errstr,30); if(!$fp){ return $data; } $head="POST ".$info['path']." HTTP/1.0\r\n"; $head.="Host: ".$info['host']."\r\n"; $head.="Referer: http://".$info['host'].$info['path']."\r\n"; $head.="Content-type: application/x-www-form-urlencoded\r\n"; $head.="Content-Length: ".strlen(trim($query))."\r\n"; $head.="\r\n"; $head.=trim($query); $write=fputs($fp,$head); $header = ""; while ($str = trim(fgets($fp,4096))) { $header.=$str; } while (!feof($fp)) { $data .= fgets($fp,4096); } return $data; } } ?>
2018-08-22支付宝支付接口错误说明错误查询 https://docs.open.alipay.com/58/103599/ 今天我遇到的一个错误,经过询问小二,网关错误,错误如下 ILLEGAL_ACCESS_SWITCH_SYSTE
2019-12-10阿里巴巴开源镜像提供的 packagist 镜像服务全局配置(推荐) 所有项目都会使用该镜像地址: composer config -g repo.packagist composer https://mirrors.aliyun.com/compos
2018-08-26实例 | 支付宝支付(使用md5加密)参数的获取 pid|key获取: 商户中心---账户管理---查看pid|key https://openhome.alipay.com/platform/keyManage.htm?keyType=
2018-10-31实例 | tp5使用七牛云上传图片和文件/删除文件thinkphp5中使用七牛云 下载 https://github.com/qiniu/php-sdk vendor文件下 新建文件 application/extra/qiniu.php retur
2018-05-28ajax-post传值的写法var data = {type:type,is_ok:is_ok,id:id}; $("#train").on("click",function(){ var id = $("#id_res").v
2018-05-27Ajax异步搜索内容,并显示使用ajax异步搜索内容,如果符合内容,则一行行的显示,每次查询时清空上次的记录 $("#search").on("click",function(){ var key = $("#keywords"