chore: 入库生产基线(2026-10-26 与 shop.douba.top 一致)
- 11 个已跟踪文件的在途改动此前只存在于工作区,生产已在运行 - 补入两个从未入库的文件:InternalController.php(app_03/box_app 内部接口)、 config/internal.php(内部通信 key,值从 .env 读取,不含硬编码密钥) - 逐文件 md5 比对过生产,内容一致 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -60,13 +60,15 @@ abstract class BaseServices
|
||||
* 创建token
|
||||
* @param int $id
|
||||
* @param $type
|
||||
* @param string $pwd
|
||||
* @param array $extras 额外字段,例如 ['phone' => '138...', 'openid' => 'o...']
|
||||
* @return array
|
||||
*/
|
||||
public function createToken(int $id, $type, string $pwd = '')
|
||||
public function createToken(int $id, $type, string $pwd = '', array $extras = [])
|
||||
{
|
||||
/** @var JwtAuth $jwtAuth */
|
||||
$jwtAuth = app()->make(JwtAuth::class);
|
||||
return $jwtAuth->createToken($id, $type, ['auth' => md5($pwd)]);
|
||||
return $jwtAuth->createToken($id, $type, array_merge(['auth' => md5($pwd)], $extras));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,7 @@ class LoginServices extends BaseServices
|
||||
*/
|
||||
public function login($account, $password, $spread_uid)
|
||||
{
|
||||
$user = $this->dao->getOne(['phone' => $account], 'uid,pwd,status');
|
||||
$user = $this->dao->getOne(['phone' => $account], 'uid,pwd,status,phone');
|
||||
if ($user) {
|
||||
if ($user->pwd !== md5((string)$password))
|
||||
throw new ValidateException('账号或密码错误');
|
||||
@@ -65,7 +65,7 @@ class LoginServices extends BaseServices
|
||||
|
||||
$uid = (int)$user['uid'];
|
||||
//更新用户信息
|
||||
$token = $this->createToken($uid, 'api', $user->pwd);
|
||||
$token = $this->createToken($uid, 'api', $user->pwd, ['phone' => $user->phone ?? '']);
|
||||
if ($token) {
|
||||
$this->updateUserInfo(['spread_uid' => $spread_uid], $user);
|
||||
// 用户登录成功事件
|
||||
@@ -268,7 +268,7 @@ class LoginServices extends BaseServices
|
||||
$this->updateUserInfo(['spread_uid' => $spread_uid], $user);
|
||||
|
||||
$uid = (int)$user['uid'];
|
||||
$token = $this->createToken($uid, 'api', $user->pwd);
|
||||
$token = $this->createToken($uid, 'api', $user->pwd, ['phone' => $user->phone ?? '']);
|
||||
if ($token) {
|
||||
// 用户登录成功事件
|
||||
event('user.login', [$uid, app('request')->ip()]);
|
||||
@@ -305,7 +305,7 @@ class LoginServices extends BaseServices
|
||||
throw new ValidateException('修改新用户登录类型出错');
|
||||
}
|
||||
$uid = (int)$switch_user['uid'];
|
||||
$token = $this->createToken($uid, 'api', $switch_user['pwd']);
|
||||
$token = $this->createToken($uid, 'api', $switch_user['pwd'], ['phone' => $switch_user->phone ?? '']);
|
||||
if ($token) {
|
||||
// 用户登录成功事件
|
||||
event('user.login', [$uid, app('request')->ip()]);
|
||||
@@ -336,7 +336,10 @@ class LoginServices extends BaseServices
|
||||
$wechatUser = app()->make(WechatUserServices::class);
|
||||
//更新用户信息
|
||||
$user = $wechatUser->wechatOauthAfter([$openid, $wechatInfo, $spread_uid, $login_type, $userType]);
|
||||
$token = $this->createToken((int)$user['uid'], $userType, $user['pwd']);
|
||||
$token = $this->createToken((int)$user['uid'], $userType, $user['pwd'], [
|
||||
'phone' => $user['phone'] ?? $phone,
|
||||
'openid' => $openid,
|
||||
]);
|
||||
if ($token) {
|
||||
return [
|
||||
'token' => $token['token'],
|
||||
|
||||
@@ -98,7 +98,7 @@ class RoutineServices extends BaseServices
|
||||
$wechatUserServices = app()->make(WechatUserServices::class);
|
||||
//写入用户信息
|
||||
$user = $wechatUserServices->wechatOauthAfter([$openid, $wechatInfo, $spread_uid, $login_type, $userType]);
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'routine', $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +133,7 @@ class RoutineServices extends BaseServices
|
||||
$wechatUserServices = app()->make(WechatUserServices::class);
|
||||
//写入用户信息
|
||||
$user = $wechatUserServices->wechatOauthAfter($createData);
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'routine', $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,15 +289,22 @@ class RoutineServices extends BaseServices
|
||||
* 获取返回信息
|
||||
* @param $user
|
||||
* @param string $userType
|
||||
* @param string $openid
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnInfo($user, string $userType = 'routine')
|
||||
public function getReturnInfo($user, string $userType = 'routine', string $openid = '')
|
||||
{
|
||||
if (!$user || !isset($user['uid']) || !$user['uid']) {
|
||||
throw new ValidateException('获取用户信息失败');
|
||||
}
|
||||
$uid = (int)$user['uid'];
|
||||
$token = $this->createToken($uid, $userType, $user['pwd']);
|
||||
// 查询 unionid(从 wechat_user 表)
|
||||
$unionid = $this->dao->value(['uid' => $uid, 'user_type' => $userType, 'is_del' => 0], 'unionid') ?? '';
|
||||
$token = $this->createToken($uid, $userType, $user["pwd"] ?? "", [
|
||||
"phone" => $user["phone"] ?? "",
|
||||
"openid" => $openid,
|
||||
"unionid" => $unionid,
|
||||
]);
|
||||
if (!$token) {
|
||||
throw new ValidateException('登录失败!');
|
||||
}
|
||||
@@ -347,7 +354,7 @@ class RoutineServices extends BaseServices
|
||||
//更新用户信息
|
||||
$wechatUserServices->wechatUpdata([$user['uid'], $wechatInfo]);
|
||||
}
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, $userType, $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -387,7 +394,7 @@ class RoutineServices extends BaseServices
|
||||
//更新用户信息
|
||||
$wechatUserServices->wechatUpdata([$user['uid'], $wechatInfo]);
|
||||
}
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, $userType, $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +423,13 @@ class RoutineServices extends BaseServices
|
||||
if ($notLogin || $storeUserMobile) {
|
||||
$userInfoKey = md5($openid . '_' . time() . '_routine');
|
||||
CacheService::setTokenBucket($userInfoKey, $createData, 7200);
|
||||
return ['auth_login' => 1, 'key' => $userInfoKey];
|
||||
// notLogin=true 时也透传 openid/unionid,让前端(H5/小程序)能拿到稳定身份标识
|
||||
return [
|
||||
'auth_login' => 1,
|
||||
'key' => $userInfoKey,
|
||||
'openid' => $openid,
|
||||
'unionid' => $routineInfo['unionid'] ?? '',
|
||||
];
|
||||
} else {
|
||||
//写入用户信息
|
||||
$user = $wechatUserServices->wechatOauthAfter($createData);
|
||||
@@ -425,7 +438,7 @@ class RoutineServices extends BaseServices
|
||||
//更新用户信息
|
||||
$wechatUserServices->wechatUpdata([$user['uid'], ['spread_uid' => $spread_uid]]);
|
||||
}
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'routine', $openid);
|
||||
|
||||
}
|
||||
|
||||
@@ -452,7 +465,7 @@ class RoutineServices extends BaseServices
|
||||
$wechatUserServices = app()->make(WechatUserServices::class);
|
||||
//写入用户信息
|
||||
$user = $wechatUserServices->wechatOauthAfter($createData);
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'routine', $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,7 +506,7 @@ class RoutineServices extends BaseServices
|
||||
$wechatUserServices = app()->make(WechatUserServices::class);
|
||||
//写入用户信息
|
||||
$user = $wechatUserServices->wechatOauthAfter([$openid, $wechatInfo, $spread_uid, $login_type, $userType]);
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'routine', $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -116,15 +116,19 @@ class WechatServices extends BaseServices
|
||||
* 获取返回信息
|
||||
* @param $user
|
||||
* @param string $userType
|
||||
* @param string $openid
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnInfo($user, string $userType = 'wechat')
|
||||
public function getReturnInfo($user, string $userType = 'wechat', string $openid = '')
|
||||
{
|
||||
if (!$user || !isset($user['uid']) || !$user['uid']) {
|
||||
throw new ValidateException('获取用户信息失败');
|
||||
}
|
||||
$uid = (int)$user['uid'];
|
||||
$token = $this->createToken($uid, $userType, $user['pwd'] ?? '');
|
||||
$token = $this->createToken($uid, $userType, $user['pwd'] ?? '', [
|
||||
'phone' => $user['phone'] ?? '',
|
||||
'openid' => $openid,
|
||||
]);
|
||||
if (!$token) {
|
||||
throw new ValidateException('登录失败!');
|
||||
}
|
||||
@@ -179,7 +183,7 @@ class WechatServices extends BaseServices
|
||||
} else {
|
||||
$wechatUserServices->wechatUpdata([$user['uid'], $wechatInfo]);
|
||||
}
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'wechat', $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +222,7 @@ class WechatServices extends BaseServices
|
||||
//更新用户信息
|
||||
$wechatUserServices->wechatUpdata([$user['uid'], $wechatInfo]);
|
||||
}
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'wechat', $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +264,7 @@ class WechatServices extends BaseServices
|
||||
//更新用户信息
|
||||
$wechatUserServices->wechatUpdata([$user['uid'], $wechatInfo]);
|
||||
}
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'wechat', $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,7 +336,7 @@ class WechatServices extends BaseServices
|
||||
//更新用户信息
|
||||
$wechatUserServices->wechatUpdata([$user['uid'], ['spread_uid' => $spread_uid]]);
|
||||
}
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, 'wechat', $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -357,7 +361,7 @@ class WechatServices extends BaseServices
|
||||
$wechatUser = app()->make(WechatUserServices::class);
|
||||
//更新用户信息
|
||||
$user = $wechatUser->wechatOauthAfter([$openid, $wechatInfo, $spread_uid, $login_type, $userType]);
|
||||
return $this->getReturnInfo($user);
|
||||
return $this->getReturnInfo($user, $userType, $openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,7 +414,7 @@ class WechatServices extends BaseServices
|
||||
$wechatUser = app()->make(WechatUserServices::class);
|
||||
//更新用户信息
|
||||
$user = $wechatUser->wechatOauthAfter([$openid, $userInfo, $spread_uid, $login_type, $userType]);
|
||||
$token = $this->getReturnInfo($user);
|
||||
$token = $this->getReturnInfo($user, $userType, $openid);
|
||||
$token['isbind'] = false;
|
||||
return $token;
|
||||
}
|
||||
|
||||
@@ -104,6 +104,10 @@ class WorkClientServices extends BaseServices
|
||||
$config = app()->make(WorkConfig::class);
|
||||
$corpId = $config->corpId;
|
||||
if (!$corpId) {
|
||||
Log::info('work client authGetExternalcontact skip (empty corp_id) ' . json_encode([
|
||||
'page' => $page,
|
||||
'cursor_len' => strlen($cursor),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
return true;
|
||||
}
|
||||
/** @var WorkMemberServices $memberService */
|
||||
@@ -111,6 +115,22 @@ class WorkClientServices extends BaseServices
|
||||
$menmberList = $memberService->getDataList(['corp_id' => $corpId], ['userid'], $page, 1);
|
||||
//没有数据就返回成功
|
||||
if (!$menmberList) {
|
||||
$memberCount = 0;
|
||||
try {
|
||||
$memberCount = $memberService->count(['corp_id' => $corpId]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('work client authGetExternalcontact member count error ' . json_encode([
|
||||
'corp_id' => $corpId,
|
||||
'message' => $e->getMessage(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
Log::info('work client authGetExternalcontact done (no member) ' . json_encode([
|
||||
'corp_id' => $corpId,
|
||||
'page' => $page,
|
||||
'member_count' => $memberCount,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -123,18 +143,43 @@ class WorkClientServices extends BaseServices
|
||||
}
|
||||
|
||||
$userids = array_column($menmberList, 'userid');
|
||||
Log::info('work client authGetExternalcontact fetch ' . json_encode([
|
||||
'corp_id' => $corpId,
|
||||
'page' => $page,
|
||||
'cursor_len' => strlen($cursor),
|
||||
'userids_count' => count($userids),
|
||||
'tag_group_count' => count($tagRes['tag_group'] ?? []),
|
||||
'tag_map_count' => count($tagMap),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
try {
|
||||
$response = Work::getBatchClientList($userids, $cursor);
|
||||
$externalContactList = $response['external_contact_list'] ?? [];
|
||||
}catch (\Throwable $e){
|
||||
Log::error('work client authGetExternalcontact batchGet exception ' . json_encode([
|
||||
'corp_id' => $corpId,
|
||||
'page' => $page,
|
||||
'cursor_len' => strlen($cursor),
|
||||
'message' => $e->getMessage(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
WorkClientJob::dispatchDo('authClient', [$page + 1, '']);
|
||||
return true;
|
||||
}
|
||||
|
||||
$stats = [
|
||||
'external_contact_count' => count($externalContactList),
|
||||
'client_insert' => 0,
|
||||
'client_update' => 0,
|
||||
'follow_insert' => 0,
|
||||
'follow_update' => 0,
|
||||
'tag_save' => 0,
|
||||
'missing_client_map' => 0,
|
||||
];
|
||||
$external = [];
|
||||
$followUser = [];//内部人员跟踪
|
||||
$externalUserids = [];//客户信息
|
||||
$this->transaction(function () use ($externalContactList, $corpId, $externalUserids, $followUser, $external, $tagMap) {
|
||||
$followUser = [];
|
||||
$externalUserids = [];
|
||||
$this->transaction(function () use ($externalContactList, $corpId, $tagMap, &$stats, &$externalUserids, &$followUser, &$external) {
|
||||
/** @var WechatUserServices $wechatUserService */
|
||||
$wechatUserService = app()->make(WechatUserServices::class);
|
||||
foreach ($externalContactList as $item) {
|
||||
@@ -196,10 +241,12 @@ class WorkClientServices extends BaseServices
|
||||
if ($this->dao->count(['external_userid' => $externalUserid, 'corp_id' => $corpId])) {
|
||||
unset($externalContact['external_userid']);
|
||||
$this->dao->update(['external_userid' => $externalUserid], $externalContact);
|
||||
$stats['client_update']++;
|
||||
} else {
|
||||
$externalContact['create_time'] = $item['follow_info']['createtime'] ??time();
|
||||
$externalContact['update_time'] = time();
|
||||
$external[] = $externalContact;
|
||||
$stats['client_insert']++;
|
||||
}
|
||||
}
|
||||
if ($external) {
|
||||
@@ -214,6 +261,7 @@ class WorkClientServices extends BaseServices
|
||||
$tagService = app()->make(WorkClientFollowTagsServices::class);
|
||||
foreach ($followUser as $userid => $items) {
|
||||
if(!isset($clientList[$userid])){
|
||||
$stats['missing_client_map']++;
|
||||
continue;
|
||||
}
|
||||
$items['client_id'] = $clientList[$userid];
|
||||
@@ -227,9 +275,11 @@ class WorkClientServices extends BaseServices
|
||||
'add_way' => $items['add_way'],
|
||||
'oper_userid' => $items['oper_userid'],
|
||||
]);
|
||||
$stats['follow_update']++;
|
||||
} else {
|
||||
$res = $followService->save($items);
|
||||
$id = $res->id;
|
||||
$stats['follow_insert']++;
|
||||
}
|
||||
if (!empty($items['tags'])) {
|
||||
$tagService->delete(['follow_id' => $id]);
|
||||
@@ -237,14 +287,32 @@ class WorkClientServices extends BaseServices
|
||||
$tag['follow_id'] = $id;
|
||||
}
|
||||
$tagService->saveAll($items['tags']);
|
||||
$stats['tag_save'] += count($items['tags']);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Log::info('work client authGetExternalcontact processed ' . json_encode([
|
||||
'corp_id' => $corpId,
|
||||
'page' => $page,
|
||||
'cursor_len' => strlen($cursor),
|
||||
'next_cursor_len' => strlen((string)($response['next_cursor'] ?? '')),
|
||||
'stats' => $stats,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
if (isset($response['next_cursor']) && $response['next_cursor']) {
|
||||
Log::info('work client authGetExternalcontact dispatch next_cursor ' . json_encode([
|
||||
'corp_id' => $corpId,
|
||||
'page' => $page,
|
||||
'next_cursor_len' => strlen((string)$response['next_cursor']),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
WorkClientJob::dispatchDo('authClient', [$page, $response['next_cursor']]);
|
||||
} else if (empty($response['next_cursor'])) {
|
||||
Log::info('work client authGetExternalcontact dispatch next_page ' . json_encode([
|
||||
'corp_id' => $corpId,
|
||||
'page' => $page + 1,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
WorkClientJob::dispatchDo('authClient', [$page + 1, '']);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user