remainSmsNum; if ($remainSmsNum <= 0) { Yii::info('商家id:' . $sjId . ' -- ' . $merchant['name'] . '短信余额不足'); return false; } $asset->remainSmsNum = --$remainSmsNum; $asset->save(); self::freeSend($params, $msg, $merchant); return true; } //自由发短,无ip和数量限制 ssh 2019.12.24 public static function freeSend($params, $msg, $merchant = null, $extend = '') { $ptStyle = dict::getDict('ptStyle', 'hd'); if (isset(Yii::$app->params['ptStyle'])) { $ptStyle = Yii::$app->params['ptStyle']; } $open = WxOpenService::getById($ptStyle); $name = isset($open['name']) ? $open['name'] : '花卉宝'; $sign = isset($merchant) == true ? "【{$merchant['name']}】" : "【{$name}】"; $msg = $sign . $msg; $sms = new ChuanglanSmsApi(); $result = $sms->sendVariableSMS($msg, $params, $extend); if (!is_null(json_decode($result))) { $output = json_decode($result, true); if (isset($output['code']) && $output['code'] == '0') { Yii::info("短信发送成功,参数:{$params} 返回:" . $result); return true; } else { Yii::info("短信发送失败,参数:{$params} 返回:" . $result); return false; } } else { Yii::info("短信发送失败,参数:{$params} 返回:" . $result); return false; } } //发短信,有ip和用户数量限制 ssh 2020.2.27 public static function send($params, $msg, $merchant = null) { $ptStyle = Yii::$app->params['ptStyle']; $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => $ptStyle]); if (empty($open)) { util::fail('没有找到平台'); } //$name = isset($open['name']) ? $open['name'] : '花卉宝'; $name = '厦门中花汇'; $sign = isset($merchant) == true ? "【{$merchant['name']}】" : "【{$name}】"; $msg = $sign . $msg; //验证是否有权限发短信 $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 = new ChuanglanSmsApi(); $sms->sendVariableSMS($msg, $params); } }