Browse Source

修正

master
weigang 5 years ago
parent
commit
0def4a0f9f
  1. 2
      app/Controller/v3/SmsController.php
  2. 8
      app/Controller/v3/UserController.php
  3. 23
      app/Service/v3/Implementations/SmsAliSendService.php
  4. 10
      app/Service/v3/Implementations/UserBindTelService.php
  5. 12
      app/Service/v3/Implementations/VerifyCodeService.php
  6. 13
      app/Service/v3/Interfaces/SmsSendServiceInterface.php
  7. 11
      app/Service/v3/Interfaces/SmsServiceInterface.php
  8. 10
      app/Service/v3/Interfaces/UserBindServiceInterface.php
  9. 10
      app/Service/v3/Interfaces/UserBindTelServiceInterface.php
  10. 4
      app/Service/v3/Interfaces/VerifyCodeServiceInterface.php
  11. 4
      config/autoload/dependencies.php

2
app/Controller/v3/SmsController.php

@ -34,7 +34,7 @@ class SmsController extends BaseController
// 获取参数 // 获取参数
$params = $request->validated(); $params = $request->validated();
// 获取并发送验证码 // 获取并发送验证码
$this->verifyCodeService->make($params['user_id'], $params['tel']);
$this->verifyCodeService->do($params['user_id'], $params['tel']);
return $this->success([]); return $this->success([]);
} }

8
app/Controller/v3/UserController.php

@ -5,7 +5,7 @@ namespace App\Controller\v3;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Request\v3\UserBindTelRequest; use App\Request\v3\UserBindTelRequest;
use App\Service\v3\Interfaces\UserBindServiceInterface;
use App\Service\v3\Interfaces\UserBindTelServiceInterface;
use App\Service\v3\Interfaces\VerifyCodeServiceInterface; use App\Service\v3\Interfaces\VerifyCodeServiceInterface;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
@ -25,9 +25,9 @@ class UserController extends BaseController
/** /**
* @Inject * @Inject
* @var UserBindServiceInterface
* @var UserBindTelServiceInterface
*/ */
protected $userBindService;
protected $userBindTelService;
public function bindTel(UserBindTelRequest $request) public function bindTel(UserBindTelRequest $request)
{ {
@ -37,7 +37,7 @@ class UserController extends BaseController
// 校验验证码 // 校验验证码
$this->verifyCodeService->check($params['user_id'], $params['tel'], $params['verify_code']); $this->verifyCodeService->check($params['user_id'], $params['tel'], $params['verify_code']);
// 绑定 // 绑定
$this->userBindService->makeTel($params['user_id'], $params['tel']);
$this->userBindTelService->do($params['user_id'], $params['tel']);
return $this->success([]); return $this->success([]);
} }

23
app/Service/v3/Implementations/SmsAliService.php → app/Service/v3/Implementations/SmsAliSendService.php

@ -11,9 +11,9 @@ use Exception;
use App\Commons\Log; use App\Commons\Log;
use App\Constants\v3\SmsTemplateCode; use App\Constants\v3\SmsTemplateCode;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\SmsServiceInterface;
use App\Service\v3\Interfaces\SmsSendServiceInterface;
class SmsAliService implements SmsServiceInterface
class SmsAliSendService implements SmsSendServiceInterface
{ {
/** /**
@ -22,7 +22,7 @@ class SmsAliService implements SmsServiceInterface
*/ */
protected $log; protected $log;
public function send($tel, $template, $templateParams)
public function do($tel, $template, $templateParams)
{ {
try { try {
@ -60,10 +60,20 @@ class SmsAliService implements SmsServiceInterface
} }
} }
public function makeVerifyCode($tel, $code)
public function check()
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
public function doVerifyCode($tel, $code)
{ {
$params = ['user_name' => '疯狂的水叔叔', 'market_name' => '验证码', 'money' => $code]; $params = ['user_name' => '疯狂的水叔叔', 'market_name' => '验证码', 'money' => $code];
return $this->send($tel, SmsTemplateCode::ALI_VERIFY_CODE, json_encode($params));
return $this->do($tel, SmsTemplateCode::ALI_VERIFY_CODE, json_encode($params));
} }
public function checkVerifyCode($tel, $code) public function checkVerifyCode($tel, $code)
@ -71,8 +81,9 @@ class SmsAliService implements SmsServiceInterface
// TODO: Implement checkVerifyCode() method. // TODO: Implement checkVerifyCode() method.
} }
public function removeVerifyCode($tel, $code)
public function undoVerifyCode($tel, $code)
{ {
// TODO: Implement removeVerifyCode() method. // TODO: Implement removeVerifyCode() method.
} }
} }

