最近公司短信到期了,我看到阿里云里面有个短信验证码服务,价格非常低,每条最高4分半,3秒可到,于是就申请了.
可是后面很难用,找不到例子代码,然后自己摸索,也咨询了阿里云的工作人员,花了2天才搞定,真不容易,记录下来,便于今后自己和其他人查阅.
<?php
session_start();
header("Content-type:text/html; charset=UTF-8");
function https_request($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
if (curl_errno($curl)) {return 'ERROR '.curl_error($curl);}
curl_close($curl);
return $data;
}
function xml_to_array($xml){
$reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
if(preg_match_all($reg, $xml, $matches)){
$count = count($matches[0]);
for($i = 0; $i < $count; $i++){
$subxml= $matches[2][$i];
$key = $matches[1][$i];
if(preg_match( $reg, $subxml