import service from "./axios";
import Store from '../store'
import md5 from "md5-ts";
import { HttpResponse } from "@/@types";
const request = (cmd:string,msg:any): Promise<HttpResponse>=>{
	msg = msg??{}
	let token = "";
	let key = "";
	let timestamp = (new Date()).valueOf();
	if (localStorage.vuex && JSON.parse(localStorage.vuex).user?.token) {
		token = Store.state.user?.token?.access_token
		key = Store.state.user?.secretKey
	}
	var encodeMsg = encodeURIComponent(JSON.stringify(msg)).toLowerCase();
	var md5Str = md5(`cmd=${cmd}&msg=${encodeMsg}&timestamp=${timestamp}&token=${token}&key=${key}`);
	var postData = {
		"msg": msg,
		"cmd": cmd,
		"timestamp": timestamp,
		"token": token,
		"sign": md5Str,
		"languageId": 1
	}
    return service.post('', postData)
}

export default request;