-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
424 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Biz; | ||
|
||
use App\Repositories\UserRepository; | ||
use App\Exceptions\NormalException; | ||
use Wxsdk\Qywx; | ||
|
||
class UserBiz | ||
{ | ||
protected $userRepo; | ||
|
||
public function __construct(UserRepository $userRepo) | ||
{ | ||
$this->userRepo = $userRepo; | ||
} | ||
|
||
public function sendWxMsg($username, $title, $message, $url = '') | ||
{ | ||
$qywx = new Qywx(config('qywx.app')); | ||
|
||
$articles = [ | ||
$qywx->buildNewsItem($title, $message, $url, ''), | ||
]; | ||
|
||
if (!is_array($username)) { | ||
$username = [$username]; | ||
} | ||
|
||
$username = array_filter($username, function ($name) { | ||
return !in_array($name, ['suadmin', 'admin', 'demo']); | ||
}); | ||
|
||
$result = $qywx->sendNewsMsg( | ||
$articles, | ||
['touser' => $username], | ||
config('qywx.app.appid') | ||
); | ||
|
||
if (($result['invaliduser'] ?? false) or | ||
($result['invalidparty'] ?? false) or | ||
($result['invalidtag'] ?? false)) { | ||
throw new NormalException('部分发送失败'); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
|
||
class NormalException extends Exception | ||
{ | ||
protected $errors = []; | ||
protected $status = 'error'; | ||
protected $data = null; | ||
|
||
public function __construct($message = '', $status = 'error', $errors = [], $data = null, $code = 0) | ||
{ | ||
$this->errors = $errors; | ||
$this->status = $status; | ||
$this->data = $data; | ||
|
||
parent::__construct($message, $code); | ||
} | ||
|
||
public function toArray() | ||
{ | ||
return [ | ||
'status' => $this->status, | ||
'message' => $this->getMessage(), | ||
'data' => $this->data, | ||
'errors' => $this->errors, | ||
'code' => $this->getCode(), | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
use App\Repositories\DepartmentRepository; | ||
use App\Repositories\UserRepository; | ||
|
||
class SyncFromQywx implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
protected $userRepo; | ||
protected $departmentRepo; | ||
|
||
public function __construct( | ||
UserRepository $userRepo, | ||
DepartmentRepository $departmentRepo | ||
) { | ||
$this->userRepo = $userRepo; | ||
$this->departmentRepo = $departmentRepo; | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$this->departmentRepo->sync(); | ||
$this->userRepo->sync(); | ||
} | ||
} |
Oops, something went wrong.