标签:
1、购买服务
我购买的是在百度进行推广的API服务。按照要求进行购买就好,之后获取自己的apikey。
2、将提供的代码修改后集成到项目中:
<?php /** * * * 发送短信 * * * */ class phonemsg{ public $ak = ‘apikey: ****************************‘; public function sendphonemsg($phonenumber, $sendmsg){ $ch = curl_init(); $url = ‘http://apis.baidu.com/kingtto_media/106sms/106sms?mobile=‘.$phonenumber.‘&content=‘.$sendmsg; $header = array($ak); curl_setopt($ch, CURLOPT_HTTPHEADER , $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch , CURLOPT_URL , $url); $res = curl_exec($ch); return $res; } } ?>
<?php /** * * 发送手机验证短息 * * */ session_start(); //生成随机码$rand = substr($randStr,0,6); $randnum = array(); for($i=0;$i<5;$i++){ $randnum[]=rand(0,9); // } $uniqid = implode($randnum); $_SESSION[‘validnum‘] = $uniqid; $validNum = urlencode(‘【即时打印】您的验证码为:‘.$uniqid.‘。如非本人操作,请忽略此条信息‘); require_once "phoneMsg.class.php"; $send = new phonemsg(); //有返回值,可以获取返回信息 $res = $send->sendphonemsg($_POST[‘phoneNumber‘], $validNum); ?>
标签:
原文地址:http://www.cnblogs.com/KTblog/p/5074458.html