Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Feb 2, 2024
0 parents commit dba4e7d
Show file tree
Hide file tree
Showing 299 changed files with 22,844 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
entry/patch.json
10 changes: 10 additions & 0 deletions AppScope/app.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"app": {
"bundleName": "cn.wildfirechat.messenger",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
8 changes: 8 additions & 0 deletions AppScope/resources/base/element/string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "Messenger"
}
]
}
Binary file added AppScope/resources/base/media/app_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"app": {
"signingConfigs": [],
"compileSdkVersion": 9,
"compatibleSdkVersion": 9,
"products": [
{
"name": "default",
"signingConfig": "default",
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
},
{
"name": "marswrapper",
"srcPath": "./marswrapper",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
6 changes: 6 additions & 0 deletions entry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
14 changes: 14 additions & 0 deletions entry/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"apiType": 'stageMode',
"buildOption": {
},
"targets": [
{
"name": "default",
"runtimeOS": "HarmonyOS"
},
{
"name": "ohosTest",
}
]
}
2 changes: 2 additions & 0 deletions entry/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { hapTasks } from '@ohos/hvigor-ohos-plugin';
11 changes: 11 additions & 0 deletions entry/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "entry",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
"marswrapper": "file:../marswrapper"
}
}
91 changes: 91 additions & 0 deletions entry/src/main/ets/api/appServer.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// @ts-nocheck
// 引入包名
import http from '@ohos.net.http';
import data_preferences from '@ohos.data.preferences';
import wfc from 'marswrapper'

class AppServer {
baseUrl = 'https://app.wildfirechat.net'
authToken = ''

requestAuthCode(mobile: string) {
return this._post('/send_code', { mobile })
}

loginWithAuthCode(phone: string, authCode: string) {
let obj = {
'mobile': phone,
'code': authCode,
'platform': 2,
'clientId': wfc.getClientId(),
}
return this._post('/login', obj)
}

_post(path: string, data: string | object): Promise<object> {
return new Promise((resolve, reject) => {
let httpRequest = http.createHttp();
// 用于订阅HTTP响应头,此接口会比request请求先返回。可以根据业务需要订阅此消息
// 从API 8开始,使用on('headersReceive', Callback)替代on('headerReceive', AsyncCallback)。 8+
httpRequest.on('headersReceive', (header) => {
console.info('header: ' + JSON.stringify(header));
// if (header.toString() === 'authToken') {
// this.authToken = header.toString();
// }
});
console.log('request', path, data)
httpRequest.request(
// 填写HTTP请求的URL地址,可以带参数也可以不带参数。URL地址需要开发者自定义。请求的参数可以在extraData中指定
this.baseUrl + path,
{
method: http.RequestMethod.POST, // 可选,默认为http.RequestMethod.GET
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json'
},
// 当使用POST请求时此字段用于传递内容
extraData: data,
expectDataType: http.HttpDataType.OBJECT, // 可选,指定返回数据的类型
usingCache: true, // 可选,默认为true
priority: 1, // 可选,默认为1
connectTimeout: 60000, // 可选,默认为60000ms
readTimeout: 60000, // 可选,默认为60000ms
usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定
}, (err, data) => {
if (!err) {
// data.result为HTTP响应内容,可根据业务需要进行解析
console.info('Result:' + JSON.stringify(data.result));
console.info('code:' + JSON.stringify(data.responseCode));
// data.header为HTTP响应头,可根据业务需要进行解析
console.info('header:' + JSON.stringify(data.header));
console.info('cookies:' + JSON.stringify(data.cookies)); // 8+
// 取消订阅HTTP响应头事件
httpRequest.off('headersReceive');
// 当该请求使用完毕时,调用destroy方法主动销毁
httpRequest.destroy();
console.log('response', data)
if (data.result.code === 0) {
resolve(data.result.result)
} else {
reject(data.result.code)
}
} else {
console.info('error:' + JSON.stringify(err));
// 取消订阅HTTP响应头事件
httpRequest.off('headersReceive');
// 当该请求使用完毕时,调用destroy方法主动销毁。
httpRequest.destroy();
console.error('err', err)
reject(err)
}
}
)
})
}
}

let self = new AppServer();

export default self


Loading

0 comments on commit dba4e7d

Please sign in to comment.