feat: 接口调试

This commit is contained in:
zoujing
2025-07-21 18:08:45 +08:00
parent eef75457c8
commit 8a040896a7
7 changed files with 28 additions and 18 deletions

View File

@@ -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;

View File

@@ -76,7 +76,7 @@
"vueVersion" : "3",
"h5" : {
"router" : {
"base" : "",
"base" : "./",
"mode" : "hash"
},
"devServer" : {

2
node_modules/.package-lock.json generated vendored
View File

@@ -1,5 +1,5 @@
{
"name": "YGTianmuCS",
"name": "YGChatCS",
"lockfileVersion": 3,
"requires": true,
"packages": {

2
package-lock.json generated
View File

@@ -1,5 +1,5 @@
{
"name": "YGTianmuCS",
"name": "YGChatCS",
"lockfileVersion": 3,
"requires": true,
"packages": {

View File

@@ -1,5 +1,5 @@
{
"appid": "wxb71a18420dee6fdc",
"appid": "wx6d8bb61f9480d79f",
"compileType": "miniprogram",
"libVersion": "3.8.10",
"packOptions": {

View File

@@ -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 }

View File

@@ -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)
}
});
});
}