6
6
*
7
7
* 中国联通手机营业厅的 URL Scheme:`chinaunicom://`,可用于点击小组件打开手机营业厅客户端
8
8
*
9
- * @version 1.0.0
9
+ * @version 1.0.1
10
10
* @author Honye
11
11
*/
12
12
13
+ // Utils module
14
+
15
+ /**
16
+ * download code
17
+ * @param {object } options
18
+ * @param {string } options.fileURL
19
+ */
20
+ const updateCode = async ( options ) => {
21
+ const { fileURL } = options ;
22
+ let fm = FileManager . local ( ) ;
23
+ if ( fm . isFileStoredIniCloud ( module . filename ) ) {
24
+ fm = FileManager . iCloud ( ) ;
25
+ }
26
+ const request = new Request ( fileURL ) ;
27
+ try {
28
+ const code = await request . loadString ( ) ;
29
+ fm . writeString ( module . filename , code ) ;
30
+ const alert = new Alert ( ) ;
31
+ alert . message = 'The code has been updated. If the script is open, close it for the change to take effect.' ;
32
+ alert . addAction ( 'OK' ) ;
33
+ alert . presentAlert ( ) ;
34
+ } catch ( e ) {
35
+ console . error ( e ) ;
36
+ }
37
+ } ;
38
+
39
+ const getImage = async ( url ) => {
40
+ const request = new Request ( url ) ;
41
+ const image = await request . loadImage ( ) ;
42
+ return image
43
+ } ;
44
+
13
45
const files = FileManager . local ( ) ;
14
46
/**
15
- * 修改为你的 cookie,cookie 获取方法,需安装 Stream 在联通客户端中进行抓包
47
+ * 修改为你的 cookie,cookie 获取方法,需在联通客户端中进行抓包
16
48
*
17
49
* 为方便多手机号使用多个组件优先采用本文件配置,其次使用 Config.js 配置
18
50
*/
19
51
let conf = {
20
- phone : '' , // 联通手机号
21
- clientCookie : '' , // m.client.10010.com API cookie
22
- actionCookie : '' // act.10010.com API cookie
52
+ /** 手机号 */
53
+ phone : '' ,
54
+ /** m.client.10010.com API cookie */
55
+ clientCookie : '' ,
56
+ /** act.10010.com API cookie */
57
+ actionCookie : ''
23
58
} ;
24
59
if ( ! conf . phone ) {
25
60
try {
@@ -48,12 +83,12 @@ const canvas = new DrawContext();
48
83
const canvWidth = 18 ;
49
84
const canvRadius = 80 ;
50
85
const widget = new ListWidget ( ) ;
51
- widget . url = 'chinaunicom://' ; // 打开联通客户端
52
- widget . setPadding ( 16 , 16 , 16 , 16 ) ; // widget边距(上,下,左,右)
86
+ widget . url = 'chinaunicom://' ;
87
+ widget . setPadding ( 16 , 16 , 16 , 16 ) ;
53
88
54
89
const main = async ( ) => {
55
90
if ( config . runsInWidget ) {
56
- render ( ) ;
91
+ await render ( ) ;
57
92
return
58
93
}
59
94
@@ -70,7 +105,9 @@ const main = async () => {
70
105
render ( ) ;
71
106
break
72
107
case 'Update' :
73
- update ( ) ;
108
+ updateCode ( {
109
+ fileURL : 'https://raw.githubusercontent.com/Honye/scriptable-scripts/master/dist/10010.js'
110
+ } ) ;
74
111
break
75
112
}
76
113
} ;
@@ -139,10 +176,10 @@ const renderLogo = async (status) => {
139
176
failed : Color . red ( )
140
177
} ;
141
178
iconStatus . tintColor = colors [ status ] ;
142
- const cuIconUrl = 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-imgbed/f77d3cdc-b757-4acd-9766-a64421bf0c6d .png' ;
179
+ const cuIconUrl = 'https://jun.fly.dev/imgs/chinaunicom .png' ;
143
180
const headerStack = widget . addStack ( ) ;
144
181
headerStack . addSpacer ( ) ;
145
- const logo = headerStack . addImage ( await getImg ( cuIconUrl ) ) ;
182
+ const logo = headerStack . addImage ( await getImage ( cuIconUrl ) ) ;
146
183
logo . imageSize = new Size ( 393 * 0.25 , 118 * 0.25 ) ;
147
184
headerStack . addSpacer ( ) ;
148
185
widget . addSpacer ( ) ;
@@ -205,12 +242,6 @@ const renderArcs = async (flowData, voiceData) => {
205
242
) ;
206
243
} ;
207
244
208
- async function getImg ( url ) {
209
- const req = new Request ( url ) ;
210
- const img = await req . loadImage ( ) ;
211
- return img
212
- }
213
-
214
245
function sinDeg ( deg ) {
215
246
return Math . sin ( ( deg * Math . PI ) / 180 )
216
247
}
@@ -272,13 +303,14 @@ const getData = async () => {
272
303
'User-Agent' : 'ChinaUnicom4.x/1.0 CFNetwork/1220.1 Darwin/20.3.0'
273
304
} ;
274
305
275
- const url = 'https://m.client.10010.com/mobileserviceimportant/home/queryUserInfoSeven?version=iphone_c@8.0102 &desmobiel=' + Tel + '&showType=0' ;
306
+ const url = 'https://m.client.10010.com/mobileserviceimportant/home/queryUserInfoSeven?version=iphone_c@9.0500 &desmobiel=' + Tel + '&showType=0' ;
276
307
const req = new Request ( url ) ;
277
308
req . headers = {
278
309
...headers ,
279
310
cookie : clientCookie
280
311
} ;
281
312
try {
313
+ // FIXME 联通已限制 IP 访问次数
282
314
const data = await req . loadJSON ( ) ;
283
315
console . log ( '余额信息请求成功 => ' ) ;
284
316
// console.log(data)
@@ -322,24 +354,4 @@ const getData = async () => {
322
354
}
323
355
} ;
324
356
325
- /** 更新脚本 */
326
- const update = async ( ) => {
327
- let fm = FileManager . local ( ) ;
328
- if ( fm . isFileStoredIniCloud ( module . filename ) ) {
329
- fm = FileManager . iCloud ( ) ;
330
- }
331
- const url = 'https://raw.githubusercontent.com/Honye/scriptable-scripts/master/10010/10010.js' ;
332
- const request = new Request ( url ) ;
333
- try {
334
- const code = await request . loadString ( ) ;
335
- fm . writeString ( module . filename , code ) ;
336
- const alert = new Alert ( ) ;
337
- alert . message = 'The code has been updated. If the script is open, close it for the change to take effect.' ;
338
- alert . addAction ( 'OK' ) ;
339
- alert . presentAlert ( ) ;
340
- } catch ( e ) {
341
- console . error ( e ) ;
342
- }
343
- } ;
344
-
345
- main ( ) ;
357
+ await main ( ) ;
0 commit comments