Files
lserp_cs_6.0/插件库/Lskj.QueryEssentialInfo/QueryApiUtil.cs
T
tdx 5e7a2d5590 SVN r1057
SVN-Revision: r1057
2025-11-28 02:34:06 +00:00

836 lines
41 KiB
C#

using Lskj.Business.Impl;
using Lskj.Control.BrowserSetting;
using Lskj.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace Lskj.QueryEssentialInfo
{
public static class QueryApiUtil
{
public static DataRow mainRow;
public static DataTable detailTab;
/// <summary>
/// 获取操作token
/// </summary>
public static void GetToken(ref string token, ref string aggOrgId)
{
token = "";
aggOrgId = "";
try
{
string url = "http://openapi.51fpcloud.com/v2/public/token";
HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
string client_id = mainRow["client_id"] + "";
string client_secret = mainRow["client_secret"] + "";
string authorization = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{client_id}:{client_secret}"));
headerDic.Add("Authorization", $"Basic {authorization}");
Dictionary<string, string> pmsDic = new Dictionary<string, string>();
pmsDic.Add("nsrsbh", mainRow["nsrsbh"] + "");
HttpWebResponse webResponse = HttpTools.Post(url, "", pmsDic, headerDic, HttpTools.Method.POST);
string result = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(result))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(result);
string code = resultJObject["code"] + "";
string msg = resultJObject["msg"] + "";
if (code.Equals("0"))
{
token = resultJObject["data"]["token"] + "";
aggOrgId = resultJObject["data"]["aggOrgId"] + "";
SqlHelper.ExecuteNonQuery(string.Format("update p_systemtab set queryEssentialToken = '{0}'", token));
SqlHelper.ExecuteNonQuery(string.Format("update p_systemtab set queryEssentialAggOrgId = '{0}'", aggOrgId));
}
else
{
throw new Exception($"获取token失败\r\n{msg}");
}
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 专项附加扣除查询
/// </summary>
/// <param name="token"></param>
/// <param name="result"></param>
/// <returns></returns>
public static string CheckPassword(ref string token, ref string aggOrgId, ref string accountId, ref string message)
{
string code = "-9999";
try
{
string url = "http://openapi.51fpcloud.com/v2/iit/check/checkPassword";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("token", token);
JObject pmsJObject = new JObject();
if (detailTab != null && detailTab.Rows.Count > 0)
{
pmsJObject.Add("aggOrgId", aggOrgId);
pmsJObject.Add("checkPassword", "Y");
pmsJObject.Add("nsrsbh", mainRow["nsrsbh"] + "");
pmsJObject.Add("qymc", mainRow["qymc"] + "");
pmsJObject.Add("mmlx", mainRow["mmlx"] + "");
pmsJObject.Add("sbmm", RsaEntryUtil.Encrypt(mainRow["sbmm"] + "", RsaEntryUtil.ToXmlPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+vuYMGtTU+42wwbaFX+PkCuSeoREKe5V4EJMi553Gc03ficUdpLHIFdEjAMHAxepwm3RAGLwyxYFK/S93k8GYMuV35L2Nj/cVeHS8scsdqXzqLUKaI4wj438OI6HDh7rWsw1M5EgMsoZvQqja53+SgD3mgIy3XyILbmA5jUp2IwIDAQAB")));
pmsJObject.Add("areaid", mainRow["areaid"] + "");
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
string resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
message = resultJObject["message"] + "";
if (code.Equals("2000"))
{
accountId = resultJObject["data"]["accountId"] + "";
}
}
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 专项附加扣除查询
/// </summary>
/// <param name="token"></param>
/// <param name="result"></param>
/// <returns></returns>
public static string QueryEssentialInfo(ref string token, ref string aggOrgId, ref string accountId, out string resultRead)
{
string code = "-9999";
resultRead = "";
try
{
string url = "http://openapi.51fpcloud.com/v2/iit/declare/queryEssentialInfo";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("token", token);
JObject pmsJObject = new JObject();
if (detailTab != null && detailTab.Rows.Count > 0)
{
pmsJObject.Add("aggOrgId", aggOrgId);
pmsJObject.Add("accountId", accountId);
pmsJObject.Add("skssq", mainRow["skssq"] + "");
JArray rylbJArray = new JArray();
{
foreach (DataRow detailRow in detailTab.Rows)
{
string addTag = detailRow["p_emp_addTag"] + "";
if (addTag.Equals("0"))
{
continue;
}
JObject rylbJObject = new JObject();
rylbJObject.Add("xm", detailRow["xm"] + "");
rylbJObject.Add("zzlx", detailRow["zzlx"] + "");
rylbJObject.Add("zzhm", detailRow["zzhm"] + "");
rylbJArray.Add(rylbJObject);
}
}
pmsJObject.Add("rylb", rylbJArray);
if (rylbJArray.Count > 0)
{
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
}
}
else
{
code = "-9998";
}
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 专项附加扣除查询反馈
/// </summary>
/// <param name="token"></param>
/// <param name="result"></param>
/// <returns></returns>
public static string QueryEssentialInfoFeedback(string taskId, ref string token, ref string aggOrgId, ref string accountId, out string resultRead)
{
string code = "-9999";
resultRead = "";
try
{
string url = "http://openapi.51fpcloud.com/v2/iit/declare/queryEssentialInfoFeedback";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("token", token);
JObject pmsJObject = new JObject();
pmsJObject.Add("aggOrgId", aggOrgId);
pmsJObject.Add("accountId", accountId);
pmsJObject.Add("taskId", taskId);
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 获取企业人员
/// </summary>
/// <param name="token"></param>
/// <param name="aggOrgId"></param>
/// <param name="accountId"></param>
/// <param name="resultRead"></param>
/// <returns></returns>
public static string QueryEssentialCompanyEmployee(ref string token, ref string aggOrgId, ref string accountId, out string resultRead)
{
string code = "-9999";
resultRead = "";
try
{
string url = "http://openapi.51fpcloud.com/v2/iit/data/getCompanyEmployee";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("token", token);
JObject pmsJObject = new JObject();
pmsJObject.Add("aggOrgId", aggOrgId);
pmsJObject.Add("accountId", accountId);
pmsJObject.Add("pageNo", "1");
pmsJObject.Add("pageSize", "100");
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 人员报送
/// </summary>
/// <param name="token"></param>
/// <param name="aggOrgId"></param>
/// <param name="accountId"></param>
/// <param name="resultRead"></param>
/// <returns></returns>
public static string QueryEssentialEmployeeInfo(ref string token, ref string aggOrgId, ref string accountId, out string resultRead)
{
string code = "-9999";
resultRead = "";
try
{
string url = "http://openapi.51fpcloud.com/v2/iit/declare/declareEmployeeInfo";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("token", token);
JObject pmsJObject = new JObject();
pmsJObject.Add("aggOrgId", aggOrgId);
pmsJObject.Add("accountId", accountId);
pmsJObject.Add("skssq", mainRow["skssq"] + "");
JArray rylbArray = new JArray();
foreach (DataRow detailRow in detailTab.Rows)
{
string addTag = detailRow["p_emp_addTag"] + "";
if (addTag.Equals("1"))
{
continue;
}
JObject rylbJObject = new JObject();
rylbJObject.Add("xm", detailRow["xm"] + "");
rylbJObject.Add("zzlx", detailRow["zzlx"] + "");
rylbJObject.Add("zzhm", detailRow["zzhm"] + "");
rylbJObject.Add("lxdh", detailRow["lxdh"] + "");
rylbJObject.Add("nsrzt", detailRow["nsrzt"] + "");
rylbJObject.Add("sfgy", detailRow["sfgy"] + "");
rylbJObject.Add("rzsgrq", detailRow["rzsgrq"] + "");
rylbJObject.Add("xb", detailRow["xb"] + "");
rylbJObject.Add("csny", detailRow["csny"] + "");
rylbJObject.Add("gj", detailRow["gj"] + "");
rylbJObject.Add("rydq", detailRow["rydq"] + "");
rylbArray.Add(rylbJObject);
}
pmsJObject.Add("rylb", rylbArray);
if (rylbArray.Count > 0)
{
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
}
}
else
{
code = "-9998";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 人员报送反馈
/// </summary>
/// <param name="token"></param>
/// <param name="aggOrgId"></param>
/// <param name="accountId"></param>
/// <param name="resultRead"></param>
/// <returns></returns>
public static string QueryEssentialEmployeeInfoFeedback(string taskId, ref string token, ref string aggOrgId, ref string accountId, out string resultRead)
{
string code = "-9999";
resultRead = "";
try
{
string url = "http://openapi.51fpcloud.com/v2/iit/declare/getEmployeeInfoFeedback";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
headerDic.Add("token", token);
JObject pmsJObject = new JObject();
pmsJObject.Add("aggOrgId", aggOrgId);
pmsJObject.Add("accountId", accountId);
pmsJObject.Add("taskId", taskId);
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 初始化
/// </summary>
public static string Init(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/gsmycsh";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("requestId", Guid.NewGuid().ToString().Replace("-", "").ToLower());
pmsJObject.Add("accountId", "1");
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 同步人员
/// </summary>
public static string Person(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/syn/person";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
JArray bizlistJArray = new JArray();
foreach (DataRow detailRow in detailTab.Rows)
{
string addTag = detailRow["p_emp_addTag"] + "";
if (addTag.Equals("1"))
{
continue;
}
JObject bizDataJObject = new JObject();
bizDataJObject.Add("name", detailRow["name"] + "");
bizDataJObject.Add("idType", detailRow["idType"] + "");
bizDataJObject.Add("idNumber", detailRow["idNumber"] + "");
bizDataJObject.Add("sex", detailRow["sex"] + "");
bizDataJObject.Add("birthday", detailRow["birthday"] + "");
bizDataJObject.Add("employType", detailRow["employType"] + "");
bizDataJObject.Add("employedDate", detailRow["employedDate"] + "");
bizDataJObject.Add("phoneNumber", detailRow["phoneNumber"] + "");
bizDataJObject.Add("isDeductExpense", detailRow["isDeductExpense"] + "");
bizlistJArray.Add(bizDataJObject);
}
pmsJObject.Add("bizDataList", bizlistJArray);
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 报送查询
/// </summary>
public static string PersonQuery(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/person/submit/query";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 同步专项附加
/// </summary>
public static string PostAddition(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/syn/special/addition";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
pmsJObject.Add("ysyf", mainRow["ysyf"] + "");
JArray idNumberjArray = new JArray();
foreach (DataRow detailRow in detailTab.Rows)
{
string addTag = detailRow["p_emp_addTag"] + "";
if (!addTag.Equals("1"))
{
continue;
}
string idNumber = detailRow["idNumber"] + "";
idNumberjArray.Add(idNumber);
}
pmsJObject.Add("idNumberList", idNumberjArray);
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 获取专项附加
/// </summary>
public static string GetAddition(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/acquire/special/addition";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
pmsJObject.Add("ysyf", mainRow["ysyf"] + "");
JArray idNumberjArray = new JArray();
foreach (DataRow detailRow in detailTab.Rows)
{
string addTag = detailRow["p_emp_addTag"] + "";
if (!addTag.Equals("1"))
{
continue;
}
string idNumber = detailRow["idNumber"] + "";
idNumberjArray.Add(idNumber);
}
pmsJObject.Add("idNumberList", idNumberjArray);
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 发起个人养老金查询
/// </summary>
/// <param name="resultRead"></param>
/// <param name="resultMsg"></param>
/// <returns></returns>
public static string GetYLJFQ(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/acquire/ylj/fqcx";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("requestId", Guid.NewGuid().ToString().Replace("-", "").ToLower());
pmsJObject.Add("accountId", "1");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
pmsJObject.Add("dknd", mainRow["dknd"] + "");
JArray idNumberjArray = new JArray();
foreach (DataRow detailRow in detailTab.Rows)
{
string addTag = detailRow["p_emp_addTag"] + "";
if (!addTag.Equals("1"))
{
continue;
}
string idNumber = detailRow["idNumber"] + "";
idNumberjArray.Add(idNumber);
}
pmsJObject.Add("idNumberList", idNumberjArray);
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 获取个人养老金明细
/// </summary>
public static string GetYLJMX(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/acquire/ylj/list";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("requestId", Guid.NewGuid().ToString().Replace("-", "").ToLower());
pmsJObject.Add("accountId", "1");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
pmsJObject.Add("dknd", mainRow["dknd"] + "");
JArray idNumberjArray = new JArray();
foreach (DataRow detailRow in detailTab.Rows)
{
string addTag = detailRow["p_emp_addTag"] + "";
if (!addTag.Equals("1"))
{
continue;
}
string idNumber = detailRow["idNumber"] + "";
idNumberjArray.Add(idNumber);
}
pmsJObject.Add("idNumberList", idNumberjArray);
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 个税申报
/// </summary>
/// <param name="resultRead"></param>
/// <param name="resultMsg"></param>
/// <returns></returns>
public static string Submit(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/submit";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
pmsJObject.Add("skssqQ", mainRow["skssqQ"] + "");
pmsJObject.Add("skssqZ", mainRow["skssqZ"] + "");
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 个税申报查询
/// </summary>
public static string SubmitQuery(out string resultRead, out string resultMsg)
{
string code = "-9999";
resultRead = "";
resultMsg = "";
try
{
string url = "http://swgxs.poc.htjs.net:9019/v2/web/sbmk/personal-tax/api/v1/submit/query";
HttpTools.setting("application/json", null, null, HttpTools.Encode.UTF8);
Dictionary<string, string> headerDic = new Dictionary<string, string>();
DateTime utcNow = DateTime.UtcNow;
string date = utcNow.ToString("r", CultureInfo.InvariantCulture);
string host = "api.baiwangjs.com";
string x_htjs_nonce = Guid.NewGuid().ToString().ToLower();
string x_htjs_ua = "1.8.0_181 64 bit, sdk-ver=1.0.0";
headerDic.Add("Date", DateTime.UtcNow.ToString());
headerDic.Add("host", host);
headerDic.Add("x-htjs-nonce", x_htjs_nonce);
headerDic.Add("x-htjs-ua", x_htjs_ua);
headerDic.Add("Authorization", $"{GetAuthorization(date, host, x_htjs_nonce, x_htjs_ua)}");
JObject pmsJObject = new JObject();
pmsJObject.Add("busiTypeCode", mainRow["busiTypeCode"] + "");
pmsJObject.Add("qysh", mainRow["qysh"] + "");
pmsJObject.Add("operator", mainRow["operator"] + "");
pmsJObject.Add("skssqQ", mainRow["skssqQ"] + "");
pmsJObject.Add("skssqZ", mainRow["skssqZ"] + "");
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
if (webResponse != null && !string.IsNullOrEmpty(resultRead))
{
JObject resultJObject = (JObject)JsonConvert.DeserializeObject(resultRead);
code = resultJObject["code"] + "";
resultMsg = resultJObject["msg"] + "";
}
}
catch (Exception)
{
throw;
}
return code;
}
/// <summary>
/// 获取Authorization
/// </summary>
public static string GetAuthorization(string date, string host, string x_htjs_nonce, string x_htjs_ua)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("POST /v2/cloud/queryUniqueSign HTTP/1.1");
stringBuilder.AppendLine($"date: {date}");
stringBuilder.AppendLine($"host: {host}");
stringBuilder.AppendLine($"x-htjs-nonce: {x_htjs_nonce}");
stringBuilder.AppendLine($"x-htjs-ua: {x_htjs_ua}");
string value = $"hmac username=\"{GetHmacSha256("", "")}\", algorithm=\"hmac-sha256\", headers=\"request-line date host x-htjs-nonce x-htjs-ua\", signature=\"{GetHmacSha256("", stringBuilder.ToString())}\"";
return value;
}
/// <summary>
/// 获取HmacSha256
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static string GetHmacSha256(string key, string value)
{
string rtnValue = "";
byte[] keyBytes = Encoding.UTF8.GetBytes(key);
byte[] valueBytes = Encoding.UTF8.GetBytes(value);
using (var hmacsha256 = n