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