代码拉取完成,页面将自动刷新
同步操作将从 eatmoreapple/openwechat 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package openwechat
import (
"encoding/json"
"net/http"
"net/http/cookiejar"
"net/url"
)
// Jar is a struct which as same as cookiejar.Jar
// cookiejar.Jar's fields are private, so we can't use it directly
type Jar struct {
jar *cookiejar.Jar
hosts map[string]*url.URL
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (j *Jar) UnmarshalJSON(bytes []byte) error {
var cookies map[string][]*http.Cookie
if err := json.Unmarshal(bytes, &cookies); err != nil {
return err
}
if j.jar == nil {
j.jar, _ = cookiejar.New(nil)
}
for u, cs := range cookies {
u, err := url.Parse(u)
if err != nil {
return err
}
j.jar.SetCookies(u, cs)
}
return nil
}
// MarshalJSON implements the json.Marshaler interface
func (j *Jar) MarshalJSON() ([]byte, error) {
var cookies = make(map[string][]*http.Cookie)
for path, u := range j.hosts {
cookies[path] = append(cookies[path], j.jar.Cookies(u)...)
}
return json.Marshal(cookies)
}
func (j *Jar) SetCookies(u *url.URL, cookies []*http.Cookie) {
if j.hosts == nil {
j.hosts = make(map[string]*url.URL)
}
path := u.Scheme + "://" + u.Host
if _, exists := j.hosts[path]; !exists {
j.hosts[path] = u
}
j.jar.SetCookies(u, cookies)
}
func (j *Jar) Cookies(u *url.URL) []*http.Cookie {
return j.jar.Cookies(u)
}
func NewJar() *Jar {
jar, _ := cookiejar.New(nil)
return &Jar{
jar: jar,
hosts: make(map[string]*url.URL),
}
}
// CookieGroup is a group of cookies
type CookieGroup []*http.Cookie
func (c CookieGroup) GetByName(cookieName string) (cookie *http.Cookie, exist bool) {
for _, cookie := range c {
if cookie.Name == cookieName {
return cookie, true
}
}
return nil, false
}
func getWebWxDataTicket(cookies []*http.Cookie) (string, error) {
cookieGroup := CookieGroup(cookies)
cookie, exist := cookieGroup.GetByName("webwx_data_ticket")
if !exist {
return "", ErrWebWxDataTicketNotFound
}
return cookie.Value, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。