fix:基础请求url

This commit is contained in:
wangzhongjie 2025-04-14 10:59:37 +08:00
parent 70951df9bb
commit 6e4f0c282b
9 changed files with 52 additions and 37 deletions

View File

@ -4,13 +4,13 @@
{
"name": "default",
"material": {
"certpath": "C:/Users/93218/.ohos/config/openharmony/default_harmony_vehicle_terminal_Ja3OiX9fkBwGKa0NNRbcXszAt35lPCdUakY4mTtjFwU=.cer",
"storePassword": "0000001B8DAD42641E5F7218D3617E25253F6E8B9D3E209D83F6E7D7A50EEA33CC9F3672C35C8893FE7C05",
"certpath": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.cer",
"storePassword": "0000001B69B6F927C1A8A9C2E65B309DCE5BAA4B1498D997D8BE4F04A3E9A739B4C9FADB2811D9CB2EAA93",
"keyAlias": "debugKey",
"keyPassword": "0000001B8689E02F5E83BE0C395F8A4DC367C1B2C222600352DC5D93C9B8251DAA9B059371E119BEA7DFB1",
"profile": "C:/Users/93218/.ohos/config/openharmony/default_harmony_vehicle_terminal_Ja3OiX9fkBwGKa0NNRbcXszAt35lPCdUakY4mTtjFwU=.p7b",
"keyPassword": "0000001BE240E3D5E0916E6FB737EBE3B7C7CED5870FCD2660699C961E1A4EC3969F036EB5EE138DC4B7FD",
"profile": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "C:/Users/93218/.ohos/config/openharmony/default_harmony_vehicle_terminal_Ja3OiX9fkBwGKa0NNRbcXszAt35lPCdUakY4mTtjFwU=.p12"
"storeFile": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.p12"
}
}
],

View File

@ -1,5 +1,5 @@
{
"lockfileVersion": 1,
"lockfileVersion": 2,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {},
"packages": {}

View File

@ -17,9 +17,14 @@ export default class EntryAbility extends UIAbility {
await InitTable()
let fileUtil = new FileUtils(this.context)
const data = await fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt');
console.log("读取配置", data)
if (data !== '' && data !== undefined) {
console.log("配置设置")
const result: EnvironmentConfigurationType = JSON.parse(data)
AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", result)
const host=`http://${result.centerIp}:${result.centerPort}`
console.log("host",host)
AppStorage.setOrCreate<string>("host",host)
}
} catch (e) {
console.error('sql first error', e)

View File

@ -221,6 +221,7 @@ struct Index {
async initParams() {
console.log("test1111")
ObtainUdpBusinessInstance.init();
await GetCarInfo()
CenterUDPBusinessInstance.init();
CenterUDPBusinessInstance.onMsg((data: centerCallBackMsgType) => {
if (data.id == 32) {
@ -228,7 +229,6 @@ struct Index {
}
},)
await GetDeviceInfo(this.context)
await GetCarInfo()
// getTCP()
this.carInfo = AppStorage.get<CarInfoType>('carInfo')!
this.deviceId = this.carInfo.carNo || ""

View File

@ -14,7 +14,6 @@ interface RequestOption {
timeout?: number
}
const base: string = AppStorage.get("host") || "http://127.0.0.1"
function xmlToJSON(target: string): object {
let conv = new convertxml.ConvertXML()
@ -120,9 +119,10 @@ type RequestResult = Object | object | string | CenterCodeResult
export default function Request<T extends RequestResult>(options: RequestOption): Promise<T> {
return new Promise((resolve, reject) => {
const base: string = AppStorage.get<string>("host") || "http://127.0.0.1"
const instance = http.createHttp()
const baseURL = options.host || base
console.log(RequestTag, "基础url:", baseURL)
instance.request(baseURL + options.url, {
method: options.method,
header: {

View File

@ -61,6 +61,8 @@ export default class UdpClient {
bindUdp(): Promise<void> | undefined {
return this.udp?.bind({
address: this.localIp, port: parseInt(this.localIpPort), family: 1
}).then(res=>{
console.log(UDPTag,"udp 绑定成功!",JSON.stringify(res))
})
}
@ -90,6 +92,8 @@ export default class UdpClient {
address: {
address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1
}
}).then(res=>{
console.log(UDPTag,"udp发送成功",JSON.stringify(res))
})
}
@ -109,14 +113,19 @@ export default class UdpClient {
}
async create(udpLocalIp: string, udpLocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) {
console.log(UDPTag,"udp 初始化")
await this.close()
this.localIp = udpLocalIp
this.oppositeIp = udpOppositeIp
this.localIpPort = udpLocalIpPort
this.oppositeIpPort = udpOppositeIpPort
this.udp = socket.constructUDPSocketInstance();
this.bindEvent()
return this.bindUdp()
try{
this.bindUdp()
this.bindEvent()
} catch (e) {
console.log(UDPTag,"udp错误",JSON.stringify(e))
}
}
onMsg(callback: Function) {

View File

@ -124,22 +124,16 @@ class CenterUDPBusiness {
this.udp.offMsg(cb)
}
async init(): Promise<void> {
return new Promise((resolve, reject) => {
try {
let result: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
AppStorage.setOrCreate("host", `http://${result.centerIp}:${result.centerPort}`)
this.udp.create(result.udplocalIp!, '8800', carInfo.udpAddress!, carInfo.messagePort!)
.then(resolve)
.catch(reject)
this.udp.setDealMethod(this.dealMsg)
} catch (e) {
reject(e)
console.error(UDPTag, "初始化中心 udp失败")
}
})
async init() {
try {
let result: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
this.udp.create(result.udplocalIp!, '8800', carInfo.udpAddress!, carInfo.messagePort!)
this.udp.setDealMethod(this.dealMsg)
} catch (e) {
console.error(UDPTag, "初始化中心 udp失败")
}
}
// 关闭所有动作

View File

@ -1,4 +1,4 @@
import { GlobalConfig } from '../../config'
import { GlobalConfig, UDPTag } from '../../config'
import { EnvironmentConfigurationType } from '../../model'
import UdpClient from '../UdpUtils'
@ -100,12 +100,17 @@ class ObtainUdpBusiness {
}
private initThirdGeneration() {
let config: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
this.thirdGenerationMachineUdp = new UdpClient()
this.thirdGenerationMachineUdp.create(config.udplocalIp!, config.udplocalIpPort!, config.udpOppositeIp!,
config.udpOppositeIpPort!)
this.thirdGenerationMachineUdp.setDealMethod(this.dealThirdGenerationMsg)
try {
let config: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
console.log("获取udp设置", JSON.stringify(config))
this.thirdGenerationMachineUdp = new UdpClient()
this.thirdGenerationMachineUdp.create(config.udplocalIp!, config.udplocalIpPort!, config.udpOppositeIp!,
config.udpOppositeIpPort!)
this.thirdGenerationMachineUdp.setDealMethod(this.dealThirdGenerationMsg)
} catch (e) {
console.error(UDPTag, "三代机 udp失败")
}
}
private dealSecondaryBoardMsg() {

View File

@ -1,5 +1,5 @@
{
"lockfileVersion": 1,
"lockfileVersion": 2,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19",
@ -8,11 +8,13 @@
"packages": {
"@ohos/hypium@1.0.19": {
"resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har",
"integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ=="
"integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==",
"registryType": "ohpm"
},
"@ohos/crypto-js@2.0.3": {
"resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/crypto-js/-/crypto-js-2.0.3.har",
"integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ=="
"integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ==",
"registryType": "ohpm"
}
}
}