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\Exception\ErrorCodeException;use App\Model\v3\User;use EasyWeChat\Factory;use Hyperf\Guzzle\CoroutineHandler;
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); }
// 更新或者插入用户数据
return User::query()->firstOrCreate( ['openid' => $result['openid']], ['unionid' => $result['unionid']] ); }
public function check($userId) { // TODO: Implement check() method.
}
public function undo($userId) { // TODO: Implement undo() method.
}}
|