|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of ibrand/laravel-sms. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) iBrand <https://www.ibrand.cc> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace iBrand\Sms; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Routing\Controller; |
|
15
|
|
|
use iBrand\Sms\Facade as Sms; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class SmsController |
|
19
|
|
|
* @package iBrand\Sms |
|
20
|
|
|
*/ |
|
21
|
|
|
class SmsController extends Controller |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function postSendCode() |
|
27
|
|
|
{ |
|
28
|
2 |
|
$mobile = request('mobile'); |
|
29
|
|
|
|
|
30
|
2 |
|
if(!config('app.debug') && !Sms::verifyMobile($mobile)){ |
|
31
|
2 |
|
return response()->json(['success' => false, 'message' => '无效手机号码']); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
2 |
View Code Duplication |
if (!Sms::canSend($mobile)) { |
|
|
|
|
|
|
35
|
2 |
|
return response()->json(['success' => false, 'message' => '每60秒发送一次']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
2 |
View Code Duplication |
if (!Sms::send($mobile)) { |
|
|
|
|
|
|
39
|
|
|
return response()->json(['success' => false, 'message' => '短信发送失败']); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
return response()->json(['success' => true, 'message' => '短信发送成功']); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* laravel sms code info. |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function info() |
|
49
|
|
|
{ |
|
50
|
2 |
|
$html = '<meta charset="UTF-8"/><h2 align="center" style="margin-top: 30px;margin-bottom: 0;">iBrand Laravel Sms</h2>'; |
|
51
|
2 |
|
$html .= '<p style="margin-bottom: 30px;font-size: 13px;color: #888;" align="center">' . 1.0 . '</p>'; |
|
52
|
2 |
|
$html .= '<p><a href="https://github.com/ibrandcc/laravel-sms" target="_blank">ibrand laravel-sms源码</a>托管在GitHub,欢迎你的使用。如有问题和建议,欢迎提供issue。</p>'; |
|
53
|
2 |
|
$html .= '<hr>'; |
|
54
|
2 |
|
$html .= '<p>你可以在调试模式(设置config/app.php中的debug为true)下查看到存储在存储器中的验证码短信/语音相关数据:</p>'; |
|
55
|
2 |
|
echo $html; |
|
56
|
2 |
|
if (config('app.debug')) { |
|
57
|
|
|
|
|
58
|
1 |
|
$key = md5('ibrand.sms.' . request('mobile')); |
|
59
|
|
|
|
|
60
|
1 |
|
dump(Sms::getStorage()->get($key, '')); |
|
61
|
|
|
} else { |
|
62
|
1 |
|
echo '<p align="center" style="color: red;">现在是非调试模式,无法查看调试数据</p>'; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: