discuzQ如何修改短信接口为阿里云短信

第一步

文件 app\Api\Serializer\ForumSettingSerializer.php

第130行

 'qcloud_sms' => (bool)$this->settings->get('qcloud_sms', 'qcloud'),

改为

'qcloud_sms' => true,

文件 app\Listeners\Setting\ClearDisabledPermission.php

找到

if ($this->settings->get('register_type') == 1) {
     $this->settings->set('register_type', 0);
 }

删除或者注释

登录后台 选择 全局->注册与登录设置 ,选择手机号模式 保存。

利用数据库管理工具执行:

INSERT INTO pre_group_permission (group_id, permission) VALUES ('10', 'publishNeedBindPhone');

10 为用户组ID 开启用户组 发帖需要绑定手机

第二步

文件 app\Api\Controller\Mobile\SendController.php

use Tobscure\JsonApi\Document;

下面加

use Overtrue\EasySms\EasySms;

找到:

if (!(bool)$this->settings->get('qcloud_sms', 'qcloud')) {
     // 未开启短息服务不发送短信
     $mobileRule = [
                     function ($attribute, $value, $fail) {
         $fail('短信服务未开启。');
     }
     ,
                 ];
 } else

删除

找到

$result = $this->smsSend($data['mobile'], new SendCodeMessage(['code' => $mobileCode->code, 'expire' => self::CODE_EXCEPTION]));
 if (isset($result['qcloud']['status']) && $result['qcloud']['status'] === 'success') {
     $mobileCode->save();
 }

注释或删除

增加

//阿里云
 $config = [
             // HTTP 请求的超时时间(秒)
 'timeout' => 5.0,
             // 默认发送配置
 'default' => [
                 // 网关调用策略,默认:顺序调用
 'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,
                 // 默认可用的发送网关
 'gateways' => [
                     'aliyun'
                 ],
             ],
             // 可用的网关配置
 'gateways' => [
                 'errorlog' => [
                     'file' => '/tmp/easy-sms.log',
                 ],
                 'aliyun' => [
                     'access_key_id' => 'AccessKeyId',
                     'access_key_secret' => 'AccessKeySecret',
                     'sign_name' => '签名',
                 ],
                 //…
 ],
         ];
 $easySms = new EasySms($config);
 $result = $easySms->send($data['mobile'],[
             'template' => '短信模板ID',
             'data' => [
                 'code' => $mobileCode->code
             ],
         ]);
 if (isset($result['aliyun']['status']) && $result['aliyun']['status'] === 'success') {
     $mobileCode->save();
 }'

完成

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
广告位招租919838898
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索