登录和接口请求
This commit is contained in:
@@ -7,6 +7,8 @@ import cryptoFramework from '@ohos.security.cryptoFramework';
|
||||
import util from '@ohos.util';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { rcp } from '@kit.RemoteCommunicationKit';
|
||||
import { HashMap } from '@kit.ArkTS';
|
||||
import { http } from '@kit.NetworkKit';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
@@ -275,33 +277,71 @@ async function decryptString(str:string) {
|
||||
// B2e%2B96mEodDQ5EIsmcpfh6cJbH7WhjSkXrIz8JtGf2gREqwSckolodE2%2FdNTTssxvwLTAltHlphKiSYWT91IpBUkt30diwj0VF1elbS193JwyOF4AU%2FhJ%2FRYQtxUHrB%2BlRo65QEhktb7z79lsRuJwUKISPEbTkrCVzRx9QDGcihdsOe44ABgLH%2BmyFhgEsMC
|
||||
// B2e+96mEodDQ5EIsmcpfh6cJbH7WhjSkXrIz8JtGf2gREqwSckolodE2/dNTTssxvwLTAltHlphKiSYWT91IpBUkt30diwj0VF1elbS193JwyOF4AU/hJ/RYQtxUHrB+lRo65QEhktb7z79lsRuJwUKISPEbTkrCVzRx9QDGcihdsOe44ABgLH+myFhgEsMC
|
||||
async function pushScanPage(str:string) {
|
||||
const liceScanSuccess = `liveScanSuccess}${str}}${authStore.getUser().uuid},${authStore.getUser().realName},${authStore.getUser().photo}`
|
||||
const textEncoder = new util.TextEncoder()
|
||||
const inputData: Uint8Array = textEncoder.encodeInto(liceScanSuccess)
|
||||
const scanData = await AESEncryptionDecryption.aes128Encrypt(inputData,BasicConstant.ExpertAesKey)
|
||||
const base64Data = AESEncryptionDecryption.customBase64Encode(scanData)
|
||||
const encodedString = encodeURIComponent(base64Data)
|
||||
const postContent = new rcp.MultipartForm({
|
||||
'message': encodedString
|
||||
})
|
||||
const session = rcp.createSession()
|
||||
session.post(BasicConstant.sendWebsocketMsg, {
|
||||
data: postContent,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
const liceScanSuccess = `videoScanSuccess}${str}}${authStore.getUser().uuid},${authStore.getUser().realName},${authStore.getUser().photo}`
|
||||
// const textEncoder = new util.TextEncoder()
|
||||
// const inputData: Uint8Array = textEncoder.encodeInto(liceScanSuccess)
|
||||
// const scanData = await AESEncryptionDecryption.aes128Encrypt(inputData,BasicConstant.ExpertAesKey)
|
||||
// const base64Data = AESEncryptionDecryption.customBase64Encode(scanData)
|
||||
// const encodedString = encodeURIComponent(base64Data)
|
||||
// let hashMap: HashMap<string, string> = new HashMap()
|
||||
// hashMap.set('message',this.code)
|
||||
|
||||
const scanData =await AESEncryptionDecryption.aesEncrypt(liceScanSuccess,"deoep09_klodLdAo")
|
||||
const encodedString = encodeURIComponent(scanData)
|
||||
let httpRequest = http.createHttp();
|
||||
let data = "message="+encodedString;
|
||||
httpRequest.request(
|
||||
BasicConstant.sendWebsocketMsg,
|
||||
{
|
||||
method: http.RequestMethod.POST,
|
||||
// Optional, default is http.RequestMethod.GET//Developers can add header fields according to their own business needs
|
||||
header: { 'Content-Type': 'application/x-www-form-urlencoded' }, // This field is used to pass content when using POST requests
|
||||
extraData: data,
|
||||
connectTimeout: 60000, // Optional, default is 60000ms
|
||||
readTimeout: 60000, // Optional, default is 60000ms
|
||||
}, (err, data) => {
|
||||
if (!err) {
|
||||
// Data.read is the HTTP response content, which can be parsed according to business needs
|
||||
console.info('Result:' + JSON.stringify(data.result));
|
||||
console.info('code:' +
|
||||
JSON.stringify(data.responseCode)); // Data.reader is an HTTP response header that can be parsed according to business needs
|
||||
console.info('header:' + JSON.stringify(data.header));
|
||||
console.info('cookies:' +
|
||||
JSON.stringify(data.cookies)); // Starting from API8
|
||||
} else {
|
||||
console.info('error:' + JSON.stringify(err)); // Unsubscribe from HTTP response header events
|
||||
httpRequest.off('headersReceive'); // When the request is exhausted, call the destroy method to actively destroy it.
|
||||
httpRequest.destroy();
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
let json:Record<string,string> = JSON.parse(response+'') as Record<string,string>
|
||||
if(json.code == '1') {
|
||||
router.pushUrl({url:'pages/VideoPage/CustomScanPage'})
|
||||
} else {
|
||||
promptAction.showToast({ message: String(json.message), duration: 1000 })
|
||||
}
|
||||
})
|
||||
.catch((err: BusinessError) => {
|
||||
console.error(`Response err: Code is ${JSON.stringify(err.code)}, message is ${JSON.stringify(err)}`);
|
||||
})
|
||||
|
||||
// const postContent = new rcp.MultipartForm({
|
||||
// 'message': encodedString
|
||||
// })
|
||||
// const postContent: rcp.RequestContent = {
|
||||
// fields: {
|
||||
// 'message': encodedString,
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// const session = rcp.createSession()
|
||||
// session.post(BasicConstant.sendWebsocketMsg, {
|
||||
// data: postContent,
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/x-www-form-urlencoded'
|
||||
// }
|
||||
// })
|
||||
// .then((response) => {
|
||||
// let json:Record<string,string> = JSON.parse(response+'') as Record<string,string>
|
||||
// if(json.code == '1') {
|
||||
// router.pushUrl({url:'pages/VideoPage/CustomScanPage'})
|
||||
// } else {
|
||||
// promptAction.showToast({ message: String(json.message), duration: 1000 })
|
||||
// }
|
||||
// })
|
||||
// .catch((err: BusinessError) => {
|
||||
// console.error(`Response err: Code is ${JSON.stringify(err.code)}, message is ${JSON.stringify(err)}`);
|
||||
// })
|
||||
// hdHttp.post<string>(BasicConstant.sendWebsocketMsg, {
|
||||
// "message":base64Data
|
||||
// } as Record<string,string>).then(async (res: HdResponse<string>) => {
|
||||
@@ -319,3 +359,4 @@ async function pushScanPage(str:string) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user