当前位置:   article > 正文

TP5 关于阿里组件发短信报错:致命错误: Class ‘Dysmsapi‘ not found 处理_pip install alibabacloud_dysmsapi20170525==2.0.24执

pip install alibabacloud_dysmsapi20170525==2.0.24执行就报错

1、按照阿里的模版进行安装,composer require alibabacloud/dysmsapi-20170525 2.0.24 直接安装,组成的接口,封转的方法,提示报错,分析原因,发现是版本有问题,需要下载指定的版本:

composer require alibabacloud/dysmsapi-20170525 2.0.20

 2、将下载的组件全部清理了,然后再重新按照新的版本;该代码是写在common.php里面的,上面加载对应的配置

代码实例:

  1. use Darabonba\OpenApi\Models\Config as Dconfig;
  2. use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
  3. use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
  4. use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
  5. /**
  6. * 阿里大于短信发送新版
  7. */
  8. function sendsms($phone, $code, $type="SMS_154950909", $flag = 'single')
  9. {
  10. $option = Config::get('applet.sms');
  11. $config = new Dconfig([
  12. // 必填,您的 AccessKey ID
  13. "accessKeyId" => $option['sms_key'],
  14. // 必填,您的 AccessKey Secret
  15. "accessKeySecret" => $option['sms_secret'],
  16. ]);
  17. $config->endpoint = "dysmsapi.aliyuncs.com";
  18. $client = new Dysmsapi($config);
  19. $sendSmsRequest = new SendSmsRequest(
  20. [
  21. "signName" => $flag,
  22. "templateCode" => $type,
  23. "phoneNumbers" => $phone,
  24. "templateParam" => "{\"code\":\"$code\"}"
  25. ]
  26. );
  27. $runtime = new RuntimeOptions([]);
  28. try {
  29. // 复制代码运行请自行打印 API 的返回值
  30. $a = $client->sendSmsWithOptions($sendSmsRequest, $runtime);
  31. return 1;
  32. }
  33. catch (Exception $error) {
  34. if (!($error instanceof TeaError)) {
  35. // $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
  36. }
  37. // 如有需要,请打印 error
  38. return 0;
  39. }
  40. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/70288
推荐阅读
相关标签
  

闽ICP备14008679号