链街Dcat后台
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.

63 lines
1.8 KiB

  1. <?php
  2. namespace App\Admin\Common;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use Dcat\Admin\Controllers\AdminController;
  7. use Graze\GuzzleHttp\JsonRpc\Client;
  8. class Sms extends AdminController
  9. {
  10. /**
  11. * 发送短信
  12. * @throws ClientException
  13. */
  14. public static function sent($params)
  15. {
  16. AlibabaCloud::accessKeyClient(env('ACCESS_KEY_ID'),env('ACCESS_SECRET'))
  17. ->regionId('cn-shenzhen')
  18. ->asDefaultClient();
  19. try {
  20. $result = AlibabaCloud::rpc()
  21. ->product('Dysmsapi')
  22. ->version('2017-05-25')
  23. ->action('SendSms')
  24. ->method('POST')
  25. ->host('dysmsapi.aliyuncs.com')
  26. ->options([
  27. 'query' => $params,
  28. ])
  29. ->request();
  30. dd($result);
  31. }catch (ClientException $e){
  32. echo $e->getErrorMessage() . PHP_EOL;
  33. }catch (ServerException $e){
  34. echo $e->getErrorMessage() . PHP_EOL;
  35. }
  36. }
  37. /**
  38. * 远程RPC调用
  39. * @param $phone
  40. * @param $template
  41. * @param $templateParams
  42. * @param string $signName
  43. * @return string
  44. */
  45. public static function rpcSent($phone, $template, $templateParams, $signName='懒族生活')
  46. {
  47. $client = Client::factory(env('RPC_SITE_HOST'));
  48. $request = $client->request(uniqid(),'/alisms/sent', [
  49. 'phone' => $phone,
  50. 'template'=>$template,
  51. 'templateParams'=> json_encode($templateParams),
  52. 'signName'=>$signName,
  53. ]);
  54. $response = $client->send($request);
  55. return $response->getBody()->getContents();
  56. }
  57. }