![cover](https://img-blog.csdnimg.cn/20210611183830262.png)
edusoho新增腾讯云短信发送功能-PHP开发
edusoho二次开发不多解析了,直接上代码。/* 技术开发QQ */{% extends 'admin/layout.html.twig' %}{% set menu = 'admin_txsms_setting' %}{% set script_controller = 'txsmsplugin/controller/tx-sms/setting' %}{% block main %}{{ w
·
就不多解析了,直接上代码。
/* 技术开发QQ */
{% extends 'admin/layout.html.twig' %}
{% set menu = 'admin_txsms_setting' %}
{% set script_controller = 'txsmsplugin/controller/tx-sms/setting' %}
{% block main %}
{{ web_macro.flash_messages() }}
<form class="form-horizontal" id="tx-sms-form" method="post">
<fieldset>
<div class="tx-sms_enabled ">
<div class="form-group">
<div class="col-md-2 control-label">
<label for="SignName">{{ '签名'|trans }}</label>
</div>
<div class="col-md-8 controls">
<input type="text" id="SignName" name="SignName" class="form-control"
value="{{ setting.SignName|default('') }}">
</div>
</div>
<div class="form-group">
<div class="col-md-2 control-label">
<label for="TemplateCode">{{ '短信模板'|trans }}</label>
</div>
<div class="col-md-8 controls">
<input type="text" id="TemplateCode" name="TemplateCode" class="form-control"
value="{{ setting.TemplateCode|default('') }}">
</div>
</div>
<div class="form-group">
<div class="col-md-2 control-label">
<label for="appid">{{ 'appid'|trans }}</label>
</div>
<div class="col-md-8 controls">
<input type="text" id="appid" name="appid" class="form-control"
value="{{ setting.appid|default }}" required/>
</div>
</div>
<div class="form-group">
<div class="col-md-2 control-label">
<label for="appkey">{{ 'appkey'|trans }}</label>
</div>
<div class="col-md-8 controls">
<input type="text" id="appkey" name="appkey" class="form-control"
value="{{ setting.appkey|default }}" required/>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>{{'模板设置'|trans}}</legend>
<div class="form-group">
<div class="col-md-2 control-label">
<label for="test_mobile">{{ '测试手机号'|trans }}</label>
</div>
<div class="col-md-7 controls">
<input type="text" id="test_mobile" name="test_mobile" class="form-control"
value="{{ setting.test_mobile|default('') }}">
</div>
<div class="col-md-2 ">
<a class="btn btn-primary js-tx-sms-test" data-url="{{ path('admin_txsms_list', {type: 'TemplateCode', code: '123465'}) }}" href="javascript:;">验证</a>
</div>
</div>
</fieldset>
<div class="row form-group">
<div class="controls col-md-offset-2 col-md-8">
<button type="submit" class="btn btn-primary">{{ 'form.btn.submit'|trans }}</button>
</div>
</div>
<input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
</form>
{% endblock %}
<?php
/* 技术开发QQ */
namespace TxSmsPlugin;
use Codeages\PluginBundle\System\PluginBase;
use TxSmsPlugin\Biz\TxSmsServiceProvider;
class TxSmsPlugin extends PluginBase
{
public function boot()
{
parent::boot();
$biz = $this->container->get('biz');
$biz->register(new TxSmsServiceProvider());
require_once __DIR__ . '/vendor/qcloudsms_php/src/index.php';
}
}
<?php
/* 技术开发QQ */
namespace TxSmsPlugin\Controller;
use AppBundle\Common\ArrayToolkit;
use AppBundle\Common\Paginator;
use AppBundle\Controller\Admin\BaseController;
use Biz\System\Service\SettingService;
use Symfony\Component\HttpFoundation\Request;
use TxSmsPlugin\Biz\TxSms\Service\TxSmsService;
class AdminController extends BaseController
{
public function settingAction(Request $request)
{
$setting = $this->getSettingService()->get('plugin_tx_sms', array());
if ($request->getMethod() == 'POST') {
$setting = $request->request->all();
$this->getSettingService()->set('plugin_tx_sms', $setting);
$this->getSettingService()->set(
'cloud_sms',
array(
'sms_enabled' => 1,
'sms_login' => 'on',
'sms_bind' => 'on',
'sms_forget_password' => 'on',
)
);
$this->getLogService()->info('system', 'update_settings', '更新腾讯云短信配置', $setting);
$this->setFlashMessage('success', 'site.save.success');
}
return $this->render(
'TxSmsPlugin:Admin:setting.html.twig',
array(
'setting' => $setting,
)
);
}
public function listsAction(Request $request)
{
$conditions = $request->query->all();
$TxSmsCount = $this->getTxSmsService()->countTxSmss($conditions);
$paginator = new Paginator($this->get('request'), $TxSmsCount, 10);
$TxSmsLists = $this->getTxSmsService()->searchTxSmss(
$conditions,
array('createdTime' => 'DESC'),
$paginator->getOffsetCount(),
$paginator->getPerPageCount()
);
$userIds = ArrayToolkit::column($TxSmsLists, 'userId');
$users = $this->getUserService()->findUsersByIds($userIds);
if ($request->getMethod() == 'POST') {
$fields = $request->query->all();
$setting = $this->getSettingService()->get('plugin_tx_sms', array());
$res = $this->getTxSmsService()->sendSms(
$setting['test_mobile'],
$fields['code'] = rand(100000, 999999),
'TemplateCode'
);
if ($res['result'] == 0) {
return $this->createJsonResponse(array('status' => true, 'data' => $res));
} else {
return $this->createJsonResponse(array('status' => false, 'data' => $res['errmsg']));
}
}
return $this->render(
'TxSmsPlugin:Admin:lists.html.twig',
array(
'users' => $users,
'lists' => $TxSmsLists,
'count' => $TxSmsCount,
'paginator' => $paginator,
)
);
}
/**
* @return SettingService
*/
protected function getSettingService()
{
return $this->createService('System:SettingService');
}
/**
* @return TxSmsService
* */
protected function getTxSmsService()
{
return $this->createService('TxSmsPlugin:TxSms:TxSmsService');
}
}
二次开发 技术交流 QQ扫一扫
更多推荐
所有评论(0)