主要使用superagent.
发送Post请求进行登录,本地测试是通过的,也就是能正常登录,但云端测试一直无法正常登录.
const cheerio = require("cheerio");
const superagent = require("superagent");
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
var login_url = "http://us.nwpu.edu.cn/eams/login.action";
// 获取openId云函数入口函数
exports.main = async (event, context) => {
// 获取基础信息
const uid = event.sno;
const pwd = event.password;
var all_course_info = "";
return new Promise((resolve, reject) => {
superagent
.post(login_url)
.type("form")
.set({
"Content-Type": "application/x-www-form-urlencoded",
Host: "us.nwpu.edu.cn",
Origin: "http://us.nwpu.edu.cn",
Referer: "http://us.nwpu.edu.cn/eams/login.action",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62"
})
.send({
username: uid,
password: pwd,
encodedPassword: "",
session_locale: "zh_CN",
})
.end(function (err, res) {
//检测是否得到想要的结果
console.log(res.text);
var name_reg = /<p class="person_title_1" title="(\S*)">/g;
var name = name_reg.exec(res.text);
if (name) {
name = name[1];
} else {
reject('出错了');
}
看下是否更新上去了