yii2短信消息队列
2017-04-11 00:00
162 查看
1、在backend\config\params-local.php中加入
<?php return [ 'order_file_sms_id' => '121313', 'order_file_sms_preview' => '您的文件请及时下载,签字后邮寄到:{1},收件人:{2},电话:{3}', 'send_invoice_sms_id' => '323232',//模板id 'send_invoice_sms_preview' => '[掘金企服】尊敬的客户您好,您的发票已寄出,快递公司:{1},快递单号:{2},预计到达时间:{3},请注意查收!如需帮助,请拨打400-900-6969.',//模板内容 ];
2、在backend\views\invoice-list\list.php中引入
<!--已寄送start--> <div class="modal fade" id="send-invoice-modal" tabindex="-1" role="dialog" aria-labelledby="modal-title"> <div class="modal-dialog" role="document"> <div class="modal-content"> <?php $sendInvoiceForm = new \backend\models\SendInvoiceForm(); $form = \yii\bootstrap\ActiveForm::begin([ 'action' => ['invoice-action/send'], 'id' => 'send-invoice-form', 'validationUrl' => ['invoice-action/send', 'is_validate' => 1], 'enableAjaxValidation' => true, 'layout' => 'horizontal', 'fieldConfig' => [ 'horizontalCssClasses' => [ 'label' => 'col-sm-3', 'offset' => 'col-sm-offset-3', 'wrapper' => 'col-sm-8', ], ], ]); ?> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">已寄送</h4> </div> <div class="modal-body"> <?= $form->field($sendInvoiceForm, 'express')->textInput() ?> <?= $form->field($sendInvoiceForm, 'express_no')->textInput() ?> <?= $form->field($sendInvoiceForm, 'send_time')->widget(DateTimePicker::className(), [ 'clientOptions' => [ 'format' => 'yyyy-mm-dd',//显示的时间格式,年-月-日 'language' => 'zh-CN', 'autoclose' => true, 'minView' => 'month',//设置时间插件的显示格式,根据不同的参数显示,这里month只显示天 ], 'clientEvents' => [], ]) ?> //引入短信队列 id:send_invoice_sms_id,内容:send_invoice_sms_preview <?php if(isset(Yii::$app->params['send_invoice_sms_id']) && isset(Yii::$app->params['send_invoice_sms_preview'])): ?> <h4>将给客户发送以下信息:</h4> <p id="sms-preview"> <?= str_replace(['{1}','{2}','{3}'], [$sendInvoiceForm->express, $sendInvoiceForm->express_no, $sendInvoiceForm->send_time], Yii::$app->params['send_invoice_sms_preview'])?> </p> <?php endif; ?> </div> <div class="modal-footer"> <?= Html::activeHiddenInput($sendInvoiceForm, 'id', ['id' => 'send-invoice-form_id']); ?> <span class="text-danger warning-active"></span> <button type="button" class="btn btn-default" data-dismiss="modal">取消</button> <button type="submit" class="btn btn-primary refund-sure-btn">确定</button> </div> <?php \yii\bootstrap\ActiveForm::end(); ?> <?php //上面输入框输入内容替换短信部分,其中"\n", "\r", "\n\r"], 用''替换,$smsPreview = str_replace(["\n", "\r", "\n\r"], '', Yii::$app->params['send_invoice_sms_preview']); $this->registerJs(<<<JS //3个输入框,只要改动任何一个就替换掉内容 $('#express, #express_no, #send_time').change(function(){ replaceSmsPreview(); }); //替换部分 function replaceSmsPreview() { var smsPreview = '{$smsPreview}';//必须用单引号,而且写在外面,否则js不识别 var express = $('#express').val(); var express_no = $('#express_no').val(); var send_time = $('#send_time').val(); //替换 smsPreview = smsPreview.replace('{1}', express).replace('{2}', express_no).replace('{3}', send_time); $('#sms-preview').text(smsPreview); } $('.send-invoice-btn').on('click', function(){ var id = $(this).attr('data-id'); $('#send-invoice-form_id').val(id); }); $('#send-invoice-form').on('beforeSubmit', function(){ var form = $(this); $.post(form.attr('action'), form.serialize(), function(rs){ if(rs.status === 200) { form.trigger('reset.yiiActiveForm'); window.location.reload(); } else { form.find('.warning-active').text(rs.message); } }, 'json'); return false; }); JS )?> </div> </div> </div> <!--已寄送end-->
相关文章推荐
- 从“阿北的知识分享”新增视频模板消息推送开始说yii2队列
- Linux进程间通信——使用消息队列
- 消息队列及发布/订阅模式
- UNIX/LINUX编程学习之进程通信--消息队列
- 如何通过短信网关发送Wappush消息?
- SpringBoot非官方教程 | 第十四篇:在springboot中用redis实现消息队列
- 消息队列的两种模式
- 分布式系统组成:分布式缓存、存储、消息队列
- linux编程之共享内存、消息队列、管道
- 消息队列 进程间通信
- 大型网站架构系列:分布式消息队列(一)
- Linux进程间通信IPC学习笔记之消息队列(Posix)
- 开源消息队列系统 rabbitmq-server 安装详细
- 关于消息队列的使用
- 进程通信之消息队列
- 架构学习----消息队列
- 快速入门分布式消息队列之 RabbitMQ(2)
- ipcs查看消息队列命令
- ios 调用短信接口发送指定内容的消息
- 学习笔记之消息队列