代码优化

This commit is contained in:
Billy 2025-10-20 11:07:55 +08:00
parent 4d47e50e96
commit 644e916648

View File

@ -89,14 +89,13 @@ class Ccblife extends Common
// 获取建行用户信息(直接从解密参数中获取)
$ccbUserId = $decryptedParams['userid'] ?? '';
$mobile = $decryptedParams['mobile'] ?? '';
$openId = $decryptedParams['openid'] ?? '';
if (empty($ccbUserId)) {
$this->error('用户信息获取失败');
}
// 处理用户登录/注册
$userInfo = $this->processUserLogin($ccbUserId, $mobile, $openId, $decryptedParams);
$userInfo = $this->processUserLogin($ccbUserId, $mobile, $decryptedParams);
// 生成商城Token
$this->auth->direct($userInfo['user_id']);
@ -105,17 +104,13 @@ class Ccblife extends Common
// 构建跳转URL
$redirectUrl = $decryptedParams['redirect_url'] ?? '/pages/index/index';
$this->success('登录成功', [
$this->success(__('Logged in successful'), [
'token' => $token,
'user_info' => $userInfo,
'redirect_url' => $redirectUrl
]);
} catch (\Exception $e) {
Log::error('建行生活登录失败: ' . $e->getMessage());
Log::error('错误文件: ' . $e->getFile());
Log::error('错误行号: ' . $e->getLine());
Log::error('错误堆栈: ' . $e->getTraceAsString());
$this->error($e->getMessage());
}
}
@ -169,11 +164,10 @@ class Ccblife extends Common
*
* @param string $ccbUserId 建行用户ID
* @param string $mobile 手机号
* @param string $openId OpenID
* @param array $params 其他参数(包含 Usr_Name 等建行返回的数据)
* @return array 用户信息
*/
private function processUserLogin($ccbUserId, $mobile, $openId, $params)
private function processUserLogin($ccbUserId, $mobile, $params)
{
Db::startTrans();
try {
@ -254,11 +248,11 @@ class Ccblife extends Common
'updatetime' => time()
];
Log::info('创建建行新用户', [
Log::info('创建建行新用户: ' . json_encode([
'ccb_user_id' => $ccbUserId,
'mobile' => $mobile,
'nickname' => $userName
]);
], JSON_UNESCAPED_UNICODE));
$userId = Db::name('user')->insertGetId($userData);
if (!$userId) {
@ -271,11 +265,11 @@ class Ccblife extends Common
Db::commit();
Log::info('建行用户登录处理成功', [
Log::info('建行用户登录处理成功: ' . json_encode([
'user_id' => $user['id'],
'ccb_user_id' => $ccbUserId,
'is_new' => $isNew
]);
], JSON_UNESCAPED_UNICODE));
return [
'user_id' => $user['id'],
@ -288,11 +282,11 @@ class Ccblife extends Common
} catch (\Exception $e) {
Db::rollback();
Log::error('建行用户登录处理失败', [
Log::error('建行用户登录处理失败: ' . json_encode([
'error' => $e->getMessage(),
'ccb_user_id' => $ccbUserId,
'trace' => $e->getTraceAsString()
]);
], JSON_UNESCAPED_UNICODE));
throw $e;
}
}
@ -326,11 +320,11 @@ class Ccblife extends Common
$this->error('配置错误private_key 为空');
}
Log::info('解密建行参数', [
Log::info('解密建行参数: ' . json_encode([
'ccbParamSJ_length' => strlen($ccbParamSJ),
'service_id' => $config['service_id'],
'private_key_length' => strlen($config['private_key'])
]);
], JSON_UNESCAPED_UNICODE));
// 解密参数(使用服务方私钥)
$decryptedParams = CcbUrlDecrypt::decrypt($ccbParamSJ, $config['private_key']);
@ -353,10 +347,10 @@ class Ccblife extends Common
$this->success('解密成功', $decryptedParams);
} catch (\Exception $e) {
Log::error('建行参数解密失败', [
Log::error('建行参数解密失败: ' . json_encode([
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
], JSON_UNESCAPED_UNICODE));
$this->error('解密失败: ' . $e->getMessage());
}
}