[Quicker] 昵图网共享分查询 - 源码归档

动作:昵图网共享分查询

自动登录昵图网并查询账户的共享分、原创分等资产信息

更新时间:2025-12-31 16:49
原始文件:昵图网共享分查询.cs

核心代码

using System;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Windows;
using Quicker.Public;

public static void Exec(IStepContext context)
{
    var stopwatch = Stopwatch.StartNew();
    
    string userName = context.GetVarValue("userName")?.ToString() ?? "";
    string password = context.GetVarValue("password")?.ToString() ?? "";
    
    if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
    {
        MessageBox.Show("请在动作变量中配置用户名和密码!", "昵图网查询", MessageBoxButton.OK, MessageBoxImage.Warning);
        context.SetVarValue("rtn", "配置错误");
        return;
    }
    
    try
    {
        var result = QueryNiPicPoints(userName, password, stopwatch);
        context.SetVarValue("rtn", result);
    }
    catch (Exception ex)
    {
        stopwatch.Stop();
        context.SetVarValue("rtn", $"错误: {ex.Message}");
        context.SetVarValue("errMessage", ex.ToString());
    }
}

static string QueryNiPicPoints(string userName, string password, Stopwatch stopwatch)
{
    var cookieContainer = new CookieContainer();
    var handler = new HttpClientHandler
    {
        CookieContainer = cookieContainer,
        UseCookies = true,
        AllowAutoRedirect = true
    };
    
    using (var client = new HttpClient(handler))
    {
        client.Timeout = TimeSpan.FromSeconds(30);
        
        // Step 1: 获取登录页面,提取 CSRF 令牌
        string loginPageUrl = "https://login.nipic.com/";
        
        var pageRequest = new HttpRequestMessage(HttpMethod.Get, loginPageUrl);
        pageRequest.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36");
        pageRequest.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        pageRequest.Headers.Add("Accept-Language", "zh-CN,zh;q=0.9");
        
        var pageResponse = client.SendAsync(pageRequest).Result;
        string html = pageResponse.Content.ReadAsStringAsync().Result;
        
        // 提取 CSRF 令牌
        string csrfToken = "";
        int csrfIndex = html.IndexOf("_csrf");
        if (csrfIndex >= 0)
        {
            string sub = html.Substring(csrfIndex, Math.Min(100, html.Length - csrfIndex));
            var match = Regex.Match(sub, @"['""]([a-f0-9-]{36})['""]");
            if (match.Success)
            {
                csrfToken = match.Groups[1].Value;
            }
        }
        
        if (string.IsNullOrEmpty(csrfToken))
        {
            return "错误: 无法获取 CSRF 令牌";
        }
        
        // Step 2: 提交登录请求
        string loginApi = "https://login.nipic.com/account/login";
        
        var formData = new Dictionary<string, string>
        {
            { "userName", userName },
            { "passWord", password },
            { "_csrf", csrfToken },
            { "rememberMe", "0" }
        };
        var content = new FormUrlEncodedContent(formData);
        
        var loginRequest = new HttpRequestMessage(HttpMethod.Post, loginApi);
        loginRequest.Content = content;
        loginRequest.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36");
        loginRequest.Headers.Add("Accept", "*/*");
        loginRequest.Headers.Add("Accept-Language", "zh-CN,zh;q=0.9");
        loginRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
        loginRequest.Headers.Add("Origin", "https://login.nipic.com");
        loginRequest.Headers.Referrer = new Uri("https://login.nipic.com/");
        
        var loginResponse = client.SendAsync(loginRequest).Result;
        string loginResult = loginResponse.Content.ReadAsStringAsync().Result;
        
        // 检查是否需要验证码 (code: 1009)
        if (loginResult.Contains("\"code\":1009") || loginResult.Contains("\"code\": 1009"))
        {
            var result = MessageBox.Show(
                " 登录频率过高,触发了验证码保护!\n\n" +
                "请在浏览器中手动登录一次以解除限制。\n\n" +
                "点击【是】打开登录页面,【否】取消操作。",
                "需要手动验证",
                MessageBoxButton.YesNo,
                MessageBoxImage.Warning
            );
            
            if (result == MessageBoxResult.Yes)
            {
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
                {
                    FileName = "https://login.nipic.com/",
                    UseShellExecute = true
                });
            }
            
            return "需要验证码,请在浏览器中登录后重试";
        }
        
        // 检查登录是否成功
        bool loginSuccess = loginResult.Contains("\"code\":0") || loginResult.Contains("\"code\": 0");
        
        if (!loginSuccess)
        {
            var msgMatch = Regex.Match(loginResult, @"""message""\s*:\s*""([^""]+)""");
            string errorMsg = msgMatch.Success ? msgMatch.Groups[1].Value : "未知错误";
            return $"登录失败: {errorMsg}";
        }
        
        // Step 3: 获取共享分数据
        string pointsUrl = "https://user.nipic.com/gxfen/list?pageIndex=1&pageSize=20";
        
        var pointsRequest = new HttpRequestMessage(HttpMethod.Get, pointsUrl);
        pointsRequest.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36");
        pointsRequest.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
        pointsRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
        pointsRequest.Headers.Referrer = new Uri("https://user.nipic.com/gxfen/page");
        
        var pointsResponse = client.SendAsync(pointsRequest).Result;
        string pointsData = pointsResponse.Content.ReadAsStringAsync().Result;
        
        // 解析分数
        var gxfenMatch = Regex.Match(pointsData, @"""Gxfen""\s*:\s*(\d+)");
        var ycfenMatch = Regex.Match(pointsData, @"""Ycfen""\s*:\s*(\d+)");
        var uidMatch = Regex.Match(pointsData, @"""uid""\s*:\s*(\d+)");
        
        int gxfen = gxfenMatch.Success ? int.Parse(gxfenMatch.Groups[1].Value) : 0;
        int ycfen = ycfenMatch.Success ? int.Parse(ycfenMatch.Groups[1].Value) : 0;
        string uid = uidMatch.Success ? uidMatch.Groups[1].Value : "未知";
        
        stopwatch.Stop();
        long elapsedMs = stopwatch.ElapsedMilliseconds;
        
        if (gxfen == 0 && ycfen == 0)
        {
            return $"数据异常: {(pointsData.Length > 300 ? pointsData.Substring(0, 300) : pointsData)}";
        }
        
        string resultText = $@"╔══════════════════════════════╗
║       昵图网账户资产         ║
╠══════════════════════════════╣
║ 账户 ID    : {uid,-16}║
║ 共享分     : {gxfen,-16}║
║ 原创分     : {ycfen,-16}║
║ 账户总分   : {gxfen + ycfen,-16}║
╠══════════════════════════════╣
║ ⏱️ 耗时    : {elapsedMs + " 毫秒",-16}║
╚══════════════════════════════╝";
        
        MessageBox.Show(resultText, "昵图网共享分查询", MessageBoxButton.OK, MessageBoxImage.Information);
        
        return $"共享分:{gxfen} 原创分:{ycfen} 总分:{gxfen + ycfen} | 耗时:{elapsedMs}ms";
    }
}

动作配置 (JSON)

{
  "ActionId": "38d23af9-9ac3-4ab5-9a97-2219544354f5",
  "Title": "昵图网共享分查询",
  "Description": "自动登录昵图网并查询账户的共享分、原创分等资产信息",
  "Icon": "fa:Solid_Donate:#FF941F5C",
  "Variables": [
    {
      "Key": "text",
      "IsLocked": false,
      "Type": 0,
      "Desc": "结果文本(自动)",
      "DefaultValue": null,
      "SaveState": false,
      "IsInput": false,
      "IsOutput": false,
      "ParamName": null,
      "InputParamInfo": null,
      "OutputParamInfo": null,
      "TableDef": null,
      "CustomType": null,
      "Group": null
    },
    {
      "Key": "rtn",
      "IsLocked": false,
      "Type": 0,
      "Desc": "返回值(自动)",
      "DefaultValue": null,
      "SaveState": false,
      "IsInput": false,
      "IsOutput": false,
      "ParamName": null,
      "InputParamInfo": null,
      "OutputParamInfo": null,
      "TableDef": null,
      "CustomType": null,
      "Group": null
    },
    {
      "Key": "errMessage",
      "IsLocked": false,
      "Type": 0,
      "Desc": "错误信息(自动)",
      "DefaultValue": null,
      "SaveState": false,
      "IsInput": false,
      "IsOutput": false,
      "ParamName": null,
      "InputParamInfo": null,
      "OutputParamInfo": null,
      "TableDef": null,
      "CustomType": null,
      "Group": null
    },
    {
      "Key": "silent",
      "IsLocked": false,
      "Type": 2,
      "Desc": "静默启动",
      "DefaultValue": "true",
      "SaveState": false,
      "IsInput": false,
      "IsOutput": false,
      "ParamName": null,
      "InputParamInfo": null,
      "OutputParamInfo": null,
      "TableDef": null,
      "CustomType": null,
      "Group": null
    },
    {
      "Type": 0,
      "Desc": "用户名",
      "IsOutput": false,
      "DefaultValue": "请输入",
      "Key": "userName"
    },
    {
      "Type": 0,
      "Desc": "密码",
      "IsOutput": false,
      "DefaultValue": "输入",
      "Key": "password"
    }
  ],
  "References": []
}

使用方法

  1. 确保您已安装 动作构建 (Action Builder) 动作。
  2. 将本文提供的 .cs.json 文件下载到同一目录
  3. 选中 .json 文件,运行「动作构建」即可生成并安装动作。
posted @ 2025-12-31 16:49  luoluoluo22  阅读(11)  评论(0)    收藏  举报