Skip to content

Commit b0340e2

Browse files
committed
fix: 修复图片失效的问题
1 parent 5c044fc commit b0340e2

File tree

3 files changed

+72
-78
lines changed

3 files changed

+72
-78
lines changed

dist/10010.js

+51-39
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,55 @@
66
*
77
* 中国联通手机营业厅的 URL Scheme:`chinaunicom://`,可用于点击小组件打开手机营业厅客户端
88
*
9-
* @version 1.0.0
9+
* @version 1.0.1
1010
* @author Honye
1111
*/
1212

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+
1345
const files = FileManager.local();
1446
/**
15-
* 修改为你的 cookie,cookie 获取方法,需安装 Stream 在联通客户端中进行抓包
47+
* 修改为你的 cookie,cookie 获取方法,需在联通客户端中进行抓包
1648
*
1749
* 为方便多手机号使用多个组件优先采用本文件配置,其次使用 Config.js 配置
1850
*/
1951
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: ''
2358
};
2459
if (!conf.phone) {
2560
try {
@@ -48,12 +83,12 @@ const canvas = new DrawContext();
4883
const canvWidth = 18;
4984
const canvRadius = 80;
5085
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);
5388

5489
const main = async () => {
5590
if (config.runsInWidget) {
56-
render();
91+
await render();
5792
return
5893
}
5994

@@ -70,7 +105,9 @@ const main = async () => {
70105
render();
71106
break
72107
case 'Update':
73-
update();
108+
updateCode({
109+
fileURL: 'https://raw.githubusercontent.com/Honye/scriptable-scripts/master/dist/10010.js'
110+
});
74111
break
75112
}
76113
};
@@ -139,10 +176,10 @@ const renderLogo = async (status) => {
139176
failed: Color.red()
140177
};
141178
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';
143180
const headerStack = widget.addStack();
144181
headerStack.addSpacer();
145-
const logo = headerStack.addImage(await getImg(cuIconUrl));
182+
const logo = headerStack.addImage(await getImage(cuIconUrl));
146183
logo.imageSize = new Size(393 * 0.25, 118 * 0.25);
147184
headerStack.addSpacer();
148185
widget.addSpacer();
@@ -205,12 +242,6 @@ const renderArcs = async (flowData, voiceData) => {
205242
);
206243
};
207244

208-
async function getImg (url) {
209-
const req = new Request(url);
210-
const img = await req.loadImage();
211-
return img
212-
}
213-
214245
function sinDeg (deg) {
215246
return Math.sin((deg * Math.PI) / 180)
216247
}
@@ -272,13 +303,14 @@ const getData = async () => {
272303
'User-Agent': 'ChinaUnicom4.x/1.0 CFNetwork/1220.1 Darwin/20.3.0'
273304
};
274305

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';
276307
const req = new Request(url);
277308
req.headers = {
278309
...headers,
279310
cookie: clientCookie
280311
};
281312
try {
313+
// FIXME 联通已限制 IP 访问次数
282314
const data = await req.loadJSON();
283315
console.log('余额信息请求成功 => ');
284316
// console.log(data)
@@ -322,24 +354,4 @@ const getData = async () => {
322354
}
323355
};
324356

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();

src/10010.js

