You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode;use App\Constants\v3\SsdbKeys;use App\Exception\ErrorCodeException;use App\Model\v3\User;use App\TaskWorker\SSDBTask;use EasyWeChat\Factory;use Hyperf\Guzzle\CoroutineHandler;use Hyperf\Utils\ApplicationContext;
class WxLoginService implements \App\Service\v3\Interfaces\WxLoginServiceInterface{
public function do($code) {
// 微信登录
$config = config('applet'); $app = Factory::miniProgram($config); $app['guzzle_handler'] = CoroutineHandler::class; $result = $app->auth->session($code);
if (isset($result['errcode'])&&$result['errcode'] != 0) { throw new ErrorCodeException(ErrorCode::WXLOGIN_INVALID_CODE); }
// 更新或者插入用户数据
$user = User::query()->firstOrCreate( ['openid' => $result['openid']], ['unionid' => $result['unionid']] )->toArray();
$return = array_merge($user, $result); $kvs = []; foreach ($return as $k => $v) { $kvs[] = $k; $kvs[] = $v; } $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $ssdb->exec('multi_hset', SsdbKeys::USER_INFO.$user['id'], $kvs);
return $user; }
public function check($userId) { // TODO: Implement check() method.
}
public function undo($userId) { // TODO: Implement undo() method.
}}
|