fix: 话费按营业厅剩余话费页面显示
This commit is contained in:
@@ -46,6 +46,7 @@ type Client struct {
|
||||
loginReferer string
|
||||
fee billAPI
|
||||
plan billAPI
|
||||
checkURL string
|
||||
qrSec string
|
||||
loginReady bool
|
||||
}
|
||||
@@ -216,11 +217,18 @@ func (c *Client) Query(ctx context.Context, phone string) (Snapshot, error) {
|
||||
if err != nil {
|
||||
return Snapshot{}, err
|
||||
}
|
||||
if phone == "" {
|
||||
phone = c.syncMall(ctx)
|
||||
} else {
|
||||
c.syncMall(ctx)
|
||||
}
|
||||
extra := url.Values{
|
||||
"ticket": {""},
|
||||
"ticketPhone": {""},
|
||||
"ticketChannel": {""},
|
||||
"userNumber": {""},
|
||||
}
|
||||
if phone != "" {
|
||||
extra.Set("userNumber", phone)
|
||||
}
|
||||
if c.plan.Language != "" {
|
||||
extra.Set("language", c.plan.Language)
|
||||
@@ -257,7 +265,7 @@ func (c *Client) finishQR(ctx context.Context) (QRStatus, error) {
|
||||
if err := c.land(ctx, servicePage); err != nil {
|
||||
return QRStatus{}, err
|
||||
}
|
||||
return QRStatus{Message: "登录成功"}, nil
|
||||
return QRStatus{Message: "登录成功", Result: LoginResult{Phone: phoneFromPIW(asString(data["piw"]))}}, nil
|
||||
}
|
||||
|
||||
func (c *Client) prepareLogin(ctx context.Context) error {
|
||||
@@ -353,6 +361,9 @@ func (c *Client) prepareBill(ctx context.Context) error {
|
||||
texts = append(texts, js)
|
||||
}
|
||||
nav := resolveNav(texts)
|
||||
if c.checkURL == "" {
|
||||
c.checkURL = findCheckURL(texts)
|
||||
}
|
||||
if nav == "" {
|
||||
return errors.New("查询页没有导航接口")
|
||||
}
|
||||
@@ -610,6 +621,91 @@ func (c *Client) setDomainCookie(name, value string) {
|
||||
}})
|
||||
}
|
||||
|
||||
func (c *Client) firstCookie(name string) string {
|
||||
for _, host := range []string{"www.10010.com", "uac.10010.com", "mxx.client.10010.com", "iservice.10010.com"} {
|
||||
if value := c.cookie(host, name); value != "" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *Client) syncMall(ctx context.Context) string {
|
||||
if c.checkURL == "" {
|
||||
return ""
|
||||
}
|
||||
jut := c.firstCookie("JUT")
|
||||
if jut == "" {
|
||||
return ""
|
||||
}
|
||||
body, err := c.postForm(ctx, c.checkURL+"?="+milli(), servicePage, url.Values{
|
||||
"_uop_id": {c.firstCookie("_uop_id")},
|
||||
"jutThird": {jut},
|
||||
"procode": {c.firstCookie("userprocode")},
|
||||
})
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
var wrap struct {
|
||||
IsLogin bool `json:"isLogin"`
|
||||
UserInfo map[string]any `json:"userInfo"`
|
||||
}
|
||||
if json.Unmarshal(body, &wrap) != nil || !wrap.IsLogin || wrap.UserInfo == nil {
|
||||
return ""
|
||||
}
|
||||
c.setDomainCookie("loginflag", "true")
|
||||
if prov := pad3(asString(wrap.UserInfo["provincecode"])); prov != "" {
|
||||
c.setDomainCookie("userprocode", prov)
|
||||
}
|
||||
if city := asString(wrap.UserInfo["citycode"]); city != "" {
|
||||
c.setDomainCookie("citycode", city)
|
||||
c.setDomainCookie("city", city)
|
||||
}
|
||||
if enc := asString(wrap.UserInfo["encryptPhoneNumber"]); enc != "" {
|
||||
c.setDomainCookie("u_account", url.QueryEscape(enc))
|
||||
}
|
||||
debugf("商城登录状态已同步")
|
||||
phone := asString(wrap.UserInfo["usernumber"])
|
||||
if len(phone) == 11 {
|
||||
return phone
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func findCheckURL(texts []string) string {
|
||||
const marker = "/mall/service/check/checklogin"
|
||||
for _, text := range texts {
|
||||
if strings.Contains(text, marker) {
|
||||
return "https://www.10010.com" + marker
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func phoneFromPIW(raw string) string {
|
||||
text, err := url.QueryUnescape(raw)
|
||||
if err != nil || text == "" {
|
||||
text = raw
|
||||
}
|
||||
var wrap struct {
|
||||
RME struct {
|
||||
Phone string `json:"u"`
|
||||
} `json:"rme"`
|
||||
}
|
||||
if json.Unmarshal([]byte(text), &wrap) != nil || len(wrap.RME.Phone) != 11 {
|
||||
return ""
|
||||
}
|
||||
return wrap.RME.Phone
|
||||
}
|
||||
|
||||
func pad3(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
for len(s) > 0 && len(s) < 3 {
|
||||
s = "0" + s
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (c *Client) dropAccount() {
|
||||
u, err := url.Parse(uacOrigin + "/")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user