From 153e0235bdac5c3b93685e6b4be6cee203f60f95 Mon Sep 17 00:00:00 2001 From: weigang Date: Wed, 26 Aug 2020 21:10:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=9C=8D=E5=8A=A1=E7=82=B9?= =?UTF-8?q?=E5=88=86=E8=B4=A6=E7=9F=AD=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/AdminUser.php | 29 +++++++++++ app/Model/CsInfo.php | 29 +++++++++++ app/Service/FinancialRecordService.php | 17 ++++++- app/Service/SmsAliService.php | 68 ++++++++++++++++++++++++++ app/Service/SmsServiceInterface.php | 9 ++++ composer.json | 3 +- config/autoload/dependencies.php | 1 + config/config.php | 7 +++ 8 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 app/Model/AdminUser.php create mode 100644 app/Model/CsInfo.php create mode 100644 app/Service/SmsAliService.php create mode 100644 app/Service/SmsServiceInterface.php diff --git a/app/Model/AdminUser.php b/app/Model/AdminUser.php new file mode 100644 index 0000000..d2ed2b6 --- /dev/null +++ b/app/Model/AdminUser.php @@ -0,0 +1,29 @@ +balance = bcadd($balance->balance, $money, 2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); + } /** @@ -101,6 +110,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface ]); $balance->balance = bcadd($balance->balance, $money, 2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); } /** @@ -125,6 +137,9 @@ class FinancialRecordService implements FinancialRecordServiceInterface ]); $balance->balance = bcadd($balance->balance, $money,2); $balance->save(); + + // 发送短信 + $this->smsAliService->sendForCommunityFinancial($user_id, $money); } diff --git a/app/Service/SmsAliService.php b/app/Service/SmsAliService.php new file mode 100644 index 0000000..9c709f6 --- /dev/null +++ b/app/Service/SmsAliService.php @@ -0,0 +1,68 @@ +regionId($alisms['regionid']) + ->asDefaultClient(); + + try { + $result = AlibabaCloud::rpc() + ->product($alisms['product']) + // ->scheme('https') // https | http + ->version('2017-05-25') + ->action('SendSms') + ->method('POST') + ->host($alisms['host']) + ->options([ + 'query' => [ + 'RegionId' => $alisms['regionid'], + 'PhoneNumbers' => $phone, + 'SignName' => $signName, + 'TemplateCode' => $template, + 'TemplateParam' => $templateParams, + ], + ]) + ->request(); + return $result->toArray(); + } catch (ClientException $e) { + $this->log->event('alisms', ['alisms_error_ClientException' => $e->getErrorMessage()]); + return false; + } catch (ServerException $e) { + $this->log->event('alisms', ['alisms_error_ServerException' => $e->getErrorMessage()]); + return false; + } + } + + public function sendForCommunityFinancial($userId, $money) + { + + $csInfo = CsInfo::query()->where(['user_id' => $userId])->first(); + $market = Market::query()->where(['id' => $csInfo->market_id])->first(); + + $params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money]; + return $this->send($csInfo->phone, self::TEMPLATE_COMMUNITY_FINANCIAL, json_encode($params)); + } +} \ No newline at end of file diff --git a/app/Service/SmsServiceInterface.php b/app/Service/SmsServiceInterface.php new file mode 100644 index 0000000..7f69282 --- /dev/null +++ b/app/Service/SmsServiceInterface.php @@ -0,0 +1,9 @@ + \App\Service\SeparateAccountsService::class, \App\Service\ShopCarServiceInterface::class => \App\Service\ShopCarService::class, \App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class, + \App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class, ]; diff --git a/config/config.php b/config/config.php index ba75ad6..d416f7f 100644 --- a/config/config.php +++ b/config/config.php @@ -40,5 +40,12 @@ return [ 'wxtempmsg' => [ 'app_id' => env('APP_ID',''), 'secret' => env('APP_SECRET',''), + ], + 'alisms' => [ + 'app_key' => env('ALI_SMS_APP_KEY', ''), + 'app_secret' => env('ALI_SMS_APP_SECRET', ''), + 'regionid' => env('ALI_SMS_REGION_ID', ''), + 'product' => env('ALI_SMS_PRODUCT', ''), + 'host' => env('ALI_SMS_HOST', ''), ] ];