fix: 话费按营业厅剩余话费页面显示
This commit is contained in:
@@ -46,6 +46,7 @@ type Client struct {
|
|||||||
loginReferer string
|
loginReferer string
|
||||||
fee billAPI
|
fee billAPI
|
||||||
plan billAPI
|
plan billAPI
|
||||||
|
checkURL string
|
||||||
qrSec string
|
qrSec string
|
||||||
loginReady bool
|
loginReady bool
|
||||||
}
|
}
|
||||||
@@ -216,11 +217,18 @@ func (c *Client) Query(ctx context.Context, phone string) (Snapshot, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Snapshot{}, err
|
return Snapshot{}, err
|
||||||
}
|
}
|
||||||
|
if phone == "" {
|
||||||
|
phone = c.syncMall(ctx)
|
||||||
|
} else {
|
||||||
|
c.syncMall(ctx)
|
||||||
|
}
|
||||||
extra := url.Values{
|
extra := url.Values{
|
||||||
"ticket": {""},
|
"ticket": {""},
|
||||||
"ticketPhone": {""},
|
"ticketPhone": {""},
|
||||||
"ticketChannel": {""},
|
"ticketChannel": {""},
|
||||||
"userNumber": {""},
|
}
|
||||||
|
if phone != "" {
|
||||||
|
extra.Set("userNumber", phone)
|
||||||
}
|
}
|
||||||
if c.plan.Language != "" {
|
if c.plan.Language != "" {
|
||||||
extra.Set("language", 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 {
|
if err := c.land(ctx, servicePage); err != nil {
|
||||||
return QRStatus{}, err
|
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 {
|
func (c *Client) prepareLogin(ctx context.Context) error {
|
||||||
@@ -353,6 +361,9 @@ func (c *Client) prepareBill(ctx context.Context) error {
|
|||||||
texts = append(texts, js)
|
texts = append(texts, js)
|
||||||
}
|
}
|
||||||
nav := resolveNav(texts)
|
nav := resolveNav(texts)
|
||||||
|
if c.checkURL == "" {
|
||||||
|
c.checkURL = findCheckURL(texts)
|
||||||
|
}
|
||||||
if nav == "" {
|
if nav == "" {
|
||||||
return errors.New("查询页没有导航接口")
|
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() {
|
func (c *Client) dropAccount() {
|
||||||
u, err := url.Parse(uacOrigin + "/")
|
u, err := url.Parse(uacOrigin + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ type Snapshot struct {
|
|||||||
Balance string `json:"balance,omitempty"`
|
Balance string `json:"balance,omitempty"`
|
||||||
BalanceNegative bool `json:"balanceNegative,omitempty"`
|
BalanceNegative bool `json:"balanceNegative,omitempty"`
|
||||||
MonthFee string `json:"monthFee,omitempty"`
|
MonthFee string `json:"monthFee,omitempty"`
|
||||||
|
CarryOver string `json:"carryOver,omitempty"`
|
||||||
|
MonthIn string `json:"monthIn,omitempty"`
|
||||||
DataRemain string `json:"dataRemain,omitempty"`
|
DataRemain string `json:"dataRemain,omitempty"`
|
||||||
DataUsed string `json:"dataUsed,omitempty"`
|
DataUsed string `json:"dataUsed,omitempty"`
|
||||||
VoiceTotal string `json:"voiceTotal,omitempty"`
|
VoiceTotal string `json:"voiceTotal,omitempty"`
|
||||||
@@ -41,12 +43,25 @@ func BuildSnapshot(phone string, balanceRaw, planRaw json.RawMessage) Snapshot {
|
|||||||
var balance map[string]any
|
var balance map[string]any
|
||||||
_ = json.Unmarshal(balanceRaw, &balance)
|
_ = json.Unmarshal(balanceRaw, &balance)
|
||||||
if balance != nil {
|
if balance != nil {
|
||||||
snap.Balance = textOf(balance["canusefeecust"])
|
snap.Balance = textOf(balance["curntbalancecust"])
|
||||||
if snap.Balance == "" {
|
if snap.Balance == "" {
|
||||||
snap.Balance = textOf(balance["curntbalancecust"])
|
snap.Balance = textOf(balance["canusefeecust"])
|
||||||
}
|
}
|
||||||
snap.BalanceNegative = strings.HasPrefix(snap.Balance, "-")
|
snap.BalanceNegative = strings.HasPrefix(snap.Balance, "-")
|
||||||
snap.MonthFee = textOf(balance["realfeecust"])
|
if truthy(balance["newVersion"]) {
|
||||||
|
snap.MonthFee = textOf(balance["realfeecustnew"])
|
||||||
|
snap.CarryOver = textOf(balance["newCarryForwardFromLastMonth"])
|
||||||
|
snap.MonthIn = textOf(balance["newDepositForTheMonth"])
|
||||||
|
}
|
||||||
|
if snap.MonthFee == "" {
|
||||||
|
snap.MonthFee = textOf(balance["realfeecust"])
|
||||||
|
}
|
||||||
|
if snap.CarryOver == "" {
|
||||||
|
snap.CarryOver = textOf(balance["carryForwardFromLastMonth"])
|
||||||
|
}
|
||||||
|
if snap.MonthIn == "" {
|
||||||
|
snap.MonthIn = textOf(balance["depositForTheMonth"])
|
||||||
|
}
|
||||||
if owe := textOf(balance["allbowefeecust"]); owe != "" && owe != "0" && owe != "0.00" {
|
if owe := textOf(balance["allbowefeecust"]); owe != "" && owe != "0" && owe != "0.00" {
|
||||||
snap.Extras = append(snap.Extras, Extra{Name: "欠费", Used: owe, Fee: owe})
|
snap.Extras = append(snap.Extras, Extra{Name: "欠费", Used: owe, Fee: owe})
|
||||||
}
|
}
|
||||||
@@ -177,6 +192,17 @@ func trimNum(v float64) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func truthy(v any) bool {
|
||||||
|
switch t := v.(type) {
|
||||||
|
case bool:
|
||||||
|
return t
|
||||||
|
case string:
|
||||||
|
return t == "true" || t == "1"
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func textOf(v any) string {
|
func textOf(v any) string {
|
||||||
switch t := v.(type) {
|
switch t := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
|||||||
@@ -28,3 +28,20 @@ func TestBuildSnapshot(t *testing.T) {
|
|||||||
t.Fatalf("resources %#v", snap.Resources)
|
t.Fatalf("resources %#v", snap.Resources)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOfficialFeeFields(t *testing.T) {
|
||||||
|
balance := []byte(`{
|
||||||
|
"newVersion": true,
|
||||||
|
"curntbalancecust": "261.09",
|
||||||
|
"canusefeecust": "731.41",
|
||||||
|
"realfeecust": "470.32",
|
||||||
|
"realfeecustnew": "361.00",
|
||||||
|
"newCarryForwardFromLastMonth": "453.88",
|
||||||
|
"carryForwardFromLastMonth": "563.20",
|
||||||
|
"newDepositForTheMonth": "168.21"
|
||||||
|
}`)
|
||||||
|
snap := BuildSnapshot("", balance, nil)
|
||||||
|
if snap.Balance != "261.09" || snap.MonthFee != "361.00" || snap.CarryOver != "453.88" || snap.MonthIn != "168.21" {
|
||||||
|
t.Fatalf("%#v", snap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
package unicom
|
package unicom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestPhoneFromPIW(t *testing.T) {
|
||||||
|
raw := url.QueryEscape(`{"rme":{"u":"13800000000"}}`)
|
||||||
|
if phoneFromPIW(raw) != "13800000000" {
|
||||||
|
t.Fatal(phoneFromPIW(raw))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestJSONPCallbackName(t *testing.T) {
|
func TestJSONPCallbackName(t *testing.T) {
|
||||||
name := jsonpCallback()
|
name := jsonpCallback()
|
||||||
if !strings.HasPrefix(name, "jQuery") || !strings.Contains(name, "_") {
|
if !strings.HasPrefix(name, "jQuery") || !strings.Contains(name, "_") {
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ func (a *App) qrPoll(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !status.Waiting && !status.Expired {
|
if !status.Waiting && !status.Expired {
|
||||||
a.acceptLogin("")
|
a.acceptLogin(status.Result.Phone)
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
"ok": true,
|
"ok": true,
|
||||||
|
|||||||
+6
-6
@@ -83,10 +83,10 @@
|
|||||||
</section>
|
</section>
|
||||||
<section id="home" hidden>
|
<section id="home" hidden>
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
<div class="stat"><span>可用余额</span><b id="balance">-</b></div>
|
<div class="stat"><span>剩余话费</span><b id="balance">-</b></div>
|
||||||
<div class="stat"><span>实时话费</span><b id="monthFee">-</b></div>
|
<div class="stat"><span>本月已消费</span><b id="monthFee">-</b></div>
|
||||||
<div class="stat"><span>剩余流量</span><b id="dataRemain">-</b></div>
|
<div class="stat"><span>上月结转</span><b id="carryOver">-</b></div>
|
||||||
<div class="stat"><span>剩余语音</span><b id="voiceRemain">-</b></div>
|
<div class="stat"><span>本月存入</span><b id="monthIn">-</b></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div id="pkg" class="hint"></div>
|
<div id="pkg" class="hint"></div>
|
||||||
@@ -153,8 +153,8 @@ function render(view) {
|
|||||||
if (view.error && !view.loggedIn) setMsg(view.error, false);
|
if (view.error && !view.loggedIn) setMsg(view.error, false);
|
||||||
$("balance").textContent = view.balance || "-";
|
$("balance").textContent = view.balance || "-";
|
||||||
$("monthFee").textContent = view.monthFee || "-";
|
$("monthFee").textContent = view.monthFee || "-";
|
||||||
$("dataRemain").textContent = view.dataRemain || "-";
|
$("carryOver").textContent = view.carryOver || "-";
|
||||||
$("voiceRemain").textContent = view.voiceRemain ? view.voiceRemain + " 分钟" : "-";
|
$("monthIn").textContent = view.monthIn || "-";
|
||||||
const who = [view.phoneMasked, view.packageName].filter(Boolean).join(" · ");
|
const who = [view.phoneMasked, view.packageName].filter(Boolean).join(" · ");
|
||||||
$("pkg").textContent = who;
|
$("pkg").textContent = who;
|
||||||
$("pollMinutes").value = view.pollMinutes || 30;
|
$("pollMinutes").value = view.pollMinutes || 30;
|
||||||
|
|||||||
Reference in New Issue
Block a user