Skip to content

Commit

Permalink
Merge pull request #2 from asundust/analysis-lZ7PVQ
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
asundust authored Aug 9, 2022
2 parents 1ac5122 + 9ff4eef commit 1217065
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/DcatWechatWorkPushServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class DcatWechatWorkPushServiceProvider extends ServiceProvider

public function register()
{
//
}

public function init()
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Actions/SendTestMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SendTestMessage extends RowAction
use WechatWorkPushSendMessageTrait;

/**
* 标题
* 标题.
*
* @return string
*/
Expand All @@ -23,8 +23,8 @@ public function title()
}

/**
* @param Request $request
* @return \Dcat\Admin\Actions\Response
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
*/
Expand All @@ -45,18 +45,18 @@ public function handle(Request $request)
'agent_id' => DcatWechatWorkPushServiceProvider::setting('agent_id'),
'secret' => DcatWechatWorkPushServiceProvider::setting('secret'),
];
if (count(array_filter($config)) != 3) {
if (3 != count(array_filter($config))) {
return $this->response()->error('【默认配置】或【自定义配置】企业微信通道尚未配置');
}
$type = '默认';
}

$title = '当前使用的【' . $type . '配置】企业微信通道发送的测试消息';
$title = '当前使用的【'.$type.'配置】企业微信通道发送的测试消息';
$result = $this->send($config, $user->name, $title);
if (0 == $result['code']) {
return $this->response()->success('使用【' . $type . '配置】企业微信通道发送消息成功');
return $this->response()->success('使用【'.$type.'配置】企业微信通道发送消息成功');
}

return $this->response()->success('使用【' . $type . '配置】企业微信通道发送消息失败:' . $result['message']);
return $this->response()->success('使用【'.$type.'配置】企业微信通道发送消息失败:'.$result['message']);
}
}
3 changes: 1 addition & 2 deletions src/Http/Controllers/WechatWorkPushHandleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class WechatWorkPushHandleController extends AdminController

/**
* @param $secret
* @param Request $request
* @return array
*
* @throws InvalidArgumentException
* @throws RuntimeException
*/
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Controllers/WechatWorkPushUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ protected function grid()
$grid->column('id', '序号');
$grid->column('name', '推送账号')->copyable();
$grid->column('sc_secret', '推送密钥')->display(function ($scSecret) {
return '<a href="javascript:void(0);" class="grid-column-copyable text-muted" data-content="' . $scSecret . '" title="" data-placement="bottom" data-original-title="已复制!"><i class="fa fa-copy"></i></a>&nbsp;***';
return '<a href="javascript:void(0);" class="grid-column-copyable text-muted" data-content="'.$scSecret.'" title="" data-placement="bottom" data-original-title="已复制!"><i class="fa fa-copy"></i></a>&nbsp;***';
});
$grid->column('api_address', '推送Api地址')->display(function () {
/* @var WechatWorkPushUser $this */
$apiAddressShow = $this->api_address_show;
$apiAddress = $this->api_address;
return '<a href="javascript:void(0);" class="grid-column-copyable text-muted" data-content="' . $apiAddress . '" title="" data-placement="bottom" data-original-title="已复制!"><i class="fa fa-copy"></i></a>&nbsp;' . $apiAddressShow;

return '<a href="javascript:void(0);" class="grid-column-copyable text-muted" data-content="'.$apiAddress.'" title="" data-placement="bottom" data-original-title="已复制!"><i class="fa fa-copy"></i></a>&nbsp;'.$apiAddressShow;
});
$grid->column('status', '账号状态')->switch();
$grid->column('is_own_wechat_work', '自定企业微信')->bool();
Expand Down
30 changes: 16 additions & 14 deletions src/Http/Traits/WechatWorkPushSendMessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ trait WechatWorkPushSendMessageTrait
/**
* 使用自定配置发送消息.
*
* @param array $config 配置 ['corp_id' => 'xxx', 'agent_id' => 'xxx', 'secret' => 'xxx'];
* @param string $name 用户
* @param string $title 标题
* @param string|null $content 内容
* @param string|null $url 链接
* @param array $config 配置 ['corp_id' => 'xxx', 'agent_id' => 'xxx', 'secret' => 'xxx'];
* @param string $name 用户
* @param string $title 标题
* @param string|null $content 内容
* @param string|null $url 链接
* @param string|null $urlTitle 链接标题
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
Expand All @@ -26,10 +26,10 @@ public function send(array $config, string $name, string $title, ?string $conten
{
$message = $title;
if ($content) {
$message .= "\n\n" . $content;
$message .= "\n\n".$content;
}
if ($url) {
$message .= "\n\n" . '<a href="' . $url . '">' . ($urlTitle ?: $url) . '</a>';
$message .= "\n\n".'<a href="'.$url.'">'.($urlTitle ?: $url).'</a>';
}

if (
Expand All @@ -45,8 +45,8 @@ public function send(array $config, string $name, string $title, ?string $conten
'msgtype' => 'text',
'agentid' => $config['agent_id'],
'text' => [
'content' => $message
]
'content' => $message,
],
]);
$result = $response->toArray();
} else {
Expand All @@ -57,16 +57,17 @@ public function send(array $config, string $name, string $title, ?string $conten
if (0 == $result['errcode'] && 'ok' == $result['errmsg']) {
return ['code' => 0, 'message' => 'success', 'original' => app()->isLocal() ? $result : []];
}

return ['code' => 1, 'message' => $result['errmsg'], 'original' => app()->isLocal() ? $result : []];
}

/**
* 使用默认配置发送消息.
*
* @param string $name 用户
* @param string $title 标题
* @param string|null $content 内容
* @param string|null $url 链接
* @param string $name 用户
* @param string $title 标题
* @param string|null $content 内容
* @param string|null $url 链接
* @param string|null $urlTitle 链接标题
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
Expand All @@ -84,9 +85,10 @@ public function defaultSend(string $name, string $title, ?string $content = null
}

/**
* 获取已安装扩展的版本号
* 获取已安装扩展的版本号.
*
* @param $packageName
*
* @return false|string
*/
private function getPackageVersion($packageName)
Expand Down
2 changes: 1 addition & 1 deletion src/Http/push.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

