mirror of
https://gitee.com/zongzhige/shopxo.git
synced 2024-12-03 12:29:57 +08:00
微信小程序用户授权优化
This commit is contained in:
parent
484f938d0f
commit
1474fffba7
@ -131,16 +131,26 @@ class User extends Common
|
||||
*/
|
||||
public function WechatUserInfo()
|
||||
{
|
||||
$result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->DecryptData(input('encrypted_data'), input('iv'), input('openid'));
|
||||
// 参数
|
||||
$params = input();
|
||||
|
||||
if(is_array($result))
|
||||
// 先从数据库获取用户信息
|
||||
$user = UserService::UserInfo('weixin_openid', $params['openid']);
|
||||
if(empty($user))
|
||||
{
|
||||
$result['nick_name'] = isset($result['nickName']) ? $result['nickName'] : '';
|
||||
$result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
|
||||
$result['gender'] = empty($result['gender']) ? 0 : ($result['gender'] == 2) ? 1 : 2;
|
||||
$result['openid'] = $result['openId'];
|
||||
$result['referrer']= isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0;
|
||||
return UserService::AuthUserProgram($result, 'weixin_openid');
|
||||
$result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->DecryptData($params['encrypted_data'], $params['iv'], $openid);
|
||||
|
||||
if(is_array($result))
|
||||
{
|
||||
$result['nick_name'] = isset($result['nickName']) ? $result['nickName'] : '';
|
||||
$result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
|
||||
$result['gender'] = empty($result['gender']) ? 0 : ($result['gender'] == 2) ? 1 : 2;
|
||||
$result['openid'] = $result['openId'];
|
||||
$result['referrer']= isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0;
|
||||
return UserService::AuthUserProgram($result, 'weixin_openid');
|
||||
}
|
||||
} else {
|
||||
return DataReturn('授权成功', 0, $user);
|
||||
}
|
||||
return DataReturn(empty($result) ? '获取用户信息失败' : $result, -100);
|
||||
}
|
||||
|
@ -1383,8 +1383,7 @@ class UserService
|
||||
'city' => empty($params['city']) ? '' : $params['city'],
|
||||
'referrer' => isset($params['referrer']) ? intval($params['referrer']) : 0,
|
||||
];
|
||||
$where = [$field=>$params['openid'], 'is_delete_time'=>0];
|
||||
$user = Db::name('User')->where($where)->find();
|
||||
$user = self::UserInfo($field, $params['openid']);
|
||||
if(!empty($user))
|
||||
{
|
||||
$data = $user;
|
||||
@ -1394,6 +1393,21 @@ class UserService
|
||||
return DataReturn('授权成功', 0, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段获取用户信息
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2019-01-25
|
||||
* @desc description
|
||||
* @param [string] $field [字段名称]
|
||||
* @param [string] $value [字段值]
|
||||
*/
|
||||
public static function UserInfo($field, $value)
|
||||
{
|
||||
return Db::name('User')->where([$field=>$value, 'is_delete_time'=>0])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* app用户注册
|
||||
* @author Devil
|
||||
|
Loading…
Reference in New Issue
Block a user