You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.2 KiB
68 lines
2.2 KiB
<?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));
|
|
}
|
|
}
|