1253 lines
62 KiB
C#
1253 lines
62 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.Data.SqlClient;
|
|
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 string urlStart = "https://api.baiwangjs.com/swgx-saas/swgxpt-shishi-cpsbmk/v2";
|
|
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 = $"{urlStart}/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 = $"{urlStart}/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 (!string.IsNullOrEmpty(addTag) && !addTag.Equals("0"))
|
|
{
|
|
continue;
|
|
}
|
|
JObject bizDataJObject = new JObject();
|
|
bizDataJObject.Add("name", detailRow.Table.Columns.Contains("name") ? detailRow["name"] + "" : "");
|
|
bizDataJObject.Add("idType", detailRow.Table.Columns.Contains("idType") ? detailRow["idType"] + "" : "");
|
|
bizDataJObject.Add("idNumber", detailRow.Table.Columns.Contains("idNumber") ? detailRow["idNumber"] + "" : "");
|
|
bizDataJObject.Add("sex", detailRow.Table.Columns.Contains("sex") ? detailRow["sex"] + "" : "");
|
|
bizDataJObject.Add("birthday", detailRow.Table.Columns.Contains("birthday") ? detailRow["birthday"] + "" : "");
|
|
string employType = detailRow.Table.Columns.Contains("employType") ? detailRow["employType"] + "" : "";
|
|
bizDataJObject.Add("employType", employType);
|
|
if (employType.Equals("雇员"))
|
|
{
|
|
bizDataJObject.Add("employedDate", detailRow.Table.Columns.Contains("employedDate") ? detailRow["employedDate"] + "" : "");
|
|
}
|
|
else if (employType.Equals("其他"))
|
|
{
|
|
bizDataJObject.Add("taxRelatedMatters", detailRow.Table.Columns.Contains("taxRelatedMatters") ? detailRow["taxRelatedMatters"] + "" : "");
|
|
}
|
|
bizDataJObject.Add("phoneNumber", detailRow.Table.Columns.Contains("phoneNumber") ? detailRow["phoneNumber"] + "" : "");
|
|
bizDataJObject.Add("isDeductExpense", detailRow.Table.Columns.Contains("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();
|
|
WriteLogInfo("同步人员", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 = $"{urlStart}/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();
|
|
WriteLogInfo("查询人员报送情况", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 = $"{urlStart}/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();
|
|
WriteLogInfo("同步专项附加", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 = $"{urlStart}/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();
|
|
WriteLogInfo("查询专项附加", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 = $"{urlStart}/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();
|
|
WriteLogInfo("发起养老金查询", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 = $"{urlStart}/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();
|
|
WriteLogInfo("获取养老金明细", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 = $"{urlStart}/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();
|
|
WriteLogInfo("个税申报", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 InvalidSubmit(out string resultRead, out string resultMsg)
|
|
{
|
|
string code = "-9999";
|
|
resultRead = "";
|
|
resultMsg = "";
|
|
try
|
|
{
|
|
string url = $"{urlStart}/web/sbmk/personal-tax/api/v1/invalid/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();
|
|
WriteLogInfo("个税申报作废", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 = $"{urlStart}/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();
|
|
WriteLogInfo("个税申报查询", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 GetIncome(out string resultRead, out string resultMsg)
|
|
{
|
|
string code = "-9999";
|
|
resultRead = "";
|
|
resultMsg = "";
|
|
try
|
|
{
|
|
string url = $"{urlStart}/web/sbmk/personal-tax/api/v1/syn/income";
|
|
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("qysh", mainRow["qysh"] + "");
|
|
pmsJObject.Add("operator", mainRow["operator"] + "");
|
|
pmsJObject.Add("skssqQ", mainRow["skssqQ"] + "");
|
|
pmsJObject.Add("skssqZ", mainRow["skssqZ"] + "");
|
|
JArray bizDataListJArry = new JArray();
|
|
JArray incomeDataListJArry = new JArray();
|
|
var groupedRows = detailTab.AsEnumerable().Where(row => (row["p_emp_addTag"] + "") == "1").GroupBy(row => row["incomeTypeCode"] + "");
|
|
foreach (var group in groupedRows)
|
|
{
|
|
JObject bizDataJObject = new JObject();
|
|
string typeCode = group.Key; //当前的分组编码
|
|
foreach (DataRow detailRow in group)
|
|
{
|
|
JObject incomeDataJObject = new JObject();
|
|
incomeDataJObject.Add("name", detailRow["name"] + "");
|
|
incomeDataJObject.Add("idType", detailRow["idType"] + "");
|
|
incomeDataJObject.Add("idNumber", detailRow["idNumber"] + "");
|
|
incomeDataJObject.Add("income", detailRow["income"] + "");
|
|
JObject externFieldsJObject = new JObject();
|
|
if (typeCode.Equals("101060100010100"))
|
|
{
|
|
externFieldsJObject.Add("endowmentInsurance", detailRow["endowmentInsurance"] + "");
|
|
externFieldsJObject.Add("medicalInsurance", detailRow["medicalInsurance"] + "");
|
|
externFieldsJObject.Add("unemploymentInsurance", detailRow["unemploymentInsurance"] + "");
|
|
externFieldsJObject.Add("housingFund", detailRow["housingFund"] + "");
|
|
}
|
|
else if (typeCode.Equals("101060100010300"))
|
|
{
|
|
externFieldsJObject.Add("sfkcjcfy", detailRow["sfkcjcfy"] + "");
|
|
externFieldsJObject.Add("employedDate", detailRow["employedDate"] + "");
|
|
}
|
|
else if (typeCode.Equals("101060100010400"))
|
|
{
|
|
|
|
}
|
|
else if (typeCode.Equals("101060100010500"))
|
|
{
|
|
externFieldsJObject.Add("sdxmdm", detailRow["sdxmdm"] + "");
|
|
}
|
|
incomeDataJObject.Add("externFields", externFieldsJObject);
|
|
incomeDataListJArry.Add(incomeDataJObject);
|
|
}
|
|
bizDataJObject.Add("incomeTypeCode", typeCode);
|
|
bizDataJObject.Add("incomeDataList", incomeDataListJArry);
|
|
bizDataListJArry.Add(bizDataJObject);
|
|
}
|
|
pmsJObject.Add("bizDataList", bizDataListJArry);
|
|
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
|
|
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
|
|
WriteLogInfo("同步收入", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 GetBatch(out string resultRead, string nsrlxdm, string incomeTypeCode, out string resultMsg)
|
|
{
|
|
string code = "-9999";
|
|
resultRead = "";
|
|
resultMsg = "";
|
|
try
|
|
{
|
|
string url = $"{urlStart}/web/sbmk/personal-tax/api/v1/gen/batch";
|
|
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("qysh", mainRow["qysh"] + "");
|
|
pmsJObject.Add("ysyf", mainRow["ysyf"] + "");
|
|
pmsJObject.Add("nsrlxdm", nsrlxdm);
|
|
pmsJObject.Add("incomeTypeCode", incomeTypeCode);
|
|
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="nsrlxdm"></param>
|
|
/// <param name="resultMsg"></param>
|
|
/// <returns></returns>
|
|
public static string GetCompute(out string resultRead, string nsrlxdm, out string resultMsg)
|
|
{
|
|
string code = "-9999";
|
|
resultRead = "";
|
|
resultMsg = "";
|
|
try
|
|
{
|
|
string url = $"{urlStart}/web/sbmk/personal-tax/api/v1/compute";
|
|
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("qysh", mainRow["qysh"] + "");
|
|
pmsJObject.Add("operator", mainRow["operator"] + "");
|
|
pmsJObject.Add("skssqQ", mainRow["skssqQ"] + "");
|
|
pmsJObject.Add("skssqZ", mainRow["skssqZ"] + "");
|
|
pmsJObject.Add("incomeTypeCode", mainRow["incomeTypeCode"] + "");
|
|
pmsJObject.Add("nsrlxDm", nsrlxdm);
|
|
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
|
|
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
|
|
WriteLogInfo("计算税款", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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="incomeTypeCode"></param>
|
|
/// <param name="resultMsg"></param>
|
|
/// <returns></returns>
|
|
public static string GetResult(out string resultRead, string nsrlxdm, out string resultMsg)
|
|
{
|
|
string code = "-9999";
|
|
resultRead = "";
|
|
resultMsg = "";
|
|
try
|
|
{
|
|
string url = $"{urlStart}/web/sbmk/personal-tax/api/v1/compute/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("qysh", mainRow["qysh"] + "");
|
|
pmsJObject.Add("skssqQ", mainRow["skssqQ"] + "");
|
|
pmsJObject.Add("skssqZ", mainRow["skssqZ"] + "");
|
|
pmsJObject.Add("nsrlxDm", nsrlxdm);
|
|
HttpWebResponse webResponse = HttpTools.Post(url, JsonConvert.SerializeObject(pmsJObject), null, headerDic, HttpTools.Method.POST);
|
|
resultRead = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
|
|
WriteLogInfo("获取税款计算结果", JsonConvert.SerializeObject(pmsJObject), resultRead);
|
|
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 = new HMACSHA256(keyBytes))
|
|
{
|
|
byte[] hashValue = hmacsha256.ComputeHash(valueBytes);
|
|
rtnValue = Convert.ToBase64String(hashValue);
|
|
}
|
|
return rtnValue;
|
|
}
|
|
/// <summary>
|
|
/// MD5加密
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public static string GetMD5Hash(string input)
|
|
{
|
|
if (string.IsNullOrEmpty(input))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
using (MD5 md5 = MD5.Create())
|
|
{
|
|
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
|
|
byte[] hashBytes = md5.ComputeHash(inputBytes);
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int i = 0; i < hashBytes.Length; i++)
|
|
{
|
|
sb.Append(hashBytes[i].ToString("x2"));
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 修改表结构
|
|
/// </summary>
|
|
/// <param name="tableName"></param>
|
|
/// <param name="colName"></param>
|
|
/// <param name="type"></param>
|
|
public static bool AlterTable(string tableName, string colName, string colType)
|
|
{
|
|
bool isResult;
|
|
try
|
|
{
|
|
if (!BaseImpl.HasExistsColumn(tableName, colName))
|
|
{
|
|
SqlHelper.ExecuteNonQuery(string.Format("alter table {0} add {1} {2}", tableName, colName, colType));
|
|
}
|
|
isResult = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
isResult = false;
|
|
}
|
|
return isResult;
|
|
}
|
|
/// <summary>
|
|
/// 判断表是否存在
|
|
/// </summary>
|
|
public static void EssentialTabExists()
|
|
{
|
|
string sql = @"IF OBJECT_ID(N'[dbo].[p_EssentialLogTab]', N'U') IS NULL
|
|
BEGIN
|
|
CREATE TABLE [dbo].[p_EssentialLogTab]
|
|
(
|
|
[Id] INT IDENTITY(1,1) NOT NULL,
|
|
[title] NVARCHAR(255) NULL,
|
|
[data] NVARCHAR(MAX) NULL,
|
|
[datetime] DATETIME NOT NULL DEFAULT(GETDATE()),
|
|
[rtnmsg] NVARCHAR(MAX) NULL,
|
|
|
|
CONSTRAINT [PK_p_EssentialLogTab] PRIMARY KEY CLUSTERED ([Id] ASC)
|
|
);
|
|
END";
|
|
SqlHelper.ExecuteNonQuery(sql);
|
|
}
|
|
/// <summary>
|
|
/// 写入日志信息
|
|
/// </summary>
|
|
public static void WriteLogInfo(string title, string data, string rtnmsg)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"
|
|
INSERT INTO [dbo].[p_EssentialLogTab]
|
|
(
|
|
[title],
|
|
[data],
|
|
[rtnmsg]
|
|
)
|
|
VALUES
|
|
(
|
|
@title,
|
|
@data,
|
|
@rtnmsg
|
|
);";
|
|
|
|
SqlParameter[] parameters =
|
|
{
|
|
new SqlParameter("@title", SqlDbType.NVarChar, 255)
|
|
{
|
|
Value = title
|
|
},
|
|
new SqlParameter("@data", SqlDbType.NVarChar, -1)
|
|
{
|
|
Value = data.Replace("'","''")
|
|
},
|
|
new SqlParameter("@rtnmsg", SqlDbType.NVarChar, -1)
|
|
{
|
|
Value = rtnmsg.Replace("'","''")
|
|
}
|
|
};
|
|
SqlHelper.ExecuteNonQuery(CommandType.Text, sql, parameters);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|