feat: 新增大量服务类图标及相关接口配置

- 新增20+家电维修类图标(电视、空调、冰箱等)
- 新增短信发送、微信手机号登录接口
- 新增服务规格查询接口
- 更新后台配置与菜单结构
- 移除支付插件相关配置
这个提交包含在:
YuanWen
2026-11-03 11:19:24 +08:00
父节点 9ae2b976a8
当前提交 c01e8fc7d9
共有 79 个文件被更改,包括 5934 次插入 和 1921 次删除

查看文件

@@ -109,4 +109,137 @@ class WxLogin
return ['user_id' => $userId, 'is_new' => $isNew];
}
/**
* 获取微信 access_token (带缓存)
*/
public static function getAccessToken()
{
$cached = \think\Cache::get('wechat_access_token');
if ($cached) {
return $cached;
}
$appid = \think\Env::get('wechat.appid');
$secret = \think\Env::get('wechat.secret');
if (!$appid || !$secret) {
return ['error' => '微信配置缺失'];
}
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret;
$ctx = stream_context_create(['http' => ['timeout' => 8, 'ignore_errors' => true]]);
$resp = @file_get_contents($url, false, $ctx);
if ($resp === false) {
return ['error' => '微信服务不可达'];
}
$data = json_decode($resp, true);
if (empty($data['access_token'])) {
return ['error' => isset($data['errmsg']) ? $data['errmsg'] : '获取 access_token 失败', 'errcode' => isset($data['errcode']) ? $data['errcode'] : 0];
}
$token = $data['access_token'];
$expire = isset($data['expires_in']) ? max(60, (int)$data['expires_in'] - 200) : 6000;
\think\Cache::set('wechat_access_token', $token, $expire);
return $token;
}
/**
* 通过手机号快速验证 code 换取用户真实手机号
*/
public static function getPhoneNumber($code)
{
$token = self::getAccessToken();
if (is_array($token) && isset($token['error'])) {
return $token;
}
$url = 'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' . $token;
$body = json_encode(['code' => (string)$code]);
$ctx = stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/json\r\n",
'content' => $body,
'timeout' => 8,
'ignore_errors' => true
]
]);
$resp = @file_get_contents($url, false, $ctx);
if ($resp === false) {
return ['error' => '网络超时,获取手机号失败'];
}
$data = json_decode($resp, true);
if (empty($data) || !isset($data['errcode']) || (int)$data['errcode'] !== 0 || empty($data['phone_info'])) {
$ec = isset($data['errcode']) ? (int)$data['errcode'] : -1;
$em = isset($data['errmsg']) ? $data['errmsg'] : '换取手机号失败';
if ($ec === 40001 || $ec === 42001) {
\think\Cache::rm('wechat_access_token');
}
return ['error' => $em, 'errcode' => $ec];
}
return $data['phone_info'];
}
/**
* 按手机号结合 openid 注册或登录(幂等合并)
*/
public static function provisionWithMobile($mobile, $openid = '', $unionid = '', $sessionKey = '')
{
$mobile = trim((string)$mobile);
$openid = trim((string)$openid);
$userId = 0;
$isNew = 0;
// 1. 优先按手机号匹配已存在用户
$existUser = Db::name('user')->where('mobile', $mobile)->find();
if ($existUser) {
$userId = (int)$existUser['id'];
}
// 2. 若手机号未查到,但有 openid,检查 user_wechat 是否已有用户
if ($userId === 0 && $openid !== '') {
$bind = Db::name('user_wechat')->where('openid', $openid)->find();
if ($bind && Db::name('user')->where('id', $bind['user_id'])->find()) {
$userId = (int)$bind['user_id'];
Db::name('user')->where('id', $userId)->update(['mobile' => $mobile, 'updatetime' => time()]);
}
}
// 3. 用户完全不存在,则注册新用户
if ($userId === 0) {
$isNew = 1;
$userId = Db::name('user')->insertGetId([
'group_id' => 1,
'username' => 'wx_' . $mobile,
'mobile' => $mobile,
'nickname' => '用户' . substr($mobile, -4),
'avatar' => '',
'status' => 'normal',
'jointime' => time(),
'createtime' => time(),
'updatetime' => time(),
]);
}
// 4. 若有 openid,建立或更新关联
if ($openid !== '') {
$bind = Db::name('user_wechat')->where('openid', $openid)->find();
$bindData = [
'user_id' => $userId,
'openid' => $openid,
'unionid' => (string)$unionid,
'session_key' => (string)$sessionKey,
'updatetime' => time(),
];
if ($bind) {
Db::name('user_wechat')->where('id', $bind['id'])->update($bindData);
} else {
$bindData['createtime'] = time();
Db::name('user_wechat')->insert($bindData);
}
}
return ['user_id' => $userId, 'is_new' => $isNew];
}
}