小程序绑定手机号

This commit is contained in:
吴昊天 2023-02-24 14:34:52 +08:00
parent 975c8f43a5
commit 7d1fc27023
5 changed files with 64 additions and 4 deletions

View File

@ -37,7 +37,12 @@ class AuthController
/**
* 小程序授权登录
* @param Request $request
* @return mixed
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @author 吴汐
* @email 442384644@qq.com
* @date 2023/02/24
*/
public function mp_auth(Request $request)
{

View File

@ -79,6 +79,23 @@ class AuthController
return app('json')->fail(410019);
}
/**
* 小程序绑定手机号
* @param string $code
* @param string $iv
* @param string $encryptedData
* @return \think\Response
* @author 吴汐
* @email 442384644@qq.com
* @date 2023/02/24
*/
public function bindingPhone($code = '', $iv = '', $encryptedData = '')
{
if (!$code || !$iv || !$encryptedData) return app('json')->fail(100100);
$this->services->bindingPhone($code, $iv, $encryptedData);
return app('json')->success(410016);
}
/** 以下方法该版本暂未使用 */
/**
* 小程序授权登录

View File

@ -35,7 +35,9 @@ Route::group('v2', function () {
//是否强制绑定手机号
Route::get('bind_status', 'v2.PublicController/bindPhoneStatus');
//小程序授权绑定手机号
Route::post('auth_bindind_phone', 'v2.wechat.AuthController/authBindingPhone');
Route::post('auth_bindind_phone', 'v2.wechat.AuthController/bindingPhone');
//小程序授权后绑定手机号
Route::post('routine/binding_phone', 'v2.wechat.AuthController/authBindingPhone');
//小程序手机号登录直接绑定
Route::post('phone_silence_auth', 'v2.wechat.AuthController/silenceAuthBindingPhone');
//微信手机号登录直接绑定

View File

@ -461,6 +461,34 @@ class RoutineServices extends BaseServices
throw new ApiException(410019);
}
/**
* @param $code
* @param $iv
* @param $encryptedData
* @return bool
* @author 吴汐
* @email 442384644@qq.com
* @date 2023/02/24
*/
public function bindingPhone($code, $iv, $encryptedData)
{
[$userInfoCong, $userInfo] = app()->make(OAuth::class, ['mini_program'])->oauth($code, [
'iv' => $iv,
'encryptedData' => $encryptedData
]);
if (!$userInfo || !isset($userInfo['purePhoneNumber'])) {
throw new ApiException(410079);
}
$uid = app()->make(WechatUserServices::class)->openidTouid($userInfoCong['openid']);
$userServices = app()->make(UserServices::class);
if ($userServices->count(['phone|account' => $userInfo['purePhoneNumber']])) {
throw new ApiException(410028);
}
$res = app()->make(UserServices::class)->update(['id' => $uid], ['phone' => $userInfo['purePhoneNumber']]);
if ($res) return true;
throw new ApiException(410017);
}
/**
* 更新用户信息

View File

@ -198,6 +198,10 @@ class WechatUserServices extends BaseServices
* 授权后获取用户信息
* @param $openid
* @param $user_type
* @return array|\think\Model|null
* @author 吴汐
* @email 442384644@qq.com
* @date 2023/02/24
*/
public function getAuthUserInfo($openid, $user_type)
{
@ -256,10 +260,14 @@ class WechatUserServices extends BaseServices
/**
* 微信授权成功后
* @param $event
* @param array $data
* @return array|mixed|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author 吴汐
* @email 442384644@qq.com
* @date 2023/02/24
*/
public function wechatOauthAfter(array $data)
{