+20-39
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
const { getImage, updateCode } = importModule('utils.module')
2+
13
const files = FileManager.local()
24
/**
3-
* 修改为你的 cookie,cookie 获取方法,需安装 Stream 在联通客户端中进行抓包
5+
* 修改为你的 cookie,cookie 获取方法,需在联通客户端中进行抓包
46
*
57
* 为方便多手机号使用多个组件优先采用本文件配置,其次使用 Config.js 配置
68
*/
79
let conf = {
8-
phone: '', // 联通手机号
9-
clientCookie: '', // m.client.10010.com API cookie
10-
actionCookie: '' // act.10010.com API cookie
10+
/** 手机号 */
11+
phone: '',
12+
/** m.client.10010.com API cookie */
13+
clientCookie: '',
14+
/** act.10010.com API cookie */
15+
actionCookie: ''
1116
}
1217
if (!conf.phone) {
1318
try {
@@ -38,12 +43,12 @@ const canvas = new DrawContext()
3843
const canvWidth = 18
3944
const canvRadius = 80
4045
const widget = new ListWidget()
41-
widget.url = 'chinaunicom://' // 打开联通客户端
42-
widget.setPadding(16, 16, 16, 16) // widget边距(上,下,左,右)
46+
widget.url = 'chinaunicom://'
47+
widget.setPadding(16, 16, 16, 16)
4348

4449
const main = async () => {
4550
if (config.runsInWidget) {
46-
render()
51+
await render()
4752
return
4853
}
4954

@@ -60,7 +65,9 @@ const main = async () => {
6065
render()
6166
break
6267
case 'Update':
63-
update()
68+
updateCode({
69+
fileURL: 'https://raw.githubusercontent.com/Honye/scriptable-scripts/master/dist/10010.js'
70+
})
6471
break
6572
default:
6673
}
@@ -129,7 +136,6 @@ async function rmBgImg () {
129136
if (files.fileExists(bgPath)) {
130137
try {
131138
files.remove(bgPath)
132-
log('背景图片清理成功')
133139
} catch (e) {
134140
log(e.message)
135141
}
@@ -152,10 +158,10 @@ const renderLogo = async (status) => {
152158
failed: Color.red()
153159
}
154160
iconStatus.tintColor = colors[status]
155-
const cuIconUrl = 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-imgbed/f77d3cdc-b757-4acd-9766-a64421bf0c6d.png'
161+
const cuIconUrl = 'https://jun.fly.dev/imgs/chinaunicom.png'
156162
const headerStack = widget.addStack()
157163
headerStack.addSpacer()
158-
const logo = headerStack.addImage(await getImg(cuIconUrl))
164+
const logo = headerStack.addImage(await getImage(cuIconUrl))
159165
logo.imageSize = new Size(393 * 0.25, 118 * 0.25)
160166
headerStack.addSpacer()
161167
widget.addSpacer()
@@ -218,12 +224,6 @@ const renderArcs = async (flowData, voiceData) => {
218224
)
219225
}
220226

221-
async function getImg (url) {
222-
const req = new Request(url)
223-
const img = await req.loadImage()
224-
return img
225-
}
226-
227227
function sinDeg (deg) {
228228
return Math.sin((deg * Math.PI) / 180)
229229
}
@@ -285,13 +285,14 @@ const getData = async () => {
285285
'User-Agent': 'ChinaUnicom4.x/1.0 CFNetwork/1220.1 Darwin/20.3.0'
286286
}
287287

288-
const url = 'https://m.client.10010.com/mobileserviceimportant/home/queryUserInfoSeven?version=iphone_c@8.0102&desmobiel=' + Tel + '&showType=0'
288+
const url = 'https://m.client.10010.com/mobileserviceimportant/home/queryUserInfoSeven?version=iphone_c@9.0500&desmobiel=' + Tel + '&showType=0'
289289
const req = new Request(url)
290290
req.headers = {
291291
...headers,
292292
cookie: clientCookie
293293
}
294294
try {
295+
// FIXME 联通已限制 IP 访问次数
295296
const data = await req.loadJSON()
296297
console.log('余额信息请求成功 => ')
297298
// console.log(data)
@@ -335,24 +336,4 @@ const getData = async () => {
335336
}
336337
}
337338

338-
/** 更新脚本 */
339-
const update = async () => {
340-
let fm = FileManager.local()
341-
if (fm.isFileStoredIniCloud(module.filename)) {
342-
fm = FileManager.iCloud()
343-
}
344-
const url = 'https://raw.githubusercontent.com/Honye/scriptable-scripts/master/10010/10010.js'
345-
const request = new Request(url)
346-
try {
347-
const code = await request.loadString()
348-
fm.writeString(module.filename, code)
349-
const alert = new Alert()
350-
alert.message = 'The code has been updated. If the script is open, close it for the change to take effect.'
351-
alert.addAction('OK')
352-
alert.presentAlert()
353-
} catch (e) {
354-
console.error(e)
355-
}
356-
}
357-
358-
main()
339+
await main()

src/10010.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"version": "1.0.1",
23
"description": [
34
"中国联通信息展示和自动签到",
45
"",

0 commit comments

Comments
 (0)