| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace common\components;
- use biz\weixin\services\WxOpenService;
- /**
- * 短信接口
- */
- class sms
- {
-
- //发短信
- public static function send($mobile, $msg, $merchant = null)
- {
- $open = WxOpenService::getById(1);
- $openName = $open['openName'];
- $sms = new chuanglanSMS('N2890342', 'abc178c7');
- $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)) {
- util::fail('请60秒后再操作');
- }
-
- $todayKey = 'SMS_NUM_' . date("Ymd") . '_' . $uniqueId . '_' . $ip;
- $num = Yii::$app->redis->executeCommand('GET', [$todayKey]);
- $num = is_numeric($num) ? $num : 0;
- if ($num > 10) {
- util::fail('您今天申请的短信条数达到上限');
- }
- Yii::$app->redis->executeCommand('SETEX', [$statusKey, 60, 'hasSend']);
- Yii::$app->redis->executeCommand('SETEX', [$todayKey, 86400, ++$num]);
- $sms->send($mobile, $msg);
- }
- }
|