remainSmsNum; if ($remainSmsNum <= 0) { Yii::info($merchant['merchantName'] . '短信余额不足'); return false; } $asset->remainSmsNum = --$remainSmsNum; $asset->save(); self::freeSend($mobile, $msg, $merchant); } //自由发短,无ip和数量限制 shish 2019.12.24 public static function freeSend($mobile, $msg, $merchant = null) { $open = WxOpenService::getById(1); $name = isset($open['name']) ? $open['name'] : '花卉宝'; $sms = new chuanglanSMS(self::ACCOUNT, self::PASSWORD); $sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$name}】"; $msg .= $sign; $sms->send($mobile, $msg); } //发短信,有ip和用户数量限制 shish 2020.2.27 public static function send($mobile, $msg, $merchant = null) { $open = WxOpenService::getOpen(); $name = isset($open['name']) ? $open['name'] : '花卉宝'; $sms = new chuanglanSMS(self::ACCOUNT, self::PASSWORD); $sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$name}】"; $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 > self::LIMIT) { util::fail('您今天申请的短信条数达到上限'); } Yii::$app->redis->executeCommand('SETEX', [$statusKey, 60, 'hasSend']); Yii::$app->redis->executeCommand('SETEX', [$todayKey, 86400, ++$num]); $sms->send($mobile, $msg); } }