| xqd
@@ -5,26 +5,16 @@ namespace App\Http\Controllers\V1;
|
|
|
use App\Models\Job;
|
|
|
use App\Models\User;
|
|
|
use App\Services\Api\CommonService;
|
|
|
-use App\Services\Api\ErrorMsgServive;
|
|
|
use App\Services\Api\UserService;
|
|
|
use App\Services\JPushService;
|
|
|
use App\Services\SmsServer;
|
|
|
use Cache;
|
|
|
-use EasyWeChat\Factory;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
-use Laravel\Socialite\Facades\Socialite;
|
|
|
-use Mews\Captcha\Captcha;
|
|
|
-use PHPUnit\Util\Exception;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
class AuthController extends Controller
|
|
|
{
|
|
|
- public function __construct()
|
|
|
- {
|
|
|
- $this->wxConfig = ['app_id' => env("WECHAT_MINI_PROGRAM_APPID"), 'secret' => env("WECHAT_MINI_PROGRAM_SECRET"), 'response_type' => 'array'];
|
|
|
- }
|
|
|
//注册
|
|
|
public function register(Request $request)
|
|
|
{
|
| xqd
@@ -83,15 +73,6 @@ class AuthController extends Controller
|
|
|
if (!$user = User::query()->where('account','=',$account)->orWhere('email','=',$account)->first()) {
|
|
|
return $this->error('账号不存在');
|
|
|
}
|
|
|
- // 账号是否禁用
|
|
|
-// if($user->status == 0){
|
|
|
-// return $this->error('账号已被禁用!');
|
|
|
-// }
|
|
|
-// $credentials1 = ['account' => $account, 'password' => $password];
|
|
|
-// if (!auth('api')->attempt($credentials1)) {
|
|
|
-// return $this->error('密码错误!');
|
|
|
-// }
|
|
|
-
|
|
|
$credentials1 = ['account' => $account, 'password' => $password];
|
|
|
$credentials2 = ['email' => $account, 'password' => $password];
|
|
|
if (!auth('api')->attempt($credentials1) && !auth('api')->attempt($credentials2)) {
|
| xqd
@@ -129,86 +110,6 @@ class AuthController extends Controller
|
|
|
return $this->success($data);
|
|
|
}
|
|
|
|
|
|
- //APP第三方授权登录(微信)
|
|
|
- public function authLogin(Request $request)
|
|
|
- {
|
|
|
- try {
|
|
|
- $socialite = Socialite::driver('weixin')->stateless()->user();
|
|
|
- $user = User::query()->where('open_id', $socialite->getId())->first();
|
|
|
- if (!$user) {
|
|
|
- $data['open_id'] = $socialite->getId();
|
|
|
- $data['user'] = [];
|
|
|
- } else {
|
|
|
- $account = $user->mobile ?: $user->email;
|
|
|
- $data = $this->doLogin($account, $request->post('jpush_reg_id', ''));
|
|
|
- }
|
|
|
- } catch (Exception $exception) {
|
|
|
- ErrorMsgServive::write($exception, requst()->url());
|
|
|
- return $this->error('微信授权登录出错~');
|
|
|
- }
|
|
|
- return $this->success($data);
|
|
|
- }
|
|
|
-
|
|
|
- //微信小程序登录(微信)
|
|
|
- public function miniProgram(Request $request)
|
|
|
- {
|
|
|
- try {
|
|
|
- $mini = Factory::miniProgram($this->wxConfig);
|
|
|
- $newMini = $mini->auth->session($request->input('code'));
|
|
|
-
|
|
|
- $iv = $request->input('iv');
|
|
|
- $encryptData = $request->input('encryptData');
|
|
|
- $decryptedData = $mini->encryptor->decryptData($newMini['session_key'], $iv, $encryptData);
|
|
|
- $openId = $decryptedData['openid'];
|
|
|
- $user = User::query()->where('open_id', $openId)->first();
|
|
|
- if (!$user) {
|
|
|
- $data['open_id'] = $openId;
|
|
|
- $data['user'] = [];
|
|
|
- } else {
|
|
|
- $account = $user->mobile ?: $user->email;
|
|
|
- $data = $this->doLogin($account, $request->post('jpush_reg_id', ''));
|
|
|
- }
|
|
|
- } catch (Exception $exception) {
|
|
|
- ErrorMsgServive::write($exception, requst()->url());
|
|
|
- return $this->error('微信授权登录出错~');
|
|
|
- }
|
|
|
- return $this->success($data);
|
|
|
- }
|
|
|
-
|
|
|
- //微信小程序获取手机号
|
|
|
- public function decryptPhone(Request $request)
|
|
|
- {
|
|
|
- $user = auth('api')->user();
|
|
|
- try {
|
|
|
- $mini = Factory::miniProgram($this->wxConfig);
|
|
|
- $newMini = $mini->auth->session($request->input('code'));
|
|
|
-
|
|
|
- $iv = $request->input('iv');
|
|
|
- $encryptData = $request->input('encryptData');
|
|
|
- $decryptedData = $mini->encryptor->decryptData($newMini['session_key'], $iv, $encryptData);
|
|
|
-
|
|
|
- $user = User::query()->where('id', $user->id)->first();
|
|
|
- $user->mobile = $decryptedData['purePhoneNumber'];
|
|
|
- $user->save();
|
|
|
- } catch (\Exception $exception) {
|
|
|
- ErrorMsgServive::write($exception, requst()->url());
|
|
|
- return $this->error('获取手机号出错~');
|
|
|
- }
|
|
|
- return $this->success();
|
|
|
- }
|
|
|
-
|
|
|
- //H5 应用进行微信授权登录
|
|
|
- public function h5Oauth()
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //微信小程序 code
|
|
|
- public function miniCode()
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
//执行登录
|
|
|
public function doLogin($user, $jpush_reg_id = null)
|
|
|
{
|