微信小程序获取手机号码适配新的接口,小程序授权登录优化
parent
3a130448f2
commit
07aa996401
|
|
@ -63,14 +63,14 @@ class AppMiniUserService
|
||||||
if(!empty($params['authcode']))
|
if(!empty($params['authcode']))
|
||||||
{
|
{
|
||||||
// 授权
|
// 授权
|
||||||
$result = (new \base\Alipay())->GetAuthSessionKey(self::AppMiniConfig('common_app_mini_alipay_appid'), $params['authcode']);
|
$ret = (new \base\Alipay())->GetAuthSessionKey(self::AppMiniConfig('common_app_mini_alipay_appid'), $params['authcode']);
|
||||||
if($result['status'] == 0)
|
if($ret['code'] == 0)
|
||||||
{
|
{
|
||||||
// 先从数据库获取用户信息
|
// 先从数据库获取用户信息
|
||||||
$user = UserService::AppUserInfoHandle(null, 'alipay_openid', $result['data']['user_id']);
|
$user = UserService::AppUserInfoHandle(null, 'alipay_openid', $ret['data']['user_id']);
|
||||||
if(empty($user))
|
if(empty($user))
|
||||||
{
|
{
|
||||||
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['user_id']]);
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$ret['data']['user_id']]);
|
||||||
} else {
|
} else {
|
||||||
// 用户状态
|
// 用户状态
|
||||||
$ret = UserService::UserStatusCheck('id', $user['id']);
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
||||||
|
|
@ -81,8 +81,6 @@ class AppMiniUserService
|
||||||
$ret = DataReturn('授权登录成功', 0, $user);
|
$ret = DataReturn('授权登录成功', 0, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$ret = DataReturn($result['msg'], -100);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$ret = DataReturn('授权码为空', -1);
|
$ret = DataReturn('授权码为空', -1);
|
||||||
|
|
@ -157,14 +155,14 @@ class AppMiniUserService
|
||||||
public static function WeixinUserAuth($params = [])
|
public static function WeixinUserAuth($params = [])
|
||||||
{
|
{
|
||||||
// 授权
|
// 授权
|
||||||
$result = (new \base\Wechat(self::AppMiniConfig('common_app_mini_weixin_appid'), self::AppMiniConfig('common_app_mini_weixin_appsecret')))->GetAuthSessionKey($params);
|
$ret = (new \base\Wechat(self::AppMiniConfig('common_app_mini_weixin_appid'), self::AppMiniConfig('common_app_mini_weixin_appsecret')))->GetAuthSessionKey($params);
|
||||||
if($result['status'] == 0)
|
if($ret['code'] == 0)
|
||||||
{
|
{
|
||||||
// unionid
|
// unionid
|
||||||
$unionid = empty($result['data']['unionid']) ? '' : $result['data']['unionid'];
|
$unionid = empty($ret['data']['unionid']) ? '' : $ret['data']['unionid'];
|
||||||
|
|
||||||
// 先从数据库获取用户信息
|
// 先从数据库获取用户信息
|
||||||
$user = UserService::AppUserInfoHandle(null, 'weixin_openid', $result['data']['openid']);
|
$user = UserService::AppUserInfoHandle(null, 'weixin_openid', $ret['data']['openid']);
|
||||||
if(empty($user) && !empty($unionid))
|
if(empty($user) && !empty($unionid))
|
||||||
{
|
{
|
||||||
// 根据unionid获取数据
|
// 根据unionid获取数据
|
||||||
|
|
@ -172,12 +170,12 @@ class AppMiniUserService
|
||||||
}
|
}
|
||||||
if(empty($user))
|
if(empty($user))
|
||||||
{
|
{
|
||||||
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid'], 'unionid'=>$unionid]);
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$ret['data']['openid'], 'unionid'=>$unionid]);
|
||||||
} else {
|
} else {
|
||||||
// 如果用户openid为空则绑定到用户下面
|
// 如果用户openid为空则绑定到用户下面
|
||||||
if(empty($user['weixin_openid']))
|
if(empty($user['weixin_openid']))
|
||||||
{
|
{
|
||||||
if(UserService::UserOpenidBind($user['id'], $result['data']['openid'], 'weixin_openid'))
|
if(UserService::UserOpenidBind($user['id'], $ret['data']['openid'], 'weixin_openid'))
|
||||||
{
|
{
|
||||||
// 登录数据更新
|
// 登录数据更新
|
||||||
$user = UserService::AppUserInfoHandle($user['id']);
|
$user = UserService::AppUserInfoHandle($user['id']);
|
||||||
|
|
@ -196,8 +194,6 @@ class AppMiniUserService
|
||||||
$ret = DataReturn('授权登录成功', 0, $user);
|
$ret = DataReturn('授权登录成功', 0, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$ret = DataReturn($result['msg'], -10);
|
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
@ -274,11 +270,11 @@ class AppMiniUserService
|
||||||
'key' => self::AppMiniConfig('common_app_mini_baidu_appkey'),
|
'key' => self::AppMiniConfig('common_app_mini_baidu_appkey'),
|
||||||
'secret' => self::AppMiniConfig('common_app_mini_baidu_appsecret'),
|
'secret' => self::AppMiniConfig('common_app_mini_baidu_appsecret'),
|
||||||
];
|
];
|
||||||
$result = (new \base\Baidu($config))->GetAuthSessionKey($params);
|
$ret = (new \base\Baidu($config))->GetAuthSessionKey($params);
|
||||||
if($result['status'] == 0)
|
if($ret['code'] == 0)
|
||||||
{
|
{
|
||||||
// 先从数据库获取用户信息
|
// 先从数据库获取用户信息
|
||||||
$user = UserService::AppUserInfoHandle(null, 'baidu_openid', $result['data']['openid']);
|
$user = UserService::AppUserInfoHandle(null, 'baidu_openid', $ret['data']['openid']);
|
||||||
if(!empty($user))
|
if(!empty($user))
|
||||||
{
|
{
|
||||||
// 用户状态
|
// 用户状态
|
||||||
|
|
@ -290,10 +286,8 @@ class AppMiniUserService
|
||||||
$ret = DataReturn('授权登录成功', 0, $user);
|
$ret = DataReturn('授权登录成功', 0, $user);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid']]);
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$ret['data']['openid']]);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$ret = DataReturn($result['msg'], -10);
|
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
@ -351,18 +345,18 @@ class AppMiniUserService
|
||||||
'key' => self::AppMiniConfig('common_app_mini_baidu_appkey'),
|
'key' => self::AppMiniConfig('common_app_mini_baidu_appkey'),
|
||||||
'secret' => self::AppMiniConfig('common_app_mini_baidu_appsecret'),
|
'secret' => self::AppMiniConfig('common_app_mini_baidu_appsecret'),
|
||||||
];
|
];
|
||||||
$result = (new \base\Baidu($config))->DecryptData($auth_data['encrypted_data'], $auth_data['iv'], $params['openid']);
|
$ret = (new \base\Baidu($config))->DecryptData($auth_data['encrypted_data'], $auth_data['iv'], $params['openid']);
|
||||||
|
|
||||||
if($result['status'] == 0 && !empty($result['data']))
|
if($ret['code'] == 0 && !empty($ret['data']))
|
||||||
{
|
{
|
||||||
$result['nickname'] = isset($result['data']['nickname']) ? $result['data']['nickname'] : '';
|
$data = [
|
||||||
$result['avatar'] = isset($result['data']['headimgurl']) ? $result['data']['headimgurl'] : '';
|
'nickname' => isset($ret['data']['nickname']) ? $ret['data']['nickname'] : '',
|
||||||
$result['gender'] = empty($result['data']['sex']) ? 0 : (($result['data']['sex'] == 2) ? 1 : 2);
|
'avatar' => isset($ret['data']['headimgurl']) ? $ret['data']['headimgurl'] : '',
|
||||||
$result['openid'] = $result['data']['openid'];
|
'gender' => empty($ret['data']['sex']) ? 0 : (($ret['data']['sex'] == 2) ? 1 : 2),
|
||||||
$result['referrer']= isset($params['referrer']) ? $params['referrer'] : 0;
|
'openid' => $ret['data']['openid'],
|
||||||
$ret = UserService::AuthUserProgram($result, 'baidu_openid');
|
'referrer' => isset($params['referrer']) ? $params['referrer'] : 0,
|
||||||
} else {
|
];
|
||||||
$ret = DataReturn($result['msg'], -1);
|
$ret = UserService::AuthUserProgram($data, 'baidu_openid');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$ret = DataReturn($ret, -1);
|
$ret = DataReturn($ret, -1);
|
||||||
|
|
@ -396,14 +390,14 @@ class AppMiniUserService
|
||||||
'appid' => self::AppMiniConfig('common_app_mini_toutiao_appid'),
|
'appid' => self::AppMiniConfig('common_app_mini_toutiao_appid'),
|
||||||
'secret' => self::AppMiniConfig('common_app_mini_toutiao_appsecret'),
|
'secret' => self::AppMiniConfig('common_app_mini_toutiao_appsecret'),
|
||||||
];
|
];
|
||||||
$result = (new \base\Toutiao($config))->GetAuthSessionKey($params);
|
$ret = (new \base\Toutiao($config))->GetAuthSessionKey($params);
|
||||||
if($result['status'] == 0)
|
if($ret['code'] == 0)
|
||||||
{
|
{
|
||||||
// 先从数据库获取用户信息
|
// 先从数据库获取用户信息
|
||||||
$user = UserService::AppUserInfoHandle(null, 'toutiao_openid', $result['data']['openid']);
|
$user = UserService::AppUserInfoHandle(null, 'toutiao_openid', $ret['data']['openid']);
|
||||||
if(empty($user))
|
if(empty($user))
|
||||||
{
|
{
|
||||||
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid']]);
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$ret['data']['openid']]);
|
||||||
} else {
|
} else {
|
||||||
// 用户状态
|
// 用户状态
|
||||||
$ret = UserService::UserStatusCheck('id', $user['id']);
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
||||||
|
|
@ -414,8 +408,6 @@ class AppMiniUserService
|
||||||
$ret = DataReturn('授权登录成功', 0, $user);
|
$ret = DataReturn('授权登录成功', 0, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$ret = DataReturn($result['msg'], -10);
|
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
@ -487,14 +479,14 @@ class AppMiniUserService
|
||||||
if(!empty($params['authcode']))
|
if(!empty($params['authcode']))
|
||||||
{
|
{
|
||||||
// 授权
|
// 授权
|
||||||
$result = (new \base\QQ(self::AppMiniConfig('common_app_mini_qq_appid'), self::AppMiniConfig('common_app_mini_qq_appsecret')))->GetAuthSessionKey($params['authcode']);
|
$ret = (new \base\QQ(self::AppMiniConfig('common_app_mini_qq_appid'), self::AppMiniConfig('common_app_mini_qq_appsecret')))->GetAuthSessionKey($params['authcode']);
|
||||||
if($result['status'] == 0)
|
if($ret['code'] == 0)
|
||||||
{
|
{
|
||||||
// 先从数据库获取用户信息
|
// 先从数据库获取用户信息
|
||||||
$user = UserService::AppUserInfoHandle(null, 'qq_openid', $result['data']['openid']);
|
$user = UserService::AppUserInfoHandle(null, 'qq_openid', $ret['data']['openid']);
|
||||||
if(empty($user))
|
if(empty($user))
|
||||||
{
|
{
|
||||||
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid']]);
|
$ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$ret['data']['openid']]);
|
||||||
} else {
|
} else {
|
||||||
// 用户状态
|
// 用户状态
|
||||||
$ret = UserService::UserStatusCheck('id', $user['id']);
|
$ret = UserService::UserStatusCheck('id', $user['id']);
|
||||||
|
|
@ -505,8 +497,6 @@ class AppMiniUserService
|
||||||
$ret = DataReturn('授权登录成功', 0, $user);
|
$ret = DataReturn('授权登录成功', 0, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$ret = DataReturn($result['msg'], -10);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$ret = DataReturn('授权码为空', -1);
|
$ret = DataReturn('授权码为空', -1);
|
||||||
|
|
@ -562,18 +552,18 @@ class AppMiniUserService
|
||||||
$ret = ParamsChecked($auth_data, $p);
|
$ret = ParamsChecked($auth_data, $p);
|
||||||
if($ret === true)
|
if($ret === true)
|
||||||
{
|
{
|
||||||
$result = (new \base\QQ(self::AppMiniConfig('common_app_mini_qq_appid'), self::AppMiniConfig('common_app_mini_qq_appsecret')))->DecryptData($auth_data['encrypted_data'], $auth_data['iv'], $params['openid']);
|
$ret = (new \base\QQ(self::AppMiniConfig('common_app_mini_qq_appid'), self::AppMiniConfig('common_app_mini_qq_appsecret')))->DecryptData($auth_data['encrypted_data'], $auth_data['iv'], $params['openid']);
|
||||||
if(is_array($result))
|
if($ret['code'] == 0 && !empty($ret['data']))
|
||||||
{
|
{
|
||||||
$result['nickname'] = isset($result['nickName']) ? $result['nickName'] : '';
|
$data = [
|
||||||
$result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
|
'nickname' => isset($ret['data']['nickName']) ? $ret['data']['nickName'] : '',
|
||||||
$result['gender'] = empty($result['gender']) ? 0 : (($result['gender'] == 2) ? 1 : 2);
|
'avatar' => isset($ret['data']['avatarUrl']) ? $ret['data']['avatarUrl'] : '',
|
||||||
$result['qq_unionid'] = isset($result['unionId']) ? $result['unionId'] : '';
|
'gender' => empty($ret['data']['gender']) ? 0 : (($ret['data']['gender'] == 2) ? 1 : 2),
|
||||||
$result['openid'] = $result['openId'];
|
'qq_unionid'=> isset($ret['data']['unionId']) ? $ret['data']['unionId'] : '',
|
||||||
$result['referrer']= isset($params['referrer']) ? $params['referrer'] : 0;
|
'openid' => $ret['data']['openId'],
|
||||||
$ret = UserService::AuthUserProgram($result, 'qq_openid');
|
'referrer' => isset($params['referrer']) ? $params['referrer'] : 0,
|
||||||
} else {
|
];
|
||||||
$ret = DataReturn(empty($result) ? '获取用户信息失败' : $result, -1);
|
$ret = UserService::AuthUserProgram($data, 'qq_openid');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$ret = DataReturn($ret, -1);
|
$ret = DataReturn($ret, -1);
|
||||||
|
|
@ -610,69 +600,92 @@ class AppMiniUserService
|
||||||
'key_name' => 'openid',
|
'key_name' => 'openid',
|
||||||
'error_msg' => '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);
|
$ret = ParamsChecked($params, $p);
|
||||||
if($ret === true)
|
if($ret !== true)
|
||||||
{
|
{
|
||||||
// 根据不同平台处理数据解密逻辑
|
return DataReturn($ret, -1);
|
||||||
$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 $ret;
|
|
||||||
|
// 根据不同平台处理数据解密逻辑
|
||||||
|
$mobile = '';
|
||||||
|
switch(APPLICATION_CLIENT_TYPE)
|
||||||
|
{
|
||||||
|
// 微信
|
||||||
|
case 'weixin' :
|
||||||
|
// 参数校验
|
||||||
|
$p = [
|
||||||
|
[
|
||||||
|
'checked_type' => 'empty',
|
||||||
|
'key_name' => 'code',
|
||||||
|
'error_msg' => '临时code为空',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$ret = ParamsChecked($params, $p);
|
||||||
|
if($ret !== true)
|
||||||
|
{
|
||||||
|
return DataReturn($ret, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用code换取手机号码
|
||||||
|
$ret = (new \base\Wechat(self::AppMiniConfig('common_app_mini_weixin_appid'), self::AppMiniConfig('common_app_mini_weixin_appsecret')))->GetUserPhoneNumber($params['code']);
|
||||||
|
if($ret['code'] == 0)
|
||||||
|
{
|
||||||
|
$mobile = $ret['data'];
|
||||||
|
} else {
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
// 百度
|
||||||
|
case 'baidu' :
|
||||||
|
// 参数校验
|
||||||
|
$p = [
|
||||||
|
[
|
||||||
|
'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)
|
||||||
|
{
|
||||||
|
return DataReturn($ret, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据解密
|
||||||
|
$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'),
|
||||||
|
];
|
||||||
|
$ret = (new \base\Baidu($config))->DecryptData($params['encrypted_data'], $params['iv'], $params['openid'], 'mobile_bind');
|
||||||
|
if($ret['code'] == 0 && !empty($ret['data']) && !empty($ret['data']['mobile']))
|
||||||
|
{
|
||||||
|
$mobile = $ret['data']['mobile'];
|
||||||
|
} else {
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
// 默认
|
||||||
|
default :
|
||||||
|
return DataReturn(APPLICATION_CLIENT_TYPE.'平台还未开发手机一键登录', -1);
|
||||||
|
}
|
||||||
|
if(empty($mobile))
|
||||||
|
{
|
||||||
|
return DataReturn('手机号码为空', -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户信息处理
|
||||||
|
$params['mobile'] = $mobile;
|
||||||
|
$params['is_onekey_mobile_bind'] = 1;
|
||||||
|
return UserService::AuthUserProgram($params, APPLICATION_CLIENT_TYPE.'_openid');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
@ -36,7 +36,7 @@ class Alipay
|
||||||
{
|
{
|
||||||
if(empty($app_id) || empty($authcode))
|
if(empty($app_id) || empty($authcode))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'参数有误'];
|
return DataReturn('参数有误', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求参数
|
// 请求参数
|
||||||
|
|
@ -66,13 +66,12 @@ class Alipay
|
||||||
// 验证签名正确则存储缓存返回数据
|
// 验证签名正确则存储缓存返回数据
|
||||||
if(!$this->SyncRsaVerify($result, 'alipay_system_oauth_token_response'))
|
if(!$this->SyncRsaVerify($result, 'alipay_system_oauth_token_response'))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'签名验证失败'];
|
return DataReturn('签名验证失败', -1);
|
||||||
}
|
}
|
||||||
|
return DataReturn('授权成功', 0, $result['alipay_system_oauth_token_response']);
|
||||||
return ['status'=>0, 'msg'=>'success', 'data'=>$result['alipay_system_oauth_token_response']];
|
|
||||||
}
|
}
|
||||||
$msg = empty($result['error_response']['sub_msg']) ? '授权失败' : $result['error_response']['sub_msg'];
|
$msg = empty($result['error_response']['sub_msg']) ? '授权失败' : $result['error_response']['sub_msg'];
|
||||||
return ['status'=>-1, 'msg'=>$msg];
|
return DataReturn($msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -60,13 +60,13 @@ class Baidu
|
||||||
$session_data = MyCache($login_key);
|
$session_data = MyCache($login_key);
|
||||||
if(empty($session_data))
|
if(empty($session_data))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'session key不存在'];
|
return DataReturn('session key不存在', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// iv长度
|
// iv长度
|
||||||
if(strlen($iv) != 24)
|
if(strlen($iv) != 24)
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'iv长度错误'];
|
return DataReturn('iv长度错误', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据解密
|
// 数据解密
|
||||||
|
|
@ -80,7 +80,7 @@ class Baidu
|
||||||
} else {
|
} else {
|
||||||
if(!function_exists('mcrypt_module_open'))
|
if(!function_exists('mcrypt_module_open'))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'mcrypt_module_open方法不支持'];
|
return DataReturn('mcrypt_module_open方法不支持', -1);
|
||||||
}
|
}
|
||||||
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, null, MCRYPT_MODE_CBC, null);
|
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, null, MCRYPT_MODE_CBC, null);
|
||||||
mcrypt_generic_init($td, $session_key, $iv);
|
mcrypt_generic_init($td, $session_key, $iv);
|
||||||
|
|
@ -89,7 +89,7 @@ class Baidu
|
||||||
mcrypt_module_close($td);
|
mcrypt_module_close($td);
|
||||||
}
|
}
|
||||||
if ($plaintext == false) {
|
if ($plaintext == false) {
|
||||||
return ['status'=>-1, 'msg'=>'解密失败'];
|
return DataReturn('解密失败', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim pkcs#7 padding
|
// trim pkcs#7 padding
|
||||||
|
|
@ -108,14 +108,13 @@ class Baidu
|
||||||
|
|
||||||
if($app_key_decode != $this->_appkey)
|
if($app_key_decode != $this->_appkey)
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'appkey不匹配'];
|
return DataReturn('appkey不匹配', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 缓存存储
|
// 缓存存储
|
||||||
$data_key = 'baidu_'.$key.'_'.$openid;
|
$data_key = 'baidu_'.$key.'_'.$openid;
|
||||||
MyCache($data_key, $data);
|
MyCache($data_key, $data);
|
||||||
|
return DataReturn('success', 0, $data);
|
||||||
return ['status'=>0, 'data'=>$data];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -131,11 +130,11 @@ class Baidu
|
||||||
{
|
{
|
||||||
if(empty($this->_appkey) || empty($this->_appkey) || empty($this->_appsecret))
|
if(empty($this->_appkey) || empty($this->_appkey) || empty($this->_appsecret))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'请先配置'];
|
return DataReturn('请先配置', -1);
|
||||||
}
|
}
|
||||||
if(empty($params['authcode']))
|
if(empty($params['authcode']))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'授权码有误'];
|
return DataReturn('授权码有误', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
|
|
@ -146,7 +145,7 @@ class Baidu
|
||||||
$result = json_decode($this->HttpRequestPost('https://spapi.baidu.com/oauth/jscode2sessionkey', $data), true);
|
$result = json_decode($this->HttpRequestPost('https://spapi.baidu.com/oauth/jscode2sessionkey', $data), true);
|
||||||
if(empty($result))
|
if(empty($result))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'授权接口调用失败'];
|
return DataReturn('授权接口调用失败', -1);
|
||||||
}
|
}
|
||||||
if(!empty($result['openid']))
|
if(!empty($result['openid']))
|
||||||
{
|
{
|
||||||
|
|
@ -155,9 +154,10 @@ class Baidu
|
||||||
|
|
||||||
// 缓存存储
|
// 缓存存储
|
||||||
MyCache($key, $result);
|
MyCache($key, $result);
|
||||||
return ['status'=>0, 'msg'=>'授权成功', 'data'=>$result];
|
return DataReturn('授权成功', 0, $result);
|
||||||
}
|
}
|
||||||
return ['status'=>-1, 'msg'=>empty($result['error_description']) ? '授权接口异常错误' : $result['error_description']];
|
$msg = empty($result['error_description']) ? '授权接口异常错误' : $result['error_description'];
|
||||||
|
return DataReturn($msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -59,19 +59,19 @@ class QQ
|
||||||
$session_data = MyCache($login_key);
|
$session_data = MyCache($login_key);
|
||||||
if(empty($session_data))
|
if(empty($session_data))
|
||||||
{
|
{
|
||||||
return 'session key不存在';
|
return DataReturn('session key不存在', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// iv长度
|
// iv长度
|
||||||
if(strlen($iv) != 24)
|
if(strlen($iv) != 24)
|
||||||
{
|
{
|
||||||
return 'iv长度错误';
|
return DataReturn('iv长度错误', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加密函数
|
// 加密函数
|
||||||
if(!function_exists('openssl_decrypt'))
|
if(!function_exists('openssl_decrypt'))
|
||||||
{
|
{
|
||||||
return 'openssl不支持';
|
return DataReturn('openssl不支持', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$aes_cipher = base64_decode($encrypted_data);
|
$aes_cipher = base64_decode($encrypted_data);
|
||||||
|
|
@ -79,18 +79,17 @@ class QQ
|
||||||
$data = json_decode($result, true);
|
$data = json_decode($result, true);
|
||||||
if($data == NULL)
|
if($data == NULL)
|
||||||
{
|
{
|
||||||
return '请重试!';
|
return DataReturn('请重试!', -1);
|
||||||
}
|
}
|
||||||
if($data['watermark']['appid'] != $this->_appid)
|
if($data['watermark']['appid'] != $this->_appid)
|
||||||
{
|
{
|
||||||
return 'appid不匹配';
|
return DataReturn('appid不匹配', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 缓存存储
|
// 缓存存储
|
||||||
$data_key = 'qq_user_info_'.$openid;
|
$data_key = 'qq_user_info_'.$openid;
|
||||||
MyCache($data_key, $data);
|
MyCache($data_key, $data);
|
||||||
|
return DataReturn('success', 0, $data);
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,7 +108,7 @@ class QQ
|
||||||
$result = $this->HttpRequestGet($url);
|
$result = $this->HttpRequestGet($url);
|
||||||
if(empty($result))
|
if(empty($result))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'授权接口调用失败'];
|
return DataReturn('授权接口调用失败', -1);
|
||||||
}
|
}
|
||||||
if(!empty($result['openid']))
|
if(!empty($result['openid']))
|
||||||
{
|
{
|
||||||
|
|
@ -118,9 +117,10 @@ class QQ
|
||||||
|
|
||||||
// 缓存存储
|
// 缓存存储
|
||||||
MyCache($key, $result);
|
MyCache($key, $result);
|
||||||
return ['status'=>0, 'msg'=>'授权成功', 'data'=>$result];
|
return DataReturn('授权成功', 0, $result);
|
||||||
}
|
}
|
||||||
return ['status'=>-1, 'msg'=>empty($result['errmsg']) ? '授权接口异常错误' : $result['errmsg']];
|
$msg = empty($result['errmsg']) ? '授权接口异常错误' : $result['errmsg'];
|
||||||
|
return DataReturn($msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -46,21 +46,26 @@ class Toutiao
|
||||||
{
|
{
|
||||||
if(empty($params['authcode']))
|
if(empty($params['authcode']))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'授权码有误'];
|
return DataReturn('授权码有误', -1);
|
||||||
}
|
}
|
||||||
if(empty($this->config['appid']) || empty($this->config['secret']))
|
if(empty($this->config['appid']) || empty($this->config['secret']))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'配置有误'];
|
return DataReturn('配置有误', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取授权
|
// 获取授权
|
||||||
$url = 'https://developer.toutiao.com/api/apps/jscode2session?appid='.$this->config['appid'].'&secret='.$this->config['secret'].'&code='.$params['authcode'];
|
$url = 'https://developer.toutiao.com/api/apps/jscode2session?appid='.$this->config['appid'].'&secret='.$this->config['secret'].'&code='.$params['authcode'];
|
||||||
$result = json_decode(RequestGet($url), true);
|
$result = json_decode(RequestGet($url), true);
|
||||||
if(empty($result) || empty($result['openid']))
|
if(empty($result))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>empty($result['errmsg']) ? '授权接口异常错误' : $result['errmsg']];
|
return DataReturn('授权接口调用失败', -1);
|
||||||
}
|
}
|
||||||
return ['status'=>0, 'msg'=>'授权成功', 'data'=>$result];
|
if(!empty($result['openid']))
|
||||||
|
{
|
||||||
|
return DataReturn('授权成功', 0, $result);
|
||||||
|
}
|
||||||
|
$msg = empty($result['errmsg']) ? '授权接口异常错误' : $result['errmsg'];
|
||||||
|
return DataReturn($msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ class Wechat
|
||||||
$data['lang'] = $params['lang'];
|
$data['lang'] = $params['lang'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $this->HttpRequestPost($url, json_encode($data), false);
|
$res = $this->HttpRequestPost($url, $data, false);
|
||||||
if(!empty($res))
|
if(!empty($res))
|
||||||
{
|
{
|
||||||
if(stripos($res, 'errcode') === false)
|
if(stripos($res, 'errcode') === false)
|
||||||
|
|
@ -146,37 +146,36 @@ class Wechat
|
||||||
$session_data = MyCache($login_key);
|
$session_data = MyCache($login_key);
|
||||||
if(empty($session_data))
|
if(empty($session_data))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'session key不存在'];
|
return DataReturn('session key不存在', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// iv长度
|
// iv长度
|
||||||
if(strlen($iv) != 24)
|
if(strlen($iv) != 24)
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'iv长度错误'];
|
return DataReturn('iv长度错误', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加密函数
|
// 加密函数
|
||||||
if(!function_exists('openssl_decrypt'))
|
if(!function_exists('openssl_decrypt'))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'openssl不支持'];
|
return DataReturn('openssl不支持', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = openssl_decrypt(base64_decode($encrypted_data), "AES-128-CBC", base64_decode($session_data['session_key']), 1, base64_decode($iv));
|
$result = openssl_decrypt(base64_decode($encrypted_data), "AES-128-CBC", base64_decode($session_data['session_key']), 1, base64_decode($iv));
|
||||||
$data = json_decode($result, true);
|
$data = json_decode($result, true);
|
||||||
if($data == NULL)
|
if($data == NULL)
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'请重试!'];
|
return DataReturn('请重试!', -1);
|
||||||
}
|
}
|
||||||
if($data['watermark']['appid'] != $this->_appid)
|
if($data['watermark']['appid'] != $this->_appid)
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'appid不匹配'];
|
return DataReturn('appid不匹配', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 缓存存储
|
// 缓存存储
|
||||||
$data_key = 'wechat_user_info_'.$openid;
|
$data_key = 'wechat_user_info_'.$openid;
|
||||||
MyCache($data_key, $data);
|
MyCache($data_key, $data);
|
||||||
|
return DataReturn('success', 0, $data);
|
||||||
return ['status'=>0, 'data'=>$data];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -192,7 +191,7 @@ class Wechat
|
||||||
{
|
{
|
||||||
if(empty($params['authcode']))
|
if(empty($params['authcode']))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'授权码有误'];
|
return DataReturn('授权码有误', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求获取session_key
|
// 请求获取session_key
|
||||||
|
|
@ -200,7 +199,7 @@ class Wechat
|
||||||
$result = $this->HttpRequestGet($url);
|
$result = $this->HttpRequestGet($url);
|
||||||
if(empty($result))
|
if(empty($result))
|
||||||
{
|
{
|
||||||
return ['status'=>-1, 'msg'=>'授权接口调用失败'];
|
return DataReturn('授权接口调用失败', -1);
|
||||||
}
|
}
|
||||||
if(!empty($result['openid']))
|
if(!empty($result['openid']))
|
||||||
{
|
{
|
||||||
|
|
@ -209,9 +208,10 @@ class Wechat
|
||||||
|
|
||||||
// 缓存存储
|
// 缓存存储
|
||||||
MyCache($key, $result);
|
MyCache($key, $result);
|
||||||
return ['status'=>0, 'msg'=>'授权成功', 'data'=>$result];
|
return DataReturn('授权成功', 0, $result);
|
||||||
}
|
}
|
||||||
return ['status'=>-1, 'msg'=>empty($result['errmsg']) ? '授权接口异常错误' : $result['errmsg']];
|
$msg = empty($result['errmsg']) ? '授权接口异常错误' : $result['errmsg'];
|
||||||
|
return DataReturn($msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -260,7 +260,7 @@ class Wechat
|
||||||
'scene' => $params['scene'],
|
'scene' => $params['scene'],
|
||||||
'width' => empty($params['width']) ? 1000 : intval($params['width']),
|
'width' => empty($params['width']) ? 1000 : intval($params['width']),
|
||||||
];
|
];
|
||||||
$res = $this->HttpRequestPost($url, json_encode($data), false);
|
$res = $this->HttpRequestPost($url, $data, false);
|
||||||
if(!empty($res))
|
if(!empty($res))
|
||||||
{
|
{
|
||||||
if(stripos($res, 'errcode') === false)
|
if(stripos($res, 'errcode') === false)
|
||||||
|
|
@ -275,6 +275,41 @@ class Wechat
|
||||||
return DataReturn($msg, -1);
|
return DataReturn($msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户手机号码
|
||||||
|
* @author Devil
|
||||||
|
* @blog http://gong.gg/
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2022-04-26
|
||||||
|
* @desc description
|
||||||
|
* @param [string] $code [临时code]
|
||||||
|
*/
|
||||||
|
public function GetUserPhoneNumber($code)
|
||||||
|
{
|
||||||
|
// 获取access_token
|
||||||
|
$access_token = $this->GetMiniAccessToken();
|
||||||
|
if($access_token === false)
|
||||||
|
{
|
||||||
|
return DataReturn('access_token获取失败', -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取手机
|
||||||
|
$url = 'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token='.$access_token;
|
||||||
|
$data = [
|
||||||
|
'code' => $code,
|
||||||
|
];
|
||||||
|
$res = $this->HttpRequestPost($url, $data);
|
||||||
|
if(!empty($res))
|
||||||
|
{
|
||||||
|
if(isset($res['errcode']) && $res['errcode'] == 0 && !empty($res['phone_info']))
|
||||||
|
{
|
||||||
|
return DataReturn('success', 0, $res['phone_info']['purePhoneNumber']);
|
||||||
|
}
|
||||||
|
return DataReturn($res['errmsg'].'('.$res['errcode'].')', -1);
|
||||||
|
}
|
||||||
|
return DataReturn('接口请求失败', -1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序获取access_token
|
* 小程序获取access_token
|
||||||
* @author Devil
|
* @author Devil
|
||||||
|
|
@ -457,10 +492,10 @@ class Wechat
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
||||||
curl_setopt($curl, CURLOPT_POST, true);
|
curl_setopt($curl, CURLOPT_POST, true);
|
||||||
|
|
||||||
$res = curl_exec($curl);
|
$res = curl_exec($curl);
|
||||||
|
curl_close($curl);
|
||||||
if($is_parsing === true)
|
if($is_parsing === true)
|
||||||
{
|
{
|
||||||
return json_decode($res, true);
|
return json_decode($res, true);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue