增加苏州接口数据推送

This commit is contained in:
liuzl 2023-01-09 15:14:06 +08:00
parent 6eee371cdf
commit 0ff57d952d
7 changed files with 110 additions and 94 deletions

View File

@ -1,9 +1,6 @@
using Nirvana.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Waste.Application.SubscribeInfo;
namespace Waste.Application
{
@ -53,5 +50,12 @@ namespace Waste.Application
/// <param name="input"></param>
/// <returns></returns>
Task<PageParms<ResultListByEquS2CDto>> GetListByEquAsync(ResultListByEquC2SDto input);
/// <summary>
/// 给第三方推送消息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task SendMessageToThird(SendThirdMessageSubscribeS2SDto input);
}
}

View File

@ -1,9 +1,6 @@
using DotNetCore.CAP;
using Furion;
using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.RemoteRequest.Extensions;
using Furion.TaskScheduler;
using Mapster;
using Nirvana.Common;
using SqlSugar;
@ -449,7 +446,7 @@ namespace Waste.Application
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
private async Task SendMessageToThird(SendThirdMessageSubscribeS2SDto input)
public async Task SendMessageToThird(SendThirdMessageSubscribeS2SDto input)
{
if (input.Weight <= 0)
{

View File

@ -1,8 +1,6 @@
using DotNetCore.CAP;
using Furion;
using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.Logging.Extensions;
using Furion.RemoteRequest.Extensions;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
@ -10,8 +8,6 @@ using Newtonsoft.Json;
using Nirvana.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Waste.Application.ThirdApiInfo;

View File

@ -215,6 +215,17 @@ namespace Waste.Application.ThirdApiInfo
wastetype = type,
weight = weight
});
//推送数据给第三方
await _resultService.SendMessageToThird(new SendThirdMessageSubscribeS2SDto
{
DeviceId = device.Id,
WasteSType = "",
Time = DateTime.Now,
TrashCode = returndata.trash,
WasteType = type,
Weight = weight.ToDecimal()
});
}
else
{
@ -238,38 +249,6 @@ namespace Waste.Application.ThirdApiInfo
}
}
/// <summary>
/// 16进制转汉字
/// </summary>
/// <param name="hex"></param>
/// <returns></returns>
private string GetChsFromHex(string hex)
{
if (hex == null)
return "";
if (hex.Length % 2 != 0)
{
hex += "20";//空格
}
// 需要将 hex 转换成 byte 数组。
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
try
{
// 每两个字符是一个 byte。
bytes[i] = byte.Parse(hex.Substring(i * 2, 2),
System.Globalization.NumberStyles.HexNumber);
}
catch
{
}
}
// 获得 GB2312Chinese Simplified。
Encoding chs = Encoding.GetEncoding("gb2312");
return chs.GetString(bytes);
}
/// <summary>
/// 16进制转10进制
/// </summary>
@ -377,40 +356,6 @@ namespace Waste.Application.ThirdApiInfo
return new ResultInfo(ResultState.SUCCESS, "success", data);
}
private int TrashType(string type)
{
if (type == "厨余垃圾") return 1;
else if (type == "可回收物") return 2;
else if (type == "有害垃圾") return 3;
else if (type == "其他垃圾") return 4;
else return 0;
}
private int GetTimestamp(DateTime time)
{
DateTime dateTimeStart = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));
int timestamp = Convert.ToInt32((time - dateTimeStart).TotalSeconds);
return timestamp;
}
/// <summary>
/// 字节数组转16进制
/// </summary>
/// <param name="bt"></param>
/// <returns></returns>
private string BytesToHexStr(byte[] bt)
{
string returnStr = "";
if (bt != null)
{
for (int i = 0; i < bt.Length; i++)
{
returnStr += bt[i].ToString("X2");
}
}
return returnStr;
}
/// <summary>
/// 更新设备版本信息
/// </summary>
@ -497,6 +442,72 @@ namespace Waste.Application.ThirdApiInfo
return returndata;
}
/// <summary>
/// 16进制转汉字
/// </summary>
/// <param name="hex"></param>
/// <returns></returns>
private string GetChsFromHex(string hex)
{
if (hex == null)
return "";
if (hex.Length % 2 != 0)
{
hex += "20";//空格
}
// 需要将 hex 转换成 byte 数组。
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
try
{
// 每两个字符是一个 byte。
bytes[i] = byte.Parse(hex.Substring(i * 2, 2),
System.Globalization.NumberStyles.HexNumber);
}
catch
{
}
}
// 获得 GB2312Chinese Simplified。
Encoding chs = Encoding.GetEncoding("gb2312");
return chs.GetString(bytes);
}
private int TrashType(string type)
{
if (type == "厨余垃圾") return 1;
else if (type == "可回收物") return 2;
else if (type == "有害垃圾") return 3;
else if (type == "其他垃圾") return 4;
else return 0;
}
private int GetTimestamp(DateTime time)
{
DateTime dateTimeStart = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));
int timestamp = Convert.ToInt32((time - dateTimeStart).TotalSeconds);
return timestamp;
}
/// <summary>
/// 字节数组转16进制
/// </summary>
/// <param name="bt"></param>
/// <returns></returns>
private string BytesToHexStr(byte[] bt)
{
string returnStr = "";
if (bt != null)
{
for (int i = 0; i < bt.Length; i++)
{
returnStr += bt[i].ToString("X2");
}
}
return returnStr;
}
/// <summary>
/// wifi数据解析
/// </summary>

View File

@ -2106,6 +2106,13 @@
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Waste.Application.IResultService.SendMessageToThird(Waste.Application.SubscribeInfo.SendThirdMessageSubscribeS2SDto)">
<summary>
给第三方推送消息
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Waste.Application.ResultInfos.ResultAppService">
<summary>
投放记录
@ -3330,13 +3337,6 @@
<param name="data"></param>
<returns></returns>
</member>
<member name="M:Waste.Application.ThirdApiInfo.OpenService.GetChsFromHex(System.String)">
<summary>
16进制转汉字
</summary>
<param name="hex"></param>
<returns></returns>
</member>
<member name="M:Waste.Application.ThirdApiInfo.OpenService.HextToDec(System.String)">
<summary>
16进制转10进制
@ -3358,13 +3358,6 @@
<param name="ecode"></param>
<returns></returns>
</member>
<member name="M:Waste.Application.ThirdApiInfo.OpenService.BytesToHexStr(System.Byte[])">
<summary>
字节数组转16进制
</summary>
<param name="bt"></param>
<returns></returns>
</member>
<member name="M:Waste.Application.ThirdApiInfo.OpenService.UpdateVersionAsync(Waste.Application.SubscribeInfo.DeviceVerS2SDto)">
<summary>
更新设备版本信息
@ -3379,6 +3372,20 @@
<param name="data"></param>
<returns></returns>
</member>
<member name="M:Waste.Application.ThirdApiInfo.OpenService.GetChsFromHex(System.String)">
<summary>
16进制转汉字
</summary>
<param name="hex"></param>
<returns></returns>
</member>
<member name="M:Waste.Application.ThirdApiInfo.OpenService.BytesToHexStr(System.Byte[])">
<summary>
字节数组转16进制
</summary>
<param name="bt"></param>
<returns></returns>
</member>
<member name="M:Waste.Application.ThirdApiInfo.OpenService.AnalyProto(Waste.Application.ThirdApiInfo.WifiRequestC2SDto)">
<summary>
wifi数据解析

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,6 @@
<PropertyGroup>
<RazorPage_SelectedScaffolderID>RazorPageScaffolder</RazorPage_SelectedScaffolderID>
<RazorPage_SelectedScaffolderCategoryPath>root/Common/RazorPage</RazorPage_SelectedScaffolderCategoryPath>
<NameOfLastUsedPublishProfile>H:\liuzl_ybhdmob\Waste\Waste.Web.Entry\Properties\PublishProfiles\waste.ybhdmob.com.pubxml</NameOfLastUsedPublishProfile>
<NameOfLastUsedPublishProfile>E:\liuzl_ybhdmob\巨天垃圾分类\Waste\Waste.Web.Entry\Properties\PublishProfiles\waste.ybhdmob.com.pubxml</NameOfLastUsedPublishProfile>
</PropertyGroup>
</Project>