use Asundust\DcatWechatWorkPush\Http\Controllers\WechatWorkPushHandleController;

Route::match(['get', 'post'], 'push/{secret}', WechatWorkPushHandleController::class . '@push');
Route::match(['get', 'post'], 'push/{secret}', WechatWorkPushHandleController::class.'@push');
2 changes: 1 addition & 1 deletion src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
use Asundust\DcatWechatWorkPush\Http\Controllers\WechatWorkPushUserController;
use Illuminate\Support\Facades\Route;

Route::resource('wechatWorkPushUsers', WechatWorkPushUserController::class)->except(['show']);
Route::resource('wechatWorkPushUsers', WechatWorkPushUserController::class)->except(['show']);
18 changes: 9 additions & 9 deletions src/Models/WechatWorkPushUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
/**
* Asundust\DcatWechatWorkPush\Models\WechatWorkPushUser.
*
* @property int $id
* @property string $name 用户的账户
* @property string $sc_secret 用户的推送密钥
* @property int $status 状态(0禁用1启用)
* @property int $id
* @property string $name 用户的账户
* @property string $sc_secret 用户的推送密钥
* @property int $status 状态(0禁用1启用)
* @property string|null $corp_id 用户自定企业ID
* @property string|null $agent_id 用户自定应用ID/agent_id
* @property string|null $secret 用户自定应用Secret
* @property bool $is_own_wechat_work
* @property string $api_address
* @property string $api_address_show
* @property bool $is_own_wechat_work
* @property string $api_address
* @property string $api_address_show
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @mixin Eloquent
Expand Down Expand Up @@ -65,12 +65,12 @@ public function getIsOwnWechatWorkAttribute(): bool
// api_address_show
public function getApiAddressShowAttribute(): string
{
return config('app.url') . '/push/***';
return config('app.url').'/push/***';
}

// api_address
public function getApiAddressAttribute(): string
{
return config('app.url') . '/push/' . $this->sc_secret . '?title=我是标题&content=我是内容(可不填)&url=我是链接(可不填)&url_title=链接标题(可不填)';
return config('app.url').'/push/'.$this->sc_secret.'?title=我是标题&content=我是内容(可不填)&url=我是链接(可不填)&url_title=链接标题(可不填)';
}
}

0 comments on commit 1217065

Please sign in to comment.