1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 20:06:09 +08:00

1.优化课程章节权限

2.优化钉钉机器人
This commit is contained in:
xiaochong0302 2023-06-15 18:05:19 +08:00
parent f7a3c0d736
commit a72f44225f
5 changed files with 74 additions and 24 deletions

View File

@ -14,15 +14,15 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">App Secret</label>
<label class="layui-form-label">Webhook</label>
<div class="layui-input-block">
<input class="layui-input" type="text" name="app_secret" value="{{ robot.app_secret }}" lay-verify="required">
<input class="layui-input" type="text" name="app_token" value="{{ robot.webhook_url }}" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">Access Token</label>
<label class="layui-form-label">加签密钥</label>
<div class="layui-input-block">
<input class="layui-input" type="text" name="app_token" value="{{ robot.app_token }}" lay-verify="required">
<input class="layui-input" type="text" name="app_secret" value="{{ robot.app_secret }}" lay-verify="required">
</div>
</div>
<div class="layui-form-item">

View File

@ -135,24 +135,21 @@ class DingTalkNotice extends Service
*/
public function send($params)
{
if (!isset($params['msgtype'])) {
$params['msgtype'] = 'text';
}
$webhookUrl = $this->settings['webhook_url'];
$appSecret = $this->settings['app_secret'];
$appToken = $this->settings['app_token'];
$timestamp = time() * 1000;
$data = sprintf("%s\n%s", $timestamp, $appSecret);
$sign = urlencode(base64_encode(hash_hmac('sha256', $data, $appSecret, true)));
$baseUrl = 'https://oapi.dingtalk.com/robot/send';
$postUrl = $webhookUrl;
$postUrl = $baseUrl . '?' . http_build_query([
'access_token' => $appToken,
'timestamp' => $timestamp,
'sign' => $sign,
]);
if (!empty($appSecret)) {
$postUrl = $webhookUrl . '&' . http_build_query([
'timestamp' => $timestamp,
'sign' => $sign,
]);
}
try {

View File

@ -69,6 +69,8 @@ trait ChapterTrait
public function setChapterUser(ChapterModel $chapter, UserModel $user)
{
if ($user->id == 0) return;
$chapterUser = null;
/**
@ -76,7 +78,7 @@ trait ChapterTrait
*/
$courseUser = $this->courseUser;
if ($user->id > 0 && $courseUser) {
if ($courseUser) {
$chapterUserRepo = new ChapterUserRepo();
$chapterUser = $chapterUserRepo->findPlanChapterUser($chapter->id, $user->id, $courseUser->plan_id);
}

View File

@ -66,16 +66,16 @@ class CourseInfo extends LogicService
$caseModel = $course->attrs['end_date'] < date('Y-m-d');
}
if ($caseOwned && $casePrice && $caseModel) {
$me['allow_order'] = 1;
}
if ($course->market_price == 0) {
$me['allow_reward'] = 1;
}
if ($user->id > 0) {
if ($caseOwned && $casePrice && $caseModel) {
$me['allow_order'] = 1;
}
if ($course->market_price == 0) {
$me['allow_reward'] = 1;
}
$me['logged'] = 1;
$favoriteRepo = new CourseFavoriteRepo();

View File

@ -0,0 +1,51 @@
<?php
/**
* @copyright Copyright (c) 2023 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
require_once 'SettingTrait.php';
use Phinx\Migration\AbstractMigration;
final class V20230611193031 extends AbstractMigration
{
use SettingTrait;
public function up()
{
$this->handleDingTalkRobotSettings();
}
protected function handleDingTalkRobotSettings()
{
$row = $this->getQueryBuilder()
->select('*')
->from('kg_setting')
->where(['section' => 'dingtalk.robot'])
->andWhere(['item_key' => 'app_token'])
->execute()->fetch(PDO::FETCH_ASSOC);
$webhookUrl = '';
/**
* 直接使用webhook地址不用单独分离出access_token简化用户操作
*/
if (!empty($row['item_value'])) {
$webhookUrl = "https://oapi.dingtalk.com/robot/send?access_token={$row['item_value']}";
}
$rows = [
[
'section' => 'dingtalk.robot',
'item_key' => 'webhook_url',
'item_value' => $webhookUrl,
],
];
$this->insertSettings($rows);
}
}