8 changed files with 161 additions and 2 deletions
-
29app/Model/AdminUser.php
-
29app/Model/CsInfo.php
-
17app/Service/FinancialRecordService.php
-
68app/Service/SmsAliService.php
-
9app/Service/SmsServiceInterface.php
-
3composer.json
-
1config/autoload/dependencies.php
-
7config/config.php
@ -0,0 +1,29 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
use Hyperf\DbConnection\Model\Model; |
|||
/** |
|||
*/ |
|||
class AdminUser extends Model |
|||
{ |
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'admin_users'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = []; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = []; |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
use Hyperf\DbConnection\Model\Model; |
|||
/** |
|||
*/ |
|||
class CsInfo extends Model |
|||
{ |
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'lanzu_cs_info'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = []; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = []; |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
use AlibabaCloud\Client\AlibabaCloud; |
|||
use AlibabaCloud\Client\Exception\ClientException; |
|||
use AlibabaCloud\Client\Exception\ServerException; |
|||
use App\Commons\Log; |
|||
use App\Model\CsInfo; |
|||
use App\Model\Market; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
|
|||
class SmsAliService implements SmsServiceInterface |
|||
{ |
|||
const TEMPLATE_COMMUNITY_FINANCIAL = 'SMS_200690862'; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var Log |
|||
*/ |
|||
protected $log; |
|||
|
|||
public function send($phone, $template, $templateParams, $signName='懒族生活') |
|||
{ |
|||
|
|||
$alisms = config('alisms'); |
|||
AlibabaCloud::accessKeyClient($alisms['app_key'], $alisms['app_secret']) |
|||
->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)); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
<?php |
|||
|
|||
namespace App\Service; |
|||
|
|||
interface SmsServiceInterface |
|||
{ |
|||
public function send($phone, $template, $templateParams); |
|||
public function sendForCommunityFinancial($userId, $money); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue