From 8a040896a7cf79ec846ce6c0507c2cea08037f2a Mon Sep 17 00:00:00 2001 From: zoujing Date: Mon, 21 Jul 2025 18:08:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/LoginManager.js | 10 ++++++---- manifest.json | 2 +- node_modules/.package-lock.json | 2 +- package-lock.json | 2 +- project.config.json | 2 +- request/api/LoginApi.js | 4 +--- request/base/request.js | 24 +++++++++++++++++------- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/manager/LoginManager.js b/manager/LoginManager.js index 0cb64d6..32d9f6c 100644 --- a/manager/LoginManager.js +++ b/manager/LoginManager.js @@ -4,13 +4,15 @@ import { getWeChatAuthCode } from "./AuthManager"; export async function loginAuth() { try { - const openIdCode = '0f1XVM100D5JCU1BP6400WQQFD2XVM1T'// await getWeChatAuthCode(); + const openIdCode = 'brother7'// await getWeChatAuthCode(); console.log('获取到的微信授权code:', openIdCode); const response = await login({ - openIdCode, - grant_type: 'wechat', + openIdCode: [openIdCode], + grant_type: 'password', scope: 'server', - clientId: '1' + //clientId: '1', + username: 'admin', + password: 'YehdBPev' }); if (response.success) { return response.data; diff --git a/manifest.json b/manifest.json index 64975c0..3eff0c7 100644 --- a/manifest.json +++ b/manifest.json @@ -76,7 +76,7 @@ "vueVersion" : "3", "h5" : { "router" : { - "base" : "", + "base" : "./", "mode" : "hash" }, "devServer" : { diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index ae811ec..967ecf1 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1,5 +1,5 @@ { - "name": "YGTianmuCS", + "name": "YGChatCS", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package-lock.json b/package-lock.json index 1b1222d..e3aa27d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "YGTianmuCS", + "name": "YGChatCS", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/project.config.json b/project.config.json index 5ced6dc..03ad7db 100644 --- a/project.config.json +++ b/project.config.json @@ -1,5 +1,5 @@ { - "appid": "wxb71a18420dee6fdc", + "appid": "wx6d8bb61f9480d79f", "compileType": "miniprogram", "libVersion": "3.8.10", "packOptions": { diff --git a/request/api/LoginApi.js b/request/api/LoginApi.js index 58bd352..2e3446c 100644 --- a/request/api/LoginApi.js +++ b/request/api/LoginApi.js @@ -1,9 +1,7 @@ import request from "../base/request"; function login(args) { - return request.post('/auth/oauth2/token', args, { - noToken: true, - }); + return request.post('/auth/oauth2/token', args); } export { login } \ No newline at end of file diff --git a/request/base/request.js b/request/base/request.js index 2ef7b58..b1b26ce 100644 --- a/request/base/request.js +++ b/request/base/request.js @@ -2,7 +2,7 @@ import { BASE_URL } from "../../constant/base"; const defaultConfig = { header: { - Authorization: '', // 可在此动态设置 token + Authorization: 'Basic Y3VzdG9tOmN1c3RvbQ==', // 可在此动态设置 token 'Content-Type': 'application/x-www-form-urlencoded' }, }; @@ -21,24 +21,34 @@ function request(url, args = {}, method = 'POST', customConfig = {}) { // 判断是否需要 token if (customConfig.noToken) { delete header.Authorization; - } else if (token) { - header.Authorization = `Basic ${token}`; } else { - delete header.Authorization; - } + if (token) { + header.Authorization = `Basic ${token}`; + } + } const config = { ...defaultConfig, ...customConfig, header }; + console.log("请求接口:" + url) + console.log("请求头:" + JSON.stringify(config)) + console.log("请求参数:" + JSON.stringify(args)) + return new Promise((resolve, reject) => { uni.request({ url, data: args, method, ...config, - success: (res) => resolve(res.data), - fail: (err) => reject(err) + success: (res) => { + console.log("请求响应:" + JSON.stringify(res)) + resolve(res.data) + }, + fail: (err) => { + console.error("请求失败:", err); + reject(err) + } }); }); }