10
app/Service/v3/Implementations/UserBindService.php → app/Service/v3/Implementations/UserBindTelService.php

@ -5,12 +5,12 @@ namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Model\v3\User; use App\Model\v3\User;
use App\Service\v3\Interfaces\UserBindServiceInterface;
use App\Service\v3\Interfaces\UserBindTelServiceInterface;
class UserBindService implements UserBindServiceInterface
class UserBindTelService implements UserBindTelServiceInterface
{ {
public function makeTel($userId, $tel)
public function do($userId, $tel)
{ {
$user = User::find($userId); $user = User::find($userId);
$user->tel = $tel; $user->tel = $tel;
@ -20,13 +20,13 @@ class UserBindService implements UserBindServiceInterface
return true; return true;
} }
public function checkTel($userId)
public function check($userId)
{ {
$user = User::find($userId); $user = User::find($userId);
return $user->tel ? true : false; return $user->tel ? true : false;
} }
public function removeTel($userId)
public function undo($userId)
{ {
$user = User::find($userId); $user = User::find($userId);
$user->tel = ''; $user->tel = '';

12
app/Service/v3/Implementations/VerifyCodeService.php

@ -7,7 +7,7 @@ use App\Constants\v3\SsdbKeys;
use App\Exception\BusinessException; use App\Exception\BusinessException;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Service\v3\Interfaces\HelperServiceInterface; use App\Service\v3\Interfaces\HelperServiceInterface;
use App\Service\v3\Interfaces\SmsServiceInterface;
use App\Service\v3\Interfaces\SmsSendServiceInterface;
use App\Service\v3\Interfaces\VerifyCodeServiceInterface; use App\Service\v3\Interfaces\VerifyCodeServiceInterface;
use App\TaskWorker\SSDBTask; use App\TaskWorker\SSDBTask;
use Hyperf\Utils\ApplicationContext; use Hyperf\Utils\ApplicationContext;
@ -17,7 +17,7 @@ class VerifyCodeService implements VerifyCodeServiceInterface
{ {
/** /**
* @Inject * @Inject
* @var SmsServiceInterface
* @var SmsSendServiceInterface
*/ */
protected $smsService; protected $smsService;
@ -27,7 +27,7 @@ class VerifyCodeService implements VerifyCodeServiceInterface
*/ */
protected $helperService; protected $helperService;
public function make($userId, $tel)
public function do($userId, $tel)
{ {
// 获取验证码 // 获取验证码
$verifyCode = $this->helperService->makeNumCode(6); $verifyCode = $this->helperService->makeNumCode(6);
@ -53,7 +53,7 @@ class VerifyCodeService implements VerifyCodeServiceInterface
} }
// 发送短信 // 发送短信
$smsRes = $this->smsService->makeVerifyCode($tel, $verifyCode);
$smsRes = $this->smsService->doVerifyCode($tel, $verifyCode);
if (!$smsRes) { if (!$smsRes) {
throw new ErrorCodeException(ErrorCode::VERIFY_CODE_ERROR); throw new ErrorCodeException(ErrorCode::VERIFY_CODE_ERROR);
} }
@ -73,12 +73,12 @@ class VerifyCodeService implements VerifyCodeServiceInterface
throw new ErrorCodeException(ErrorCode::INVALID_VERIFY_CODE); throw new ErrorCodeException(ErrorCode::INVALID_VERIFY_CODE);
} }
$this->remove($userId, $tel);
$this->undo($userId, $tel);
return true; return true;
} }
public function remove($userId, $tel)
public function undo($userId, $tel)
{ {
$ssdbClient = ApplicationContext::getContainer()->get(SSDBTask::class); $ssdbClient = ApplicationContext::getContainer()->get(SSDBTask::class);
return $ssdbClient->exec( return $ssdbClient->exec(

13
app/Service/v3/Interfaces/SmsSendServiceInterface.php

@ -0,0 +1,13 @@
<?php
namespace App\Service\v3\Interfaces;
interface SmsSendServiceInterface
{
public function do($tel, $template, $templateParams);
public function check();
public function undo();
public function doVerifyCode($tel, $code);
public function checkVerifyCode($tel, $code);
public function undoVerifyCode($tel, $code);
}

11
app/Service/v3/Interfaces/SmsServiceInterface.php

@ -1,11 +0,0 @@
<?php
namespace App\Service\v3\Interfaces;
interface SmsServiceInterface
{
public function send($tel, $template, $templateParams);
public function makeVerifyCode($tel, $code);
public function checkVerifyCode($tel, $code);
public function removeVerifyCode($tel, $code);
}

10
app/Service/v3/Interfaces/UserBindServiceInterface.php

@ -1,10 +0,0 @@
<?php
namespace App\Service\v3\Interfaces;
interface UserBindServiceInterface
{
public function makeTel($userId, $tel);
public function checkTel($userId);
public function removeTel($userId);
}

10
app/Service/v3/Interfaces/UserBindTelServiceInterface.php

@ -0,0 +1,10 @@
<?php
namespace App\Service\v3\Interfaces;
interface UserBindTelServiceInterface
{
public function do($userId, $tel);
public function check($userId);
public function undo($userId);
}

4
app/Service/v3/Interfaces/VerifyCodeServiceInterface.php

@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces;
interface VerifyCodeServiceInterface interface VerifyCodeServiceInterface
{ {
public function make($userId, $tel);
public function do($userId, $tel);
public function check($userId, $tel, $verifyCode); public function check($userId, $tel, $verifyCode);
public function remove($userId, $tel);
public function undo($userId, $tel);
} }

4
config/autoload/dependencies.php

@ -36,9 +36,9 @@ return [
\App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class, \App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class,
\App\Service\OrderListServiceInterface::class => \App\Service\OrderListService::class, \App\Service\OrderListServiceInterface::class => \App\Service\OrderListService::class,
\App\Service\v3\Interfaces\GoodsServiceInterface::class => \App\Service\v3\Implementations\GoodsService::class, \App\Service\v3\Interfaces\GoodsServiceInterface::class => \App\Service\v3\Implementations\GoodsService::class,
\App\Service\v3\Interfaces\SmsServiceInterface::class => \App\Service\v3\Implementations\SmsAliService::class,
\App\Service\v3\Interfaces\SmsSendServiceInterface::class => \App\Service\v3\Implementations\SmsAliSendService::class,
\App\Service\v3\Interfaces\HelperServiceInterface::class => \App\Service\v3\Implementations\HelperService::class, \App\Service\v3\Interfaces\HelperServiceInterface::class => \App\Service\v3\Implementations\HelperService::class,
\App\Service\v3\Interfaces\VerifyCodeServiceInterface::class => \App\Service\v3\Implementations\VerifyCodeService::class, \App\Service\v3\Interfaces\VerifyCodeServiceInterface::class => \App\Service\v3\Implementations\VerifyCodeService::class,
\App\Service\v3\Interfaces\UserBindServiceInterface::class => \App\Service\v3\Implementations\UserBindService::class,
\App\Service\v3\Interfaces\UserBindTelServiceInterface::class => \App\Service\v3\Implementations\UserBindTelService::class,
\App\Service\v3\Interfaces\OrderServiceInterface::class => \App\Service\v3\Implementations\OrderService::class, \App\Service\v3\Interfaces\OrderServiceInterface::class => \App\Service\v3\Implementations\OrderService::class,
]; ];
Loading…
Cancel
Save