You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

/**
* https://github.com/jinke18/educoder_weapp
* @licence GPL-3.0
* @author jinke18
*/
/**
* Cookie类用于网络中cookie的各类操作
*/
export class Cookie{
/**
*
* example: "autologin_trustie=8acaa2b09d5056c0e9d82519052276b9d4a524e9; domain=.educoder.net ; path=/; expires=Fri, 29 Nov 2019 15:32:53 -0000; HttpOnly"
*/
constructor(str){
this.origin_str = str;
this.analyse_cookie(str);
}
analyse_cookie(str){
this.string = str.slice(0, str.indexOf(";"));
let idx = this.string.indexOf("=");
this.key = this.string.slice(0, idx);
this.value = this.string.slice(idx+1);
}
toString(){
return this.string;
//return this.key + "=" + this.value;
}
save(){
if(!this.key){
console.error("cookie保存时: 没有键值key");
}
wx.setStorageSync(this.key, this.origin_str);
}
static load(key){
return new Cookie(wx.getStorageSync(key));
}
}
function test() {
//used to test the class Cookie
cookie_str = "autologin_trustie=8acaa2b09d5056c0e9d82519052276b9d4a524e9; domain=.educoder.net ; path=/; expires=Fri, 29 Nov 2019 15:32:53 -0000; HttpOnly";
cookie = new Cookie(cookie_str);
}
//test();