|
|
@@ -0,0 +1,148 @@
|
|
|
+/*
|
|
|
+中国联通充值折扣券
|
|
|
+
|
|
|
+[Script]
|
|
|
+
|
|
|
+[MITM]
|
|
|
+
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+const scriptName = `中国联通充值折扣券`;
|
|
|
+const magicJS = MagicJS(scriptName, "INFO");
|
|
|
+
|
|
|
+const gUserAgent = `ChinaUnicom4.x/11.7 (com.chinaunicom.mobilebusiness; build:48; iOS 16.6.1) Alamofire/4.7.3 unicom{version:[email protected]}`;
|
|
|
+
|
|
|
+const gHost = `m.client.10010.com`;
|
|
|
+
|
|
|
+const gCommonHeaders = {
|
|
|
+ 'Cookie': ``,
|
|
|
+ 'Accept': `*`,
|
|
|
+ 'Connection': `keep-alive`,
|
|
|
+ 'Content-Type': `application/x-www-form-urlencoded`,
|
|
|
+ 'Accept-Encoding': `gzip;q=1.0, compress;q=0.5`,
|
|
|
+ 'Host': gHost,
|
|
|
+ 'User-Agent': gUserAgent,
|
|
|
+ 'X-Tingyun-Id': `4gA5HRiCw8g;c=2;r=1184031225;u=62ffa39b4f94b3f4742089def7690470bd24ba1846d5d369e5460f4f029537a331b0b70e1293dcfcd727cab6b63edf43::BD4E4C616020FB61`,
|
|
|
+ 'Accept-Language': `zh-Hans-CN;q=1.0`,
|
|
|
+ 'X-Tingyun': `c=A|uBuVhVARE0A`
|
|
|
+};
|
|
|
+
|
|
|
+const UnicomConstKey = {
|
|
|
+ // 基础数据
|
|
|
+ Cookie: 'UnicomActivityCookie',
|
|
|
+ // 充值优惠折扣活动数据
|
|
|
+ RechargeDiscData: 'UnicomRechargeDiscData',
|
|
|
+};
|
|
|
+
|
|
|
+let gRetBody;
|
|
|
+
|
|
|
+async function Main() {
|
|
|
+ if (magicJS.isStrictRequest) {
|
|
|
+ magicJS.checkRecordRequestBody();
|
|
|
+ }
|
|
|
+ if (magicJS.isRequest) {
|
|
|
+ checkHandleRequest();
|
|
|
+ } else {
|
|
|
+ updateHeaders();
|
|
|
+ await tryGrab();
|
|
|
+ }
|
|
|
+ magicJS.notification.msg('');
|
|
|
+ if (gRetBody) {
|
|
|
+ magicJS.done({
|
|
|
+ body: JSON.stringify(gRetBody)
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ magicJS.done();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function checkHandleRequest() {
|
|
|
+}
|
|
|
+
|
|
|
+function setRechargeDiscReqData(id, paramStr) {
|
|
|
+ let data = magicJS.data.read(UnicomConstKey.RechargeDiscData, null)
|
|
|
+ let nowDateStr = magicJS.formatDate(nowDate, 'yyyy/MM/dd');
|
|
|
+ if (!data || data.date != nowDateStr) {
|
|
|
+ data = {
|
|
|
+ date: nowDateStr,
|
|
|
+ dict: {},
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.dict = data.dict || {};
|
|
|
+ data.dict[id] = paramStr;
|
|
|
+ magicJS.data.write(UnicomConstKey.RechargeDiscData, data);
|
|
|
+}
|
|
|
+
|
|
|
+function deleteRechargeDiscReqData(id) {
|
|
|
+ let data = magicJS.data.read(UnicomConstKey.RechargeDiscData, null)
|
|
|
+ let nowDateStr = magicJS.formatDate(nowDate, 'yyyy/MM/dd');
|
|
|
+ if (data && data.date == nowDateStr) {
|
|
|
+ if (data.dict) {
|
|
|
+ delete data.dict[id];
|
|
|
+ magicJS.data.write(UnicomConstKey.RechargeDiscData, data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function getRechargeDiscReqDataDict() {
|
|
|
+ let data = magicJS.data.read(UnicomConstKey.RechargeDiscData, null)
|
|
|
+ let nowDateStr = magicJS.formatDate(nowDate, 'yyyy/MM/dd');
|
|
|
+ if (!data || data.date != nowDateStr) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return data.dict;
|
|
|
+}
|
|
|
+function updateHeaders() {
|
|
|
+ gCommonHeaders[`Cookie`] = magicJS.data.read(UnicomConstKey.Cookie, '');
|
|
|
+}
|
|
|
+
|
|
|
+async function tryGrab() {
|
|
|
+ let taskData = getRechargeDiscReqDataDict();
|
|
|
+ let tipsText = ``;
|
|
|
+ for (let i = 0; i < 5; i++) {
|
|
|
+ for (let id in taskData) {
|
|
|
+ let paramStr = taskData[id];
|
|
|
+ let result = await grabDiscCoupon(id, paramStr);
|
|
|
+ if (result) {
|
|
|
+ switch (result.status) {
|
|
|
+ case '0000':
|
|
|
+ case '1004'://库存不足
|
|
|
+ deleteRechargeDiscReqData(id);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ tipsText += `优惠折扣券[${id}]${result.msg}\n`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tipsText.length > 0) {
|
|
|
+ magicJS.notification.appendNotifyInfo(`领取结果如下:\n${tipsText}`);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function grabDiscCoupon(id, paramStr) {
|
|
|
+ let url = `https://m.client.10010.com/AppMonthly/appMonth/dddddddddd/${id}?p=${paramStr}`;
|
|
|
+ let headers = { ...gCommonHeaders };
|
|
|
+
|
|
|
+ let options = {
|
|
|
+ url: url,
|
|
|
+ headers: headers,
|
|
|
+ body: ``,
|
|
|
+ };
|
|
|
+ let result = await magicJS.http.get(options).then(response => {
|
|
|
+ try {
|
|
|
+ let rspData = response.body;
|
|
|
+ magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
|
|
|
+ return rspData;
|
|
|
+ } catch (e) {
|
|
|
+ magicJS.logger.error(e);
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ const msg = `请求抢充值折扣券异常\n${JSON.stringify(err)}`;
|
|
|
+ magicJS.logger.error(msg);
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+}
|