Browse Source

调整短信接口

master
lanzu_qinsheng 5 years ago
parent
commit
24a3b0dc64
  1. 23
      app/Admin/Common/Rpc.php
  2. 40
      app/Admin/Common/Sms.php

23
app/Admin/Common/Rpc.php

@ -14,6 +14,7 @@ class Rpc
const ORDER_SINGLE_REFUND = "/order/onlineSingleRefund"; const ORDER_SINGLE_REFUND = "/order/onlineSingleRefund";
const GET_DISTANCE = "/location/getDistanceByTencent"; const GET_DISTANCE = "/location/getDistanceByTencent";
const DO_BY_ORDER = "/badge/doByOrder"; const DO_BY_ORDER = "/badge/doByOrder";
const ALI_SMS_SENT = "/alisms/sent";
@ -112,5 +113,27 @@ class Rpc
return json_decode($response->getBody()->getContents(),true); return json_decode($response->getBody()->getContents(),true);
} }
/**
* 阿里大于
* @param $phone
* @param $template
* @param $templateParams
* @param string $signName
* @return string
*/
public static function alisSmsSent($phone, $template, $templateParams, $signName='懒族生活'){
$client = Client::factory(env('RPC_SITE_HOST'));
$request = $client->request(uniqid(),
self::ALI_SMS_SENT,
[
'phone' => $phone,
'template'=>$template,
'templateParams'=> json_encode($templateParams),
'signName'=>$signName,
]);
$response = $client->send($request);
return $response->getBody()->getContents();
}
} }

40
app/Admin/Common/Sms.php

@ -12,34 +12,6 @@ use Graze\GuzzleHttp\JsonRpc\Client;
class Sms extends AdminController class Sms extends AdminController
{ {
/**
* 发送短信
* @throws ClientException
*/
public static function sent($params)
{
AlibabaCloud::accessKeyClient(env('ACCESS_KEY_ID'),env('ACCESS_SECRET'))
->regionId('cn-shenzhen')
->asDefaultClient();
try {
$result = AlibabaCloud::rpc()
->product('Dysmsapi')
->version('2017-05-25')
->action('SendSms')
->method('POST')
->host('dysmsapi.aliyuncs.com')
->options([
'query' => $params,
])
->request();
dd($result);
}catch (ClientException $e){
echo $e->getErrorMessage() . PHP_EOL;
}catch (ServerException $e){
echo $e->getErrorMessage() . PHP_EOL;
}
}
/** /**
* 远程RPC调用 * 远程RPC调用
* @param $phone * @param $phone
@ -48,16 +20,8 @@ class Sms extends AdminController
* @param string $signName * @param string $signName
* @return string * @return string
*/ */
public static function rpcSent($phone, $template, $templateParams, $signName='懒族生活')
public static function rpcSent($phone, $template, $templateParams, $signName)
{ {
$client = Client::factory(env('RPC_SITE_HOST'));
$request = $client->request(uniqid(),'/alisms/sent', [
'phone' => $phone,
'template'=>$template,
'templateParams'=> json_encode($templateParams),
'signName'=>$signName,
]);
$response = $client->send($request);
return $response->getBody()->getContents();
return Rpc::alisSmsSent($phone, $template, $templateParams, $signName);
} }
} }
Loading…
Cancel
Save