liyinglin 2 years ago
parent 60cfeb8cb0
commit 4c70c15dec

@ -3,11 +3,15 @@
namespace App\Http\Controllers\Customer;
use App\Customer;
use App\Helpers\ResponseCode;
use App\Models\User;
use Carbon\Carbon;
use EasyWeChat\Factory;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Tymon\JWTAuth\Facades\JWTAuth;
class AuthController extends Controller
@ -241,4 +245,38 @@ class AuthController extends Controller
$token = $this->guard()->login($user);
return $this->respondWithToken($token);
}
/**
* @OA\Post(
* path="/customer/mobile",
* tags={"用户端用户相关"},
* summary="V2-通过code获取手机号",
* description="",
* @OA\Parameter(name="code", in="query", @OA\Schema(type="string"), required=true, description="code"),
* @OA\Parameter(name="openid", in="query", @OA\Schema(type="string"), required=true, description="openid"),
* @OA\Response(
* response="200",
* description=""
* )
* )
*/
public function mobile()
{
$code = request('code');
$config = [
'app_id' => $this->appid,
'secret' => $this->appsecret
];
$app = Factory::miniProgram($config);
$result = $app->phone_number->getUserPhoneNumber($code);
$mobile = $result['phone_info']['purePhoneNumber'] ?? '';
$user = $this->authModel->firstOrCreate([
"mobile" => $mobile
]);
$user->openid = $mobile;
$user->save();
$token = $this->guard()->login($user);
return $this->respondWithToken($token);
}
}

@ -113,6 +113,9 @@ Route::group(["namespace" => "Admin", "prefix" => "admin"], function () {
Route::group(["namespace" => "Customer", "prefix" => "customer"], function () {
Route::post('login', 'AuthController@login');
Route::post('get-phone-by-openid', 'AuthController@getPhoneByOpenid');
Route::post('mobile', 'AuthController@mobile');
Route::post('logout', 'AuthController@logout');
Route::post('refresh', 'AuthController@refresh');
Route::post('me', 'AuthController@me');

Loading…
Cancel
Save