旧版服务端
This commit is contained in:
1 parent
3429c8b402
commit
25bbb5f9c8
971 files changed
+87141
-40
No files matched your search
Executable
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$openid = $_GET['openid'];
|
||||
$SMSCode = $_GET['code'];
|
||||
$phonenumbers = $_GET['phoneNumber'];
|
||||
$currentDateTime = date('Y-m-d H:i:s');
|
||||
|
||||
// 数据库连接信息
|
||||
$servername = "localhost";
|
||||
$username = "api_yeomai_site";
|
||||
$password = "GAmidytesHHLjGkY";
|
||||
$dbname = "api_yeomai_site";
|
||||
|
||||
// 创建连接
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
// 检查连接是否成功
|
||||
if ($conn->connect_error) {
|
||||
die("连接失败: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// 查询数据库中符合条件的记录
|
||||
$sql = "SELECT * FROM 验证码发送 WHERE 发送人openid='$openid' AND 验证码='$SMSCode' AND 手机号='$phonenumbers' ORDER BY `发送时间` DESC";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
$row = $result->fetch_assoc();
|
||||
$sendTime = strtotime($row['发送时间']);
|
||||
$currentTime = strtotime($currentDateTime);
|
||||
|
||||
if ($currentTime - $sendTime <= 300) { // 5分钟的时间差为300秒
|
||||
echo json_encode(["message" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["message" => "验证码超时"]);
|
||||
}
|
||||
} else {
|
||||
echo json_encode(["message" => "验证码错误"]);
|
||||
}
|
||||
|
||||
// 关闭数据库连接
|
||||
$conn->close();
|
||||
?>
|
||||
Executable
+86
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
namespace AlibabaCloud\SDK\Sample;
|
||||
|
||||
use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
|
||||
use AlibabaCloud\Tea\Utils\Utils;
|
||||
use AlibabaCloud\Tea\Console\Console;
|
||||
use \Exception;
|
||||
use AlibabaCloud\Tea\Exception\TeaError;
|
||||
|
||||
use Darabonba\OpenApi\Models\Config;
|
||||
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
|
||||
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$phonenumbers=$_GET['phonenumbers'];
|
||||
$random_number = $_GET['random_number'];
|
||||
|
||||
class Sample {
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Dysmsapi Client
|
||||
*/
|
||||
public static function createClient(){
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/311677.html。
|
||||
$_ENV['ALIBABA_CLOUD_ACCESS_KEY_ID'] = 'LTAI5t9tjJ28sXfyYF4x4cos';
|
||||
$_ENV['ALIBABA_CLOUD_ACCESS_KEY_SECRET'] = 'CPs7r48N3Ka6aRxDn5y9PB4BwwcLjR';
|
||||
$config = new Config([
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
//"accessKeyId" => $_ENV["ALIBABA_CLOUD_ACCESS_KEY_ID"],
|
||||
"accessKeyId" => 'LTAI5t9tjJ28sXfyYF4x4cos',
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
//"accessKeySecret" => $_ENV["ALIBABA_CLOUD_ACCESS_KEY_SECRET"]
|
||||
"accessKeySecret" => 'CPs7r48N3Ka6aRxDn5y9PB4BwwcLjR'
|
||||
]);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
||||
$config->endpoint = "dysmsapi.aliyuncs.com";
|
||||
return new Dysmsapi($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $phonenumbers
|
||||
* @param int $random_number
|
||||
* @return void
|
||||
*/
|
||||
public static function main($phonenumbers, $random_number){
|
||||
$client = self::createClient();
|
||||
|
||||
$sendSmsRequest = new SendSmsRequest([
|
||||
"phoneNumbers" => $phonenumbers,
|
||||
"signName" => "叶雷讲数学",
|
||||
"templateCode" => "SMS_465440201",
|
||||
"templateParam" => "{\"code\":\"$random_number\"}"
|
||||
]);
|
||||
|
||||
$runtime = new RuntimeOptions([]);
|
||||
try {
|
||||
$resp = $client->sendSmsWithOptions($sendSmsRequest, $runtime);
|
||||
echo json_encode(array(
|
||||
$resp->body,
|
||||
// $resp,
|
||||
// "random_number" => $random_number
|
||||
));
|
||||
} catch (Exception $error) {
|
||||
if (!($error instanceof TeaError)) {
|
||||
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
|
||||
}
|
||||
// 输出错误信息为JSON格式
|
||||
echo json_encode(array(
|
||||
"phoneNumbers" => $phonenumbers,
|
||||
"error" => $error->getMessage(),
|
||||
"recommend" => isset($error->data["Recommend"]) ? $error->data["Recommend"] : null,
|
||||
// "random_number" => $random_number
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
if (file_exists($path)) {
|
||||
require_once $path;
|
||||
}
|
||||
error_reporting(E_ERROR | E_PARSE);
|
||||
Sample::main($phonenumbers, $random_number);
|
||||
?>
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$openid=$_GET['openid'];
|
||||
$phonenumbers=$_GET['phonenumbers'];
|
||||
// $currentDateTime = strtotime(date('Y-m-d H:i:s'));
|
||||
$currentDateTime = date('Y-m-d H:i:s');
|
||||
$random_number = rand(100000, 999999);
|
||||
|
||||
// 定义手机号码正则表达式
|
||||
$pattern = '/^1\d{10}$/';
|
||||
// 使用preg_match函数进行匹配验证
|
||||
if (preg_match($pattern, $phonenumbers)) {
|
||||
// 数据库连接信息
|
||||
$servername = "localhost";
|
||||
$username = "api_yeomai_site";
|
||||
$password = "GAmidytesHHLjGkY";
|
||||
$dbname = "api_yeomai_site";
|
||||
|
||||
// 创建连接
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
// 检查连接是否成功
|
||||
if ($conn->connect_error) {die("连接失败: " . $conn->connect_error);}
|
||||
|
||||
// 查询数据库中符合条件的记录
|
||||
$sql = "SELECT * FROM 用户信息 WHERE OpenID='$openid'";
|
||||
$result = $conn->query($sql);
|
||||
if ($result->num_rows > 0) {
|
||||
$insertdate_sql = "INSERT INTO 验证码发送 (发送人openid, 手机号, 验证码, 发送时间) VALUES ('$openid', '$phonenumbers', '$random_number', '$currentDateTime')";
|
||||
$insertdate_result = $conn->query($insertdate_sql);
|
||||
if ($insertdate_result === TRUE) {
|
||||
//发送短信
|
||||
$url = 'https://api.yeomai.site/SMS/src/send_SMS.php' . '?phonenumbers='. $phonenumbers .'&random_number='. $random_number;
|
||||
$response = file_get_contents($url);
|
||||
echo $response;
|
||||
}
|
||||
}
|
||||
// 关闭数据库连接
|
||||
$conn->close();
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user