plutosdk 0.0.8-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -0
- package/dist/pluto-sdk.js +2 -0
- package/lib/App.d.ts +24 -0
- package/lib/App.js +61 -0
- package/lib/components/BlurMask/index.d.ts +10 -0
- package/lib/components/BlurMask/index.js +14 -0
- package/lib/components/CatAni/index.d.ts +30 -0
- package/lib/components/CatAni/index.js +243 -0
- package/lib/components/GameInfo/index.d.ts +10 -0
- package/lib/components/GameInfo/index.js +17 -0
- package/lib/components/Index/index.d.ts +10 -0
- package/lib/components/Index/index.js +15 -0
- package/lib/components/Login/index.d.ts +10 -0
- package/lib/components/Login/index.js +28 -0
- package/lib/components/NetLoading/index.d.ts +7 -0
- package/lib/components/NetLoading/index.js +12 -0
- package/lib/components/PayButton/index.d.ts +16 -0
- package/lib/components/PayButton/index.js +18 -0
- package/lib/components/PlayButton/index.d.ts +29 -0
- package/lib/components/PlayButton/index.js +56 -0
- package/lib/components/Purchase/index.d.ts +61 -0
- package/lib/components/Purchase/index.js +183 -0
- package/lib/components/ShareButton/index.d.ts +14 -0
- package/lib/components/ShareButton/index.js +29 -0
- package/lib/components/StrokeText/index.d.ts +18 -0
- package/lib/components/StrokeText/index.js +32 -0
- package/lib/components/WalletInfo/index.d.ts +36 -0
- package/lib/components/WalletInfo/index.js +107 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/interface.d.ts +42 -0
- package/lib/interface.js +1 -0
- package/lib/main.d.ts +5 -0
- package/lib/main.js +19 -0
- package/lib/sdk.d.ts +46 -0
- package/lib/sdk.js +306 -0
- package/lib/utils/Api.d.ts +32 -0
- package/lib/utils/Api.js +122 -0
- package/lib/utils/Net.d.ts +33 -0
- package/lib/utils/Net.js +94 -0
- package/lib/utils/Platform.d.ts +63 -0
- package/lib/utils/Platform.js +142 -0
- package/lib/utils/User.d.ts +62 -0
- package/lib/utils/User.js +78 -0
- package/lib/utils/Utils.d.ts +10 -0
- package/lib/utils/Utils.js +72 -0
- package/lib/utils/WalletManager.d.ts +52 -0
- package/lib/utils/WalletManager.js +236 -0
- package/lib/utils/config.d.ts +25 -0
- package/lib/utils/config.js +72 -0
- package/lib/utils/constant.d.ts +38 -0
- package/lib/utils/constant.js +43 -0
- package/package.json +51 -0
package/lib/sdk.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import PubSub from 'pubsub-js';
|
|
2
|
+
import { CODE, EVENT_GAME_INFO_LOADED, EVENT_GAME_READY, EVENT_PURCHASE_COMPLETED, EVENT_SWITCH_PAGE, PAGE_ID } from './utils/constant';
|
|
3
|
+
import { clipboard } from './utils/Utils';
|
|
4
|
+
import Config from './utils/Config';
|
|
5
|
+
import walletManager from './utils/WalletManager';
|
|
6
|
+
import net from './utils/Net';
|
|
7
|
+
import user from './utils/User';
|
|
8
|
+
import platform from './utils/Platform';
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export const init = () => {
|
|
13
|
+
return sdk.init();
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export const login = () => {
|
|
19
|
+
return sdk.login();
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
export const ready = () => {
|
|
25
|
+
sdk.ready();
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
export const share = () => {
|
|
31
|
+
sdk.share();
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export const getShareLink = () => {
|
|
37
|
+
return sdk.getShareLink();
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
export const copyShareLink = () => {
|
|
43
|
+
return sdk.copyShareLink();
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param name
|
|
48
|
+
* @param orderId
|
|
49
|
+
* @param amount
|
|
50
|
+
* @param customData
|
|
51
|
+
* @param callback
|
|
52
|
+
*/
|
|
53
|
+
export const purchase = (productId, name, orderId, amount, customData = '', callback = null) => {
|
|
54
|
+
return sdk.purchase(productId, name, orderId, amount, customData, callback);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
export const connectWallet = () => {
|
|
60
|
+
return sdk.connectWallet();
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
export const disconnectWallet = () => {
|
|
66
|
+
return sdk.disconnectWallet();
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
export const getWalletConnected = () => {
|
|
72
|
+
return sdk.getWalletConnected();
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
class Sdk {
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
constructor() {
|
|
82
|
+
//
|
|
83
|
+
this._loadingGame = false;
|
|
84
|
+
//
|
|
85
|
+
this._loadGameRetryCount = 0;
|
|
86
|
+
//
|
|
87
|
+
this._initialized = false;
|
|
88
|
+
//
|
|
89
|
+
this._logined = false;
|
|
90
|
+
//
|
|
91
|
+
this._purchaseing = false;
|
|
92
|
+
//
|
|
93
|
+
this._purchaseCallback = null;
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @param _
|
|
97
|
+
* @param status
|
|
98
|
+
*/
|
|
99
|
+
this.onPuchaseCompleted = (_, status) => {
|
|
100
|
+
if (this._purchaseCallback) {
|
|
101
|
+
let obj = {
|
|
102
|
+
success: status,
|
|
103
|
+
productId: user.purchaseData.productId,
|
|
104
|
+
orderId: user.purchaseData.orderId,
|
|
105
|
+
customData: user.purchaseData.customData
|
|
106
|
+
};
|
|
107
|
+
this._purchaseCallback.apply(null, [obj]);
|
|
108
|
+
this._purchaseCallback = null;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
PubSub.subscribe(EVENT_PURCHASE_COMPLETED, this.onPuchaseCompleted);
|
|
112
|
+
Config.init();
|
|
113
|
+
net.init();
|
|
114
|
+
platform.init();
|
|
115
|
+
walletManager.init();
|
|
116
|
+
this.getGameInfo();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
*
|
|
120
|
+
*/
|
|
121
|
+
getGameInfo() {
|
|
122
|
+
if (this._loadingGame) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
//
|
|
126
|
+
this._loadingGame = true;
|
|
127
|
+
this._loadGameRetryCount++;
|
|
128
|
+
platform.reqGameInfo().then(data => {
|
|
129
|
+
this._loadingGame = false;
|
|
130
|
+
PubSub.publish(EVENT_SWITCH_PAGE, PAGE_ID.Login);
|
|
131
|
+
PubSub.publish(EVENT_GAME_INFO_LOADED, true);
|
|
132
|
+
}).catch((error) => {
|
|
133
|
+
this._loadingGame = false;
|
|
134
|
+
PubSub.publish(EVENT_GAME_INFO_LOADED, false);
|
|
135
|
+
console.log(error.message);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
*/
|
|
141
|
+
init() {
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
//
|
|
144
|
+
if (user.gameInfo) {
|
|
145
|
+
this._initialized = true;
|
|
146
|
+
return resolve();
|
|
147
|
+
}
|
|
148
|
+
//
|
|
149
|
+
let loadGame = () => {
|
|
150
|
+
PubSub.subscribeOnce(EVENT_GAME_INFO_LOADED, (_, result) => {
|
|
151
|
+
if (result) {
|
|
152
|
+
this._initialized = true;
|
|
153
|
+
return resolve();
|
|
154
|
+
}
|
|
155
|
+
//
|
|
156
|
+
if (this._loadGameRetryCount < 5) {
|
|
157
|
+
return loadGame();
|
|
158
|
+
}
|
|
159
|
+
//
|
|
160
|
+
reject({
|
|
161
|
+
code: CODE.InitError,
|
|
162
|
+
message: 'load game config error.'
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
this.getGameInfo();
|
|
166
|
+
};
|
|
167
|
+
loadGame();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
*
|
|
172
|
+
*/
|
|
173
|
+
login() {
|
|
174
|
+
if (!this._initialized) {
|
|
175
|
+
return Promise.reject({
|
|
176
|
+
code: CODE.NotInit,
|
|
177
|
+
message: 'pluto sdk not initialize.'
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
//
|
|
181
|
+
if (this._logined) {
|
|
182
|
+
return Promise.reject({
|
|
183
|
+
code: CODE.Logined,
|
|
184
|
+
message: 'pluto sdk already login.'
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
//
|
|
188
|
+
return platform.reqLogin().then(data => {
|
|
189
|
+
this._logined = true;
|
|
190
|
+
return data;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
*
|
|
195
|
+
*/
|
|
196
|
+
ready() {
|
|
197
|
+
if (!this._logined) {
|
|
198
|
+
console.warn('pluto sdk not login!');
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
//
|
|
202
|
+
PubSub.publish(EVENT_GAME_READY, true);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @param productId
|
|
206
|
+
* @param name
|
|
207
|
+
* @param orderId
|
|
208
|
+
* @param amount
|
|
209
|
+
* @param customData
|
|
210
|
+
* @param callback
|
|
211
|
+
*/
|
|
212
|
+
purchase(productId, name, orderId, amount, customData, callback) {
|
|
213
|
+
return new Promise((resolve, reject) => {
|
|
214
|
+
if (!this._logined) {
|
|
215
|
+
console.warn('pluto sdk not login!');
|
|
216
|
+
return reject({
|
|
217
|
+
code: CODE.NotLogin,
|
|
218
|
+
message: 'pluto sdk not login'
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
//
|
|
222
|
+
if (this._purchaseing) {
|
|
223
|
+
console.warn('payment is being processed!');
|
|
224
|
+
return reject({
|
|
225
|
+
code: CODE.Purchaseing,
|
|
226
|
+
message: 'payment is being processed'
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
//
|
|
230
|
+
this._purchaseing = true;
|
|
231
|
+
this._purchaseCallback = callback;
|
|
232
|
+
platform.reqPurchase(productId, name, orderId, amount, customData).then(() => {
|
|
233
|
+
this._purchaseing = false;
|
|
234
|
+
PubSub.publish(EVENT_SWITCH_PAGE, PAGE_ID.Purchase);
|
|
235
|
+
resolve();
|
|
236
|
+
}).catch((error) => {
|
|
237
|
+
this._purchaseing = false;
|
|
238
|
+
console.log(error.message);
|
|
239
|
+
reject(error);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
*/
|
|
246
|
+
share() {
|
|
247
|
+
if (!this._initialized) {
|
|
248
|
+
return console.log('pluto sdk not initialize.');
|
|
249
|
+
}
|
|
250
|
+
console.log('pluto sdk share');
|
|
251
|
+
platform.share(user.gameInfo.describe);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
*
|
|
255
|
+
*/
|
|
256
|
+
getShareLink() {
|
|
257
|
+
if (!this._initialized) {
|
|
258
|
+
console.log('pluto sdk not initialize.');
|
|
259
|
+
return "";
|
|
260
|
+
}
|
|
261
|
+
let link = `https://t.me/${Config.BOT_NAME}/games?startapp=g_${Config.GAME_ID}_${user.plutoId}`;
|
|
262
|
+
return link;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
*
|
|
266
|
+
*/
|
|
267
|
+
copyShareLink() {
|
|
268
|
+
return new Promise((resolve, reject) => {
|
|
269
|
+
if (!this._initialized) {
|
|
270
|
+
return reject({
|
|
271
|
+
code: CODE.NotInit,
|
|
272
|
+
message: 'pluto sdk not initialize.'
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
//
|
|
276
|
+
let link = `https://t.me/${Config.BOT_NAME}/games?startapp=g_${Config.GAME_ID}_${user.plutoId}`;
|
|
277
|
+
clipboard(link).then(() => {
|
|
278
|
+
resolve();
|
|
279
|
+
}).catch(error => {
|
|
280
|
+
reject({
|
|
281
|
+
code: CODE.ClipboardError,
|
|
282
|
+
message: error
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
*
|
|
289
|
+
*/
|
|
290
|
+
connectWallet() {
|
|
291
|
+
return walletManager.connect();
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
*
|
|
295
|
+
*/
|
|
296
|
+
disconnectWallet() {
|
|
297
|
+
return walletManager.disconnect();
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
*
|
|
301
|
+
*/
|
|
302
|
+
getWalletConnected() {
|
|
303
|
+
return walletManager.connected;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const sdk = new Sdk();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*/
|
|
4
|
+
export default class Api {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
private static showLog;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
static gameInfo(): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
static login(): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param amount
|
|
20
|
+
*/
|
|
21
|
+
static priceExchange(amount: number): Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* @param productId
|
|
24
|
+
* @param name
|
|
25
|
+
* @param orderId
|
|
26
|
+
* @param amount
|
|
27
|
+
* @param payType
|
|
28
|
+
* @param currency
|
|
29
|
+
* @param customData
|
|
30
|
+
*/
|
|
31
|
+
static order(productId: string, name: string, orderId: string, amount: number, payType: number, currency: string, customData: string): Promise<any>;
|
|
32
|
+
}
|
package/lib/utils/Api.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import Config from './Config';
|
|
2
|
+
import net from './Net';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export default class Api {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
static showLog(msg) {
|
|
11
|
+
if (Config.TEST_MODE) {
|
|
12
|
+
console.log(msg);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
static gameInfo() {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
let path = `api/pluto/gameinfo/${Config.GAME_ID}`;
|
|
21
|
+
let param = {
|
|
22
|
+
botname: Config.BOT_NAME,
|
|
23
|
+
initdata: Config.INIT_DATA
|
|
24
|
+
};
|
|
25
|
+
net.post(path, param).then(resp => {
|
|
26
|
+
Api.showLog(`gameInfo=>${JSON.stringify(resp)}`);
|
|
27
|
+
if (resp.code != 0) {
|
|
28
|
+
return reject({
|
|
29
|
+
code: resp.code,
|
|
30
|
+
message: resp.message
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
resolve(resp.data);
|
|
34
|
+
}).catch(error => {
|
|
35
|
+
reject(error);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
static login() {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
let path = `api/pluto/login/${Config.GAME_ID}`;
|
|
45
|
+
let param = {
|
|
46
|
+
botname: Config.BOT_NAME,
|
|
47
|
+
initdata: Config.INIT_DATA
|
|
48
|
+
};
|
|
49
|
+
net.post(path, param).then(resp => {
|
|
50
|
+
Api.showLog(`login=>${JSON.stringify(resp)}`);
|
|
51
|
+
if (resp.code != 0) {
|
|
52
|
+
return reject({
|
|
53
|
+
code: resp.code,
|
|
54
|
+
message: resp.message
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
resolve(resp.data);
|
|
58
|
+
}).catch(error => {
|
|
59
|
+
reject(error);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param amount
|
|
66
|
+
*/
|
|
67
|
+
static priceExchange(amount) {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
let path = `api/pluto/priceexchange/${Config.GAME_ID}`;
|
|
70
|
+
let param = {
|
|
71
|
+
amount
|
|
72
|
+
};
|
|
73
|
+
net.post(path, param).then(resp => {
|
|
74
|
+
Api.showLog(`priceExchange=>${JSON.stringify(resp)}`);
|
|
75
|
+
if (resp.code != 0) {
|
|
76
|
+
return reject({
|
|
77
|
+
code: resp.code,
|
|
78
|
+
message: resp.message
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
resolve(resp.data);
|
|
82
|
+
}).catch(error => {
|
|
83
|
+
reject(error);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @param productId
|
|
89
|
+
* @param name
|
|
90
|
+
* @param orderId
|
|
91
|
+
* @param amount
|
|
92
|
+
* @param payType
|
|
93
|
+
* @param currency
|
|
94
|
+
* @param customData
|
|
95
|
+
*/
|
|
96
|
+
static order(productId, name, orderId, amount, payType, currency, customData) {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
let path = `api/pluto/order/${Config.GAME_ID}`;
|
|
99
|
+
let param = {
|
|
100
|
+
productid: productId,
|
|
101
|
+
productname: name,
|
|
102
|
+
orderid: orderId,
|
|
103
|
+
amount: amount,
|
|
104
|
+
paytype: payType,
|
|
105
|
+
currencycode: currency,
|
|
106
|
+
customdata: customData
|
|
107
|
+
};
|
|
108
|
+
net.post(path, param).then(resp => {
|
|
109
|
+
Api.showLog(`order=>${JSON.stringify(resp)}`);
|
|
110
|
+
if (resp.code != 0) {
|
|
111
|
+
return reject({
|
|
112
|
+
code: resp.code,
|
|
113
|
+
message: resp.message
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
resolve(resp.data);
|
|
117
|
+
}).catch(error => {
|
|
118
|
+
reject(error);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*/
|
|
4
|
+
declare class Net {
|
|
5
|
+
private _axios;
|
|
6
|
+
private _baseUrl;
|
|
7
|
+
private _token;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
set token(value: string);
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param baseUrl
|
|
15
|
+
*/
|
|
16
|
+
init(): void;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param url
|
|
20
|
+
* @param params
|
|
21
|
+
* @param isInternal
|
|
22
|
+
*/
|
|
23
|
+
get(url: string, params?: any, isInternal?: boolean): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param url
|
|
27
|
+
* @param data
|
|
28
|
+
* @param isInternal
|
|
29
|
+
*/
|
|
30
|
+
post(url: string, data: any, isInternal?: boolean): Promise<any>;
|
|
31
|
+
}
|
|
32
|
+
declare const _default: Net;
|
|
33
|
+
export default _default;
|
package/lib/utils/Net.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { CODE } from "./constant";
|
|
3
|
+
import Config from "./Config";
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
class Net {
|
|
8
|
+
constructor() {
|
|
9
|
+
//
|
|
10
|
+
this._baseUrl = '';
|
|
11
|
+
//
|
|
12
|
+
this._token = '';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
set token(value) {
|
|
18
|
+
this._token = value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param baseUrl
|
|
23
|
+
*/
|
|
24
|
+
init() {
|
|
25
|
+
this._baseUrl = Config.API_URL;
|
|
26
|
+
this._axios = axios.create({
|
|
27
|
+
timeout: 10000 //超时10s
|
|
28
|
+
});
|
|
29
|
+
//添加响应拦截器
|
|
30
|
+
this._axios.interceptors.response.use(response => {
|
|
31
|
+
//2xx 范围内的状态码都会触发该函数
|
|
32
|
+
return response;
|
|
33
|
+
}, error => {
|
|
34
|
+
//超出 2xx 范围的状态码都会触发该函数
|
|
35
|
+
console.log(error.toJSON());
|
|
36
|
+
return Promise.reject({
|
|
37
|
+
code: CODE.NetError,
|
|
38
|
+
message: error.message
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param url
|
|
45
|
+
* @param params
|
|
46
|
+
* @param isInternal
|
|
47
|
+
*/
|
|
48
|
+
get(url, params = null, isInternal = true) {
|
|
49
|
+
let config = {};
|
|
50
|
+
//
|
|
51
|
+
if (params) {
|
|
52
|
+
config.params = params;
|
|
53
|
+
}
|
|
54
|
+
//
|
|
55
|
+
if (isInternal) {
|
|
56
|
+
url = this._baseUrl + url;
|
|
57
|
+
//
|
|
58
|
+
if (this._token) {
|
|
59
|
+
config.headers = {
|
|
60
|
+
Authorization: `Bearer ${this._token}`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//
|
|
65
|
+
return this._axios.get(url, config).then(response => {
|
|
66
|
+
return response.data;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param url
|
|
72
|
+
* @param data
|
|
73
|
+
* @param isInternal
|
|
74
|
+
*/
|
|
75
|
+
post(url, data, isInternal = true) {
|
|
76
|
+
let config = {};
|
|
77
|
+
//
|
|
78
|
+
if (isInternal) {
|
|
79
|
+
url = this._baseUrl + url;
|
|
80
|
+
//
|
|
81
|
+
if (this._token) {
|
|
82
|
+
config.headers = {
|
|
83
|
+
Authorization: `Bearer ${this._token}`
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//
|
|
88
|
+
return this._axios.post(url, data, config).then(response => {
|
|
89
|
+
return response.data;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//
|
|
94
|
+
export default new Net();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { IGame, ILogin, IOrder } from "../interface";
|
|
2
|
+
import { CURRENCY, PAY_TYPE } from './constant';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
declare class Platform {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
init(): void;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
reqGameInfo(): Promise<IGame>;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
reqLogin(): Promise<ILogin>;
|
|
19
|
+
/**
|
|
20
|
+
* @param productId
|
|
21
|
+
* @param name
|
|
22
|
+
* @param orderId
|
|
23
|
+
* @param price
|
|
24
|
+
* @param customData
|
|
25
|
+
*/
|
|
26
|
+
reqPurchase(productId: string, name: string, orderId: string, amount: number, customData: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param payType
|
|
30
|
+
* @param currency
|
|
31
|
+
*/
|
|
32
|
+
reqOrder(payType: PAY_TYPE, currency: CURRENCY): Promise<IOrder>;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param url
|
|
36
|
+
*/
|
|
37
|
+
openLink(url: string): void;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param url
|
|
41
|
+
*/
|
|
42
|
+
openTelegramLink(url: string): void;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param url
|
|
46
|
+
*/
|
|
47
|
+
openInvoice(url: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param content
|
|
51
|
+
*/
|
|
52
|
+
share(content: string): void;
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
enableClosingConfirmation(): void;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
disableClosingConfirmation(): void;
|
|
61
|
+
}
|
|
62
|
+
declare const _default: Platform;
|
|
63
|
+
export default _default;
|