<?php
//命名空间
namespace app\\index\\controller;
use think\\controller;
use app\\index\\module;
class Index extends controller{
public function Sms(){
//接受手机号 访问路由上index,php/phone/13012492778
$phone = post(\'phone\');
$rand = rand(1000,9999);
$url = "http://api.chanyoo.cn/utf8/interface/send_sms.aspx?username=wgnoreognreo&password=cnjdskcnkds&content=验证码:".$rand."【短信提示】&receiver=".$phone; //URL为短信发送的api地址,返回为xml的方式
$file = file_get_contents($url); //跨域访问 访问外部网站get
//转换xml结果
$xml = simplexml_load_string($file);
$date = json_decode(json_encode($xml),TRUE); //如果成功,$date[\'message\']返回“短信提交成功”
//进行对$date
if($date[\'message\'] == "短信提交成功"){
$Sms = Sms::create([ //成功后返回json格式的数据
"phone" => $phone,
"rand" => $rand,
]);
echo "存入成功!".$Sms;
};
}
}
?>