|
@ -643,7 +643,7 @@ class AdminService extends AdminBaseService |
|
|
public function sendEmailOrSms($param) |
|
|
public function sendEmailOrSms($param) |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
if (empty($param['user_id'])) { |
|
|
if (empty($param['user_id']) || empty($param['type']) || empty($param['content'])) { |
|
|
return $this->toData('400', '参数错误'); |
|
|
return $this->toData('400', '参数错误'); |
|
|
} |
|
|
} |
|
|
if (!in_array($param['type'], [1,2])) { |
|
|
if (!in_array($param['type'], [1,2])) { |
|
@ -657,17 +657,17 @@ class AdminService extends AdminBaseService |
|
|
|
|
|
|
|
|
// 发送邮件 |
|
|
// 发送邮件 |
|
|
if ($param['type'] == 1) { |
|
|
if ($param['type'] == 1) { |
|
|
|
|
|
if (empty($param['title'])) { |
|
|
|
|
|
return $this->toData('400', '参数错误'); |
|
|
|
|
|
} |
|
|
if (empty($user->email)) { |
|
|
if (empty($user->email)) { |
|
|
return $this->toData('500', '用户邮箱为空'); |
|
|
return $this->toData('500', '用户邮箱为空'); |
|
|
} |
|
|
} |
|
|
$emailTemplate = EmailTemplateModel::where('tpl_type', EmailTemplateModel::TPL_TYPE_ONE)->find(); |
|
|
|
|
|
if (empty($emailTemplate)) { |
|
|
|
|
|
return json(['code'=>500, 'message'=>'邮件模板为空']); |
|
|
|
|
|
} |
|
|
|
|
|
$emailTemplate = $emailTemplate->toArray(); |
|
|
|
|
|
$emailTemplate['email'] = $user->email; |
|
|
$emailTemplate['email'] = $user->email; |
|
|
|
|
|
$title = trim($param['title']); |
|
|
|
|
|
$content = trim($param['content']); |
|
|
$phpEmail = new \app\utility\SendEmail(); |
|
|
$phpEmail = new \app\utility\SendEmail(); |
|
|
$bool = $phpEmail->sendEmail($emailTemplate['email'], $emailTemplate['title'], $emailTemplate['content']); |
|
|
$bool = $phpEmail->sendEmail($emailTemplate['email'], $title, $content); |
|
|
if (!$bool) { |
|
|
if (!$bool) { |
|
|
return $this->toData('500', '邮件发送失败'); |
|
|
return $this->toData('500', '邮件发送失败'); |
|
|
} |
|
|
} |
|
@ -678,18 +678,16 @@ class AdminService extends AdminBaseService |
|
|
if (empty($user->phone_number)) { |
|
|
if (empty($user->phone_number)) { |
|
|
return $this->toData('500', '用户手机号为空'); |
|
|
return $this->toData('500', '用户手机号为空'); |
|
|
} |
|
|
} |
|
|
|
|
|
Log::info("目标手机号:". $user->phone_number); |
|
|
$accessKey = env('SMS.ACCESS_KEY_ID'); |
|
|
$accessKey = env('SMS.ACCESS_KEY_ID'); |
|
|
$secret = env('SMS.ACCESS_KEY_SECRET'); |
|
|
$secret = env('SMS.ACCESS_KEY_SECRET'); |
|
|
if (empty($accessKey) || empty($secret)) { |
|
|
if (empty($accessKey) || empty($secret)) { |
|
|
return $this->toData('500', '短信账号配置错误'); |
|
|
return $this->toData('500', '短信账号配置错误'); |
|
|
} |
|
|
} |
|
|
$smsTemplate = SmsTemplateModel::where(['tpl_type'=> SmsTemplateModel::TPL_TYPE_ONE])->find(); |
|
|
|
|
|
if (empty($smsTemplate)) { |
|
|
|
|
|
return json(['code'=>500, 'message'=>'短信模板为空']); |
|
|
|
|
|
} |
|
|
|
|
|
$to = $user->phone_number; |
|
|
$to = $user->phone_number; |
|
|
$content = $smsTemplate->content; |
|
|
$content = trim($param['content']); |
|
|
$bool = (new \app\utility\SendSms())->sendMessageWithTemplate($to, $content, $accessKey, $secret); |
|
|
$from = 'Bourse'; |
|
|
|
|
|
$bool = (new \app\utility\SendSms())->sendMessageToGlobe($to, $content, $from, $accessKey, $secret); |
|
|
if (!$bool) { |
|
|
if (!$bool) { |
|
|
return $this->toData('500', '短信发送失败'); |
|
|
return $this->toData('500', '短信发送失败'); |
|
|
} |
|
|
} |
|
|