mall_client/zyhs_app_java/zyhs3_uniapp/common/http/tim.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2026-03-13 07:50:35 +00:00
import config from '@/TIM/config.js'
import { genTestUserSig } from '@/debug/GenerateTestUserSig.js';
import req from './request.js'
const ApiURL = config.ApiURL;
const sdkappid = config.AppID;
const identifier = config.identifier;
const usersig = genTestUserSig(identifier).userSig;
/* 创建群聊 */
export const create_group = (GroupId)=> {
return http('post',`group_open_http_svc/create_group?sdkappid=${sdkappid}&identifier=${identifier}&usersig=${usersig}&random=${random()}&contenttype=json`,{
})
}
/* 解散群组 */
export const destroy_group = (GroupId)=> {
return http('post',`group_open_http_svc/destroy_group?sdkappid=${sdkappid}&identifier=${identifier}&usersig=${usersig}&random=${random()}&contenttype=json`,{GroupId})
}
/* 随机数函数 */
function random(min = 0, max = 999999999) {
return Math.floor(Math.random() * (max - min)) + min;
}
/* 封装自定义请求 */
function http(method, url, data){
let _req = new req({
baseUrl:ApiURL,header:{"Content-Type": "application/json;charset=UTF-8"},
},reqInterceptor,resInterceptor)
return _req.request({method,url,data})
}
/* 请求前拦截 */
const reqInterceptor = async (options) => {
return options
}
// 调用成功回调
const resInterceptor = (response, conf = {}) => {
if(response.statusCode==200){
return response.data;
}else{
console.log(response);
}
}