|
|
<?php
namespace App\Service\v3\Implementations;
use AlibabaCloud\Client\AlibabaCloud;use AlibabaCloud\Client\Exception\ClientException;use AlibabaCloud\Client\Exception\ServerException;use App\Constants\v3\ErrorCode;use App\Exception\ErrorCodeException;use App\Model\v3\CsInfo;use App\Model\v3\Market;use Exception;use App\Commons\Log;use App\Constants\v3\SmsTemplateCode;use Hyperf\Di\Annotation\Inject;use App\Service\v3\Interfaces\SmsSendServiceInterface;
class SmsAliSendService implements SmsSendServiceInterface{
/** * @Inject * @var Log */ protected $log;
public function do($tel, $template, $templateParams, $signName = '') {
try { $aliSms = config('alisms'); AlibabaCloud::accessKeyClient($aliSms['app_key'], $aliSms['app_secret']) ->regionId($aliSms['regionid']) ->asDefaultClient();
$result = AlibabaCloud::rpc() ->product($aliSms['product']) ->version('2017-05-25') ->action('SendSms') ->method('POST') ->host($aliSms['host']) ->options([ 'query' => [ 'RegionId' => $aliSms['regionid'], 'PhoneNumbers' => $tel, 'SignName' => $signName ?: $aliSms['sign_name'], 'TemplateCode' => $template, 'TemplateParam' => $templateParams, ], ]) ->request(); return $result->toArray(); } catch (ClientException $e) { $this->log->event('alisms', ['alisms_error_ClientException' => $e->getErrorMessage(), 'tel' => $tel, 'template' => json_encode($templateParams)]); throw new ErrorCodeException(ErrorCode::SMS_SEND_FAILURE); } catch (ServerException $e) { $this->log->event('alisms', ['alisms_error_ServerException' => $e->getErrorMessage(), 'tel' => $tel, 'template' => json_encode($templateParams)]); throw new ErrorCodeException(ErrorCode::SMS_SEND_FAILURE); } catch (Exception $e) { $this->log->event('alisms', ['alisms_error_Exception' => $e->getErrorMessage(), 'tel' => $tel, 'template' => json_encode($templateParams)]); throw new ErrorCodeException(ErrorCode::SMS_SEND_FAILURE); } }
public function check() { // TODO: Implement check() method.
}
public function undo() { // TODO: Implement undo() method.
}
public function doVerifyCode($tel, $code) { $params = ['code' => $code]; return $this->do($tel, SmsTemplateCode::ALI_VERIFY_CODE, json_encode($params)); }
public function checkVerifyCode($tel, $code) { // TODO: Implement checkVerifyCode() method.
}
public function undoVerifyCode($tel, $code) { // TODO: Implement removeVerifyCode() method.
}
public function doCommunityFinancial($csUserAdminId, $money, $orderMain) {
if ($money == 0) { return true; }
$csInfo = CsInfo::query()->where(['admin_user_id' => $csUserAdminId])->first(); $market = Market::query()->where(['id' => $orderMain->market_id])->first();
// $params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money];
$orderTel = substr_replace($orderMain->tel, '****', 3, 4); $params = [ 'store_name' => ' ['.$csInfo->name.'] ', 'markert_name' => ' ['.$market->name.'] ', 'user_name' => $orderMain->name.'(懒ID:'.$orderMain->user_id.')', 'pay_money' => $orderMain->money.'元', 'money' => $money.'元' ]; return $this->do($csInfo->phone, SmsTemplateCode::ALI_COMMUNITY_FINANCIAL, json_encode($params)); }
public function doWithdrawFail($storeName, $money, $errorCode, $errorCodeDes) { // 微信接口提示商户名称:${store_name},提现金额:${money}元,失败原因:${note}。
$params = ['store_name' => $storeName, 'money' => floatval(bcdiv($money, '100', 2)), 'note' => '(公司账户)'.$errorCodeDes]; return $this->do('18077798210', SmsTemplateCode::ALI_PAY_FOR_WITHDRAW_FAIL, json_encode($params)); }
}
|