提交 81eb6a5f 编写于 作者: G gongfuxiang

手机一键绑定适配系统用户类型

上级 c3f5f6c0
...@@ -786,76 +786,7 @@ class User extends Common ...@@ -786,76 +786,7 @@ class User extends Common
*/ */
public function OnekeyUserMobileBind() public function OnekeyUserMobileBind()
{ {
// 参数校验 return ApiService::ApiDataReturn(AppMiniUserService::AppMiniOnekeyUserMobileBind($this->data_post));
$p = [
[
'checked_type' => 'empty',
'key_name' => 'openid',
'error_msg' => 'openid为空',
],
[
'checked_type' => 'empty',
'key_name' => 'encrypted_data',
'error_msg' => '解密数据为空',
],
[
'checked_type' => 'empty',
'key_name' => 'iv',
'error_msg' => 'iv为空,请重试',
]
];
$ret = ParamsChecked($this->data_post, $p);
if($ret === true)
{
// 根据不同平台处理数据解密逻辑
$mobile = '';
$error_msg = '';
switch(APPLICATION_CLIENT_TYPE)
{
// 微信
case 'weixin' :
$result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);
if($result['status'] == 0 && !empty($result['data']) && !empty($result['data']['purePhoneNumber']))
{
$mobile = $result['data']['purePhoneNumber'];
} else {
$error_msg = $result['msg'];
}
break;
// 百度
case 'baidu' :
$config = [
'appid' => MyC('common_app_mini_baidu_appid'),
'key' => MyC('common_app_mini_baidu_appkey'),
'secret' => MyC('common_app_mini_baidu_appsecret'),
];
$result = (new \base\Baidu($config))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid'], 'mobile_bind');
if($result['status'] == 0 && !empty($result['data']) && !empty($result['data']['mobile']))
{
$mobile = $result['data']['mobile'];
} else {
$error_msg = $result['msg'];
}
break;
// 默认
default :
$error_msg = APPLICATION_CLIENT_TYPE.'平台还未开发手机一键登录';
}
if(empty($mobile) || !empty($error_msg))
{
$ret = DataReturn(empty($error_msg) ? '数据解密失败' : $error_msg, -1);
} else {
// 用户信息处理
$this->data_post['mobile'] = $mobile;
$this->data_post['is_onekey_mobile_bind'] = 1;
$ret = UserService::AuthUserProgram($this->data_post, APPLICATION_CLIENT_TYPE.'_openid');
}
} else {
$ret = DataReturn($ret, -1);
}
return ApiService::ApiDataReturn($ret);
} }
} }
?> ?>
\ No newline at end of file
...@@ -591,5 +591,88 @@ class AppMiniUserService ...@@ -591,5 +591,88 @@ class AppMiniUserService
} }
return $ret; return $ret;
} }
/**
* 小程序用户手机一键绑定
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2022-04-14
* @desc description
* @param [array] $params [输入参数]
*/
public static function AppMiniOnekeyUserMobileBind($params = [])
{
// 参数校验
$p = [
[
'checked_type' => 'empty',
'key_name' => 'openid',
'error_msg' => 'openid为空',
],
[
'checked_type' => 'empty',
'key_name' => 'encrypted_data',
'error_msg' => '解密数据为空',
],
[
'checked_type' => 'empty',
'key_name' => 'iv',
'error_msg' => 'iv为空,请重试',
]
];
$ret = ParamsChecked($params, $p);
if($ret === true)
{
// 根据不同平台处理数据解密逻辑
$mobile = '';
$error_msg = '';
switch(APPLICATION_CLIENT_TYPE)
{
// 微信
case 'weixin' :
$result = (new \base\Wechat(self::AppMiniConfig('common_app_mini_weixin_appid'), self::AppMiniConfig('common_app_mini_weixin_appsecret')))->DecryptData($params['encrypted_data'], $params['iv'], $params['openid']);
if($result['status'] == 0 && !empty($result['data']) && !empty($result['data']['purePhoneNumber']))
{
$mobile = $result['data']['purePhoneNumber'];
} else {
$error_msg = $result['msg'];
}
break;
// 百度
case 'baidu' :
$config = [
'appid' => self::AppMiniConfig('common_app_mini_baidu_appid'),
'key' => self::AppMiniConfig('common_app_mini_baidu_appkey'),
'secret' => self::AppMiniConfig('common_app_mini_baidu_appsecret'),
];
$result = (new \base\Baidu($config))->DecryptData($params['encrypted_data'], $params['iv'], $params['openid'], 'mobile_bind');
if($result['status'] == 0 && !empty($result['data']) && !empty($result['data']['mobile']))
{
$mobile = $result['data']['mobile'];
} else {
$error_msg = $result['msg'];
}
break;
// 默认
default :
$error_msg = APPLICATION_CLIENT_TYPE.'平台还未开发手机一键登录';
}
if(empty($mobile) || !empty($error_msg))
{
$ret = DataReturn(empty($error_msg) ? '数据解密失败' : $error_msg, -1);
} else {
// 用户信息处理
$params['mobile'] = $mobile;
$params['is_onekey_mobile_bind'] = 1;
$ret = UserService::AuthUserProgram($params, APPLICATION_CLIENT_TYPE.'_openid');
}
} else {
$ret = DataReturn($ret, -1);
}
return ApiService::ApiDataReturn($ret);
}
} }
?> ?>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册