hnm sign
// ==UserScript==
// @name hnm sign
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.2.0
// @description sign by requesting
// @author tfsn20
// @crontab * 1-23 once * *
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @connect h5.ha.chinamobile.com
// ==/UserScript==
//这里填入hncmjsSSOCookie
const hncmjsSSOCookie = ''
//判断str是否可json化,返回bool
function isJsonString(str) {
try {
if (typeof JSON.parse(str) == "object" && JSON.parse(str) != null) {
return true;
}
} catch (e) {
}
return false;
}
//获取刷新cookie, 返回responseHeads
function refleshCookie() {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'https://h5.ha.chinamobile.com/hnmccClient/action.dox ',
method: "POST",
data: `authSign=souKVM9C3tOm78xNOdA%2BAhKiUVL0WXSC2%2BYH3h5RrDn8sx%2BQ5MG%2FwCC0De77ed34tJeeu8BvouHB%0AOmWQdxL97WCQo%2BpN7fr%2FUtj6Z3oETgCtZ7hTtw7eyMMfz%2FkV51L%2FfnAb29NeNvhCAnQnwFmPEJTK%0ABDrauBZV8XBQ3XOlKerypjzGZ%2Feyoy0pBSsBjXLl%2F8CmDFNHH%2FM3l5dvCfyGskgQjLtnsh0YeeEV%0AqP7wHMnYUIXgYWcNMxTPPp1P3CZJ7pVOzSoV6agIDeYnbQSqiDlFeO8RODgat4H4P%2F35TrMnq8KB%0AJwkb55tp0wXZvuRgUhnqCxi3o%2BmFW8xiAZKFol3u6T4tqqAVJ%2BcFV67dysy1te1b%2FF7KHPWxAs1%2F%0AU0xNrDBE9oQbWiRv%2BpKc1a90sfZjt1AnHTpI9afzjemPHT0NA%2F9prUa5pRW%2FBGUIvaTk0jx6eSx5%0Ab0S1JovbtMDir7%2FOPRDNShJU9L%2FBJ1ApIdcObhKkYzbFqFBXMSMonqcdP8%2Ftu1WkQzPhQctud%2FoW%0AF34U4Y4vRF0tVLfU3vbb1NhvbD%2B0CKQUlOVc1iUwG5xw3vFv8GtuJVkbD1FBhsHRpq3K8seIJgja%0A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ECYIPsaNHDphRimbp8nd%2BY3s%2BTD%2FSYHMM5Nk12JQ74fm0Yh6DHOL%0AlGyVyDSPd5apoeN2Dz%2BuF7JnfAGf%2FvZSJbwV5AZ8u09TJK3K8seIJgjadxsrpYrRJunHmYKuWfuP%0AYPzDQOEMfMP86%2BERY30CTFPlXNYlMBuccHeXUN5q57tkMBlipnoSbBHD1sUBzaR4nc9kzy77KlPq%0AVC4suqYy9srjdg8%2FrheyZze7Jr8hp2rlyUF0ZlSUwN7jdg8%2FrheyZ5lero%2FqP4wMRimbp8nd%2BY3H%0AgL5R3VYZOHWo2DrGKsns3vYb51SUkVp9dHKfMpG480GaYKaFeEBjFOdrOiPdUtGI9rOdsN9wRJES%0Av%2BVptemhykXDyoER2dJQuuRFKQbuGKdF4fkIiyuFVhc7gd%2BAICrjdg8%2FrheyZwq5swBwUS0kFZj%2F%0APVKHVuHbzths75oFON72G%2BdUlJFaPAmkC4YzM%2FxcvF8IXNej9f%2F4IetUwGAQVLfU3vbb1NhGKZun%0Ayd35jW%2B%2BYVy%2BcbK0QvHx9Z0NskQFFwxXShBOHcPWxQHNpHidzmxd6gvGXXVrwHk15%2FNa52jRk2AD%0A9EXs8dGndlI%2Fa7uaQ5YEBc%2FYa0gZEFIfymmp3vYb51SUkVp9dHKfMpG4868JWgb%2BM%2FbbaP9vGVwW%0AGeAzItTXRMJUHLK6TPXrHHtCBp3O40ywFKVWL%2FQIsUlbjpHEamU8HBjLq1oBiddu817YSBjeBcxd%0Aa5ybehP9eB0JuYpEkF4feGftJRgRscr5LKWhYnfUJaEcWPkC1m%2B4DLgsL%2Fhc1BWK6BqkoQlnDBJy%0ArV5B5UmdQrWvv3kcx86CvV1zAtI1aeNf`,
headers: {
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
'Accept': 'application/json, text/javascript, */*; q=0.01',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; PACM00 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Host': 'h5.ha.chinamobile.com',
'Origin': 'https://h5.ha.chinamobile.com',
'Referer': 'https://h5.ha.chinamobile.com/hnmccClientWap/2021/07/signNew/index.html?defaultSelected=ACT_20210312_2323&rn=RECO20210220165226AUID337507&pn=APP_7.0_SY',
'region': 'HN',
'version': '7.0.3',
'platform': 'android',
'cookie': `hncmjsSSOCookie=${hncmjsSSOCookie};VersionName=7.0.3;channel=OPPO_CHANNEL`
},
onload: async function (xhr) {
console.log('refleshCookie', xhr.responseHeaders);
resolve(xhr.responseHeaders)
}, onerror() {
GM_notification({
title: "刷新cookie失败",
text: "网络错误"
});
reject("网络错误");
}
})
})
}
//获取刷新的cookie后签到, 返回签到结果的json字符串
function hnmSign() {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'https://h5.ha.chinamobile.com/hnmccClientWap/signNewEdition/signDraw4h.do?r=0.029410902623797197',
method: "POST",
data: 'channel=channel_app&taskId=&from=',
headers: {
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cros",
"Sec-Fetch-Dest": "empty",
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; PACM00 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://h5.ha.chinamobile.com',
'Referer': 'https://h5.ha.chinamobile.com/hnmccClientWap/2021/07/signNew/index.html?defaultSelected=ACT_20210312_2323&rn=RECO20210220165226AUID337507&pn=APP_7.0_SY',
'cookie': `VersionName=7.0.3; channel=OPPO_CHANNEL`
},
onload: function (xhr) {
console.log('hnmSign', xhr.response);
resolve(xhr.response)
}
})
})
}
//查询我的券, 返回全部券的array
function queryMyCoupon() {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'https://h5.ha.chinamobile.com/hnmccClientWap/mycoupon/queryMyCoupon.do',
method: "POST",
data: 'couponStatus=DSY',
headers: {
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cros",
"Sec-Fetch-Dest": "empty",
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'com.xinhang.mobileclient',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; PACM00 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36',
'Host': 'h5.ha.chinamobile.com',
'Referer': 'https://h5.ha.chinamobile.com/hnmccClientWap/act_h5/html/h5/myCard/cardIndex',
'cookie': `VersionName=7.0.3; channel=OPPO_CHANNEL`
},
onload: function (xhr) {
if (isJsonString(xhr.response)) {
let couponJson = JSON.parse(xhr.response);
console.log(couponJson.mobile, couponJson.result.obj, couponJson.result.obj.length);
resolve(couponJson.result.obj)
}
}
})
})
}
//获取使用券的信息, 返回券信息的json
function getCouponInfo(json) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'https://h5.ha.chinamobile.com/hnmccClientWap/coupon/getCouponInfo.do',
method: "POST",
data: `ENCRYPT=${json.couponNum}&couponCfgNum=${json.couponCfgNum}`,
headers: {
'Host': 'h5.ha.chinamobile.com',
'Accept': 'application/json, text/plain, */*',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; PACM00 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'https://h5.ha.chinamobile.com',
'X-Requested-With': 'com.xinhang.mobileclient',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': `https://h5.ha.chinamobile.com/hnmccClientWap/act_h5/html/h5/myCard/cardDetail?couponCfgNum=${json.couponCfgNum}&ENCRYPT=${json.couponNum}`,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'cookie': `VersionName=7.0.3; channel=OPPO_CHANNEL`
},
onload: function (xhr) {
if (isJsonString(xhr.response)) {
let jsonTemp = JSON.parse(xhr.response);
console.log(jsonTemp.result.obj);
resolve(jsonTemp.result.obj)
} else {
resolve(xhr.response)
}
}
})
})
}
//使用券, 返回用response
function useCoupon(json) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'https://h5.ha.chinamobile.com/hnmccClientWap/coupon/couponUse.do',
method: "POST",
data: `couponCfgNum=${json.couponCfgNum}&ENCRYPT=${json.newNum}&dataSource=${json.dataSource}&couponType=${json.couponType}&showTypeId=${json.showTypeId}&cfgId=${json.cfgId}&useType=${json.useType}&isEcp=${json.isEcp}&isAct=${json.isAct}`,
headers: {
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cros",
"Sec-Fetch-Dest": "empty",
'Accept': 'application/json, text/plain, */*',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; PACM00 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'com.xinhang.mobileclient',
'Host': 'h5.ha.chinamobile.com',
'Referer': `https://h5.ha.chinamobile.com/hnmccClientWap/act_h5/html/h5/myCard/cardDetail?couponCfgNum=${json.couponCfgNum}&ENCRYPT=${json.couponNum}`,
'origin': 'https://h5.ha.chinamobile.com',
'cookie': `VersionName=7.0.3; channel=OPPO_CHANNEL`
},
onload: function (xhr) {
console.log('useCoupon', xhr.response);
resolve(xhr.response)
}
})
})
}
//周日转转乐(抽奖和获取机会)
//查询当前可抽奖次数, 返回次数
function initChance() {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'https://h5.ha.chinamobile.com/hnmccClientWap/weekend/init.do',
method: "POST",
data: 'portalPcAccessLogTarget=1',
headers: {
'Host': 'h5.ha.chinamobile.com',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; PACM00 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://h5.ha.chinamobile.com',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://h5.ha.chinamobile.com/hnmccClientWap/2021/07/zhouMo/index.html?channel=channel_QD&WT.ac_id=220602_ZMZZL_QD',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': 'VersionName=7.0.3; channel=OPPO_CHANNEL'
},
onload: function (xhr) {
console.log('initChance', xhr.response, JSON.parse(xhr.response).n_count);
resolve(JSON.parse(xhr.response).n_count)
}
})
})
}
//抽奖, 返回抽奖情况
function drawWeekend() {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'https://h5.ha.chinamobile.com/hnmccClientWap/weekend/chick.do',
method: "POST",
data: 'channel=channel_QD',
headers: {
'Host': 'h5.ha.chinamobile.com',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; PACM00 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://h5.ha.chinamobile.com',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://h5.ha.chinamobile.com/hnmccClientWap/2021/07/zhouMo/index.html?channel=channel_QD&WT.ac_id=220602_ZMZZL_QD',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cookie': 'VersionName=7.0.3; channel=OPPO_CHANNEL'
},
onload: function (xhr) {
console.log('darwWeekend', xhr.response);
resolve(xhr.response)
}
})
})
}
//获取抽奖机会, 返回获取结果
function getchance() {
return new Promise(async (resolve, reject) => {
let aTemp = '';
function request(i) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: 'https://h5.ha.chinamobile.com/hnmccClientWap/weekend/freq.do',
method: "POST",
data: `type=${i}`,
headers: {
'Host': 'h5.ha.chinamobile.com',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; PACM00 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://h5.ha.chinamobile.com',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://h5.ha.chinamobile.com/hnmccClientWap/2021/07/zhouMo/index.html?channel=channel_QD&WT.ac_id=220602_ZMZZL_QD',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7'
},
onload: function (xhr) {
console.log('getChance', xhr.response);
aTemp += i + xhr.response;
resolve(aTemp)
}
})
})
};
for (var i = 1; i < 5; i++) {
await request(i)
};
console.log('getChance', aTemp);
resolve('getChance' + aTemp)
})
}
//通知和执行函数
return new Promise((resolve, reject) => {
//刷新cookie和之后执行的函数
async function refleshCookieThen() {
//等待cookie刷新
await refleshCookie();
let signInfo = await hnmSign();
//判断是否登录成功
if (signInfo == '{"result":{"code":0,"info":"登录超时"}}') {
reject('cookie错误')
} else {
GM_notification({
title: "签到信息",
text: JSON.parse(signInfo).result.info
})
//判断是否是周末
if (new Date().getDay() == 6 || new Date().getDay() == 0) {
//获取抽奖机会
GM_notification({
title: "获取的抽奖次数情况",
text: await getchance()
});
//根据可抽奖次数来抽奖
let weekendDrawTime = await initChance();
if (weekendDrawTime == 0) {
GM_notification({
title: "抽奖情况",
text: "暂无抽奖次数"
})
} else {
for (let i = 0; i < weekendDrawTime; i++) {
GM_notification({
title: "抽奖情况",
text: await drawWeekend()
})
}
}
//根据券的个数来发送用券请求
let couponCount = await queryMyCoupon();
if (couponCount == 0) {
GM_notification({
title: "用券情况",
text: "暂时无券"
})
} else {
for (let i = 0; i < chance.length; i++) {
GM_notification({
title: "用券情况",
text: await useCoupon(await getCouponInfo(chance[i]))
})
}
};
resolve('sign and draw success')
} else {
//根据券的个数来发送用券请求
let couponCount = await queryMyCoupon();
if (couponCount == 0) {
GM_notification({
title: "用券情况",
text: "暂时无券"
})
} else {
for (let i = 0; i < chance.length; i++) {
GM_notification({
title: "用券情况",
text: await useCoupon(await getCouponInfo(chance[i]))
})
}
}
resolve('sign success')
}
}
}
refleshCookieThen();
})