|
|
@@ -11,6 +11,12 @@ use Yii;
|
|
|
*/
|
|
|
class sms
|
|
|
{
|
|
|
+ //短信服务帐号
|
|
|
+ const ACCOUNT = 'N2890342';
|
|
|
+ //短信服务密码
|
|
|
+ const PASSWORD = 'abc178c7';
|
|
|
+ //一个用户一天同个IP申请的短信条数
|
|
|
+ const LIMIT = 10;
|
|
|
|
|
|
//商家发短信 shish 2019.12.24
|
|
|
public static function merchantSend($mobile, $msg, $merchant)
|
|
|
@@ -27,30 +33,30 @@ class sms
|
|
|
self::freeSend($mobile, $msg, $merchant);
|
|
|
}
|
|
|
|
|
|
- //自由发送无限制 shish 2019.12.24
|
|
|
+ //自由发短,无ip和数量限制 shish 2019.12.24
|
|
|
public static function freeSend($mobile, $msg, $merchant = null)
|
|
|
{
|
|
|
$open = WxOpenService::getById(1);
|
|
|
$openName = $open['openName'];
|
|
|
- $sms = new chuanglanSMS('N2890342', 'abc178c7');
|
|
|
+ $sms = new chuanglanSMS(self::ACCOUNT, self::PASSWORD);
|
|
|
$sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$openName}】";
|
|
|
$msg .= $sign;
|
|
|
$sms->send($mobile, $msg);
|
|
|
}
|
|
|
-
|
|
|
- //发短信
|
|
|
+
|
|
|
+ //发短信,有ip和用户数量限制 shish 2020.2.27
|
|
|
public static function send($mobile, $msg, $merchant = null)
|
|
|
{
|
|
|
$open = WxOpenService::getById(1);
|
|
|
$openName = $open['openName'];
|
|
|
- $sms = new chuanglanSMS('N2890342', 'abc178c7');
|
|
|
+ $sms = new chuanglanSMS(self::ACCOUNT, self::PASSWORD);
|
|
|
$sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$openName}】";
|
|
|
$msg .= $sign;
|
|
|
-
|
|
|
+
|
|
|
//验证是否有权限发短信
|
|
|
$uniqueId = isset($merchant['id']) ? $merchant['id'] : 1;
|
|
|
$ip = httpUtil::ip();
|
|
|
-
|
|
|
+
|
|
|
$statusKey = 'SMS_STATUS_' . $uniqueId . '_' . $ip;
|
|
|
$hasSend = Yii::$app->redis->executeCommand('GET', [$statusKey]);
|
|
|
if (!empty($hasSend)) {
|
|
|
@@ -60,10 +66,10 @@ class sms
|
|
|
$todayKey = 'SMS_NUM_' . date("Ymd") . '_' . $uniqueId . '_' . $ip;
|
|
|
$num = Yii::$app->redis->executeCommand('GET', [$todayKey]);
|
|
|
$num = is_numeric($num) ? $num : 0;
|
|
|
- if ($num > 10) {
|
|
|
+ if ($num > self::LIMIT) {
|
|
|
util::fail('您今天申请的短信条数达到上限');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Yii::$app->redis->executeCommand('SETEX', [$statusKey, 60, 'hasSend']);
|
|
|
Yii::$app->redis->executeCommand('SETEX', [$todayKey, 86400, ++$num]);
|
|
|
$sms->send($mobile, $msg);
|