Test.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php namespace App\Http\Controllers\Api;
  2. use AlibabaCloud\SDK\Dyvmsapi\V20170525\Dyvmsapi;
  3. use \Exception;
  4. use AlibabaCloud\Tea\Exception\TeaError;
  5. use AlibabaCloud\Tea\Utils\Utils;
  6. use Darabonba\OpenApi\Models\Config;
  7. use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\SingleCallByTtsRequest;
  8. use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
  9. use App\Facades\Servers\Logs\Log;
  10. /**
  11. * 测试接口
  12. *
  13. * @author 刘相欣
  14. *
  15. * */
  16. class Test extends Api{
  17. /**
  18. * 同步 /api/test/sync_user
  19. *
  20. * */
  21. public function sync_user(){
  22. // 获取三天后到期的优惠券->addDays(3)
  23. $list = $Model->query()->where([['status','=',0],['exp_time','>',now()->createFromTimestamp(1741338720)->startOfDay()->getTimestamp()],['exp_time','<',now()->createFromTimestamp(1741338720)->endOfDay()->getTimestamp()]])->pluck('coupon_id','custom_uid')->toArray();
  24. // 通过列表查询对应的客户手机号
  25. $phoneList = $Custom->query()->whereIn('uid',array_keys($list))->pluck('phone')->toArray();
  26. // 给这些手机号发送一条阿里云短信
  27. $phoneList = implode(',',$phoneList);
  28. dd($phoneList);
  29. Log::error("测试接口",'测试接口',request()->all());
  30. return response()->json(["code"=> 0,"msg"=>"成功"]);
  31. self::main();
  32. }
  33. /**
  34. * 使用AK&SK初始化账号Client
  35. * @return Dyvmsapi Client
  36. */
  37. public static function createClient(){
  38. // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
  39. // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/311677.html
  40. $config = new Config(["accessKeyId" => 'LTAI5tDwjfteBvivYN41r8sJ', "accessKeySecret" => 'yowuOGi2nYYnrqGpO3qcz94C4brcPp']);
  41. // Endpoint 请参考 https://api.aliyun.com/product/Dyvmsapi
  42. $config->endpoint = "dyvmsapi.aliyuncs.com";
  43. return new Dyvmsapi($config);
  44. }
  45. /**
  46. * @param string[] $args
  47. * @return void
  48. */
  49. public static function main(){
  50. $client = self::createClient();
  51. $singleCallByTtsRequest = new SingleCallByTtsRequest([
  52. 'calledNumber' => '18610028595',
  53. 'ttsCode' => 'TTS_307425151',
  54. 'ttsParam' => '{"name":"刘先生","task":"11"}',
  55. 'playTimes' => 1
  56. ]);
  57. $runtime = new RuntimeOptions([]);
  58. try {
  59. // 复制代码运行请自行打印 API 的返回值
  60. $result = $client->singleCallByTtsWithOptions($singleCallByTtsRequest, $runtime);
  61. dd($result->toMap());
  62. }
  63. catch (Exception $error) {
  64. if (!($error instanceof TeaError)) {
  65. $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
  66. }
  67. // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
  68. // 错误 message
  69. var_dump($error->message);
  70. // 诊断地址
  71. var_dump($error->data["Recommend"]);
  72. Utils::assertAsString($error->message);
  73. }
  74. }
  75. }