- 添加短信模版
通過一下代碼可以判斷出,模版ID是通過數據庫查出來了
細看getSmsTemplate方法發現,是根據類型返回不同的模版ID,數據都在system_notice_config這個表里。思路清晰了,我們要自定義短信就得在這個表里面加一條數據。如下
INSERT INTO `eb_system_notice_config` (`notice_config_id`, `notice_title`, `const_key`, `notice_info`, `notice_sys`, `notice_sms`, `notice_wechat`, `wechat_tempkey`, `wechat_content`, `wechat_tempid`, `notice_routine`, `routine_tempkey`, `routine_content`, `routine_tempid`, `type`, `sms_tempid`, `sms_ali_tempid`, `sms_content`, `create_time`, `update_time`, `kid`) VALUES (33, '自定義名稱', '自定義key', '自定義消息說明', -1, 1, -1, null, '', null, -1, null, '', 0, '自定義一號通短信模版ID', '自定義阿里云短信模版ID', '阿里云短信模板內容', '2022-12-05 14:41:52', '2023-09-06 15:48:31', 0);
注意里面一些自定義參數,這參數得根據具體使用情況而定
`notice_sys`,`notice_sms`,`notice_wechat`,`notice_routine`這幾個字段是控制消息開關。
`kid` 小程序模版消息時使用。
`sms_content` 模板內容
例如sms_content為: 恭喜您已成為${store_name}商城付費會員,擁有專享優惠權益,有效期截至${date},祝您購物愉快!
這個消息模版需要兩個參數store_name和date
我們在使用時需要以數組的形式傳參,如下(代碼路徑:crmeb/services/SmsService.php。287行)
self::create()->send('要發送的手機號', $tempId, ['store_name' => '自定義名稱','date' => '自定義時間']);
2. 添加短信發送
在文件 crmeb/services/SmsService.php sendMessage() 方法下定義新的類型,如下所示
注意:這里面的自定義key得根具上面添加數據時的const_key走
store_name和date是短信模版里面的參數。
3. 使用
發送消息的總入口在隊列SendSmsJob中,路徑crmeb/jobs/SendSmsJob.php
使用時調用隊列,如下。 參數說明:tempId是必傳的,其它參數根據實際使用情況而定
Queue::push(SendSmsJob::class, ['tempId' => '自定義key']);
修改完隊列代碼后要重啟隊列在測試