黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Shared.Common;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone
{
    /// <summary>
    /// 其他没法分类的功能的逻辑
    /// </summary>
    public class HdlOtherFunctionLogic
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 其他没法分类的功能的逻辑
        /// </summary>
        private static HdlOtherFunctionLogic m_Current = null;
        /// <summary>
        /// 其他没法分类的功能的逻辑
        /// </summary>
        public static HdlOtherFunctionLogic Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new HdlOtherFunctionLogic();
                }
                return m_Current;
            }
        }
 
        #endregion
 
        #region ■ 经纬度_____________________________
 
        /// <summary>
        /// 添加App的经纬度上报事件
        /// </summary>
        public void AddAppLatAndLonEvent()
        {
            Application.LocationAction += (lon, lat) =>
            {
                //GPS坐标转成高德坐标
                double out_lng, out_lat;
                HdlGpsLocationConvertLogic.Current.WGS84_to_GCJ02(lon, lat, out out_lng, out out_lat);
                //上报经纬度
                this.ReceiveAppLatAndLon(out_lng.ToString(), out_lat.ToString());
            };
        }
 
        /// <summary>
        /// App的经纬度上报
        /// </summary>
        /// <param name="lat"></param>
        /// <param name="lon"></param>
        private void ReceiveAppLatAndLon(string lon, string lat)
        {
            if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
            {
                //如果已经退出登陆的话
                return;
            }
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //经纬度上报采用mqtt的方式上报
                try
                {
                    //发送主题
                    string strTopic = "/ClientToCloud/" + Config.Instance.Guid + "/Report/Location";
                    //发送数据
                    var dic = new Dictionary<string, string>();
                    dic["lon"] = lon;
                    dic["lat"] = lat;
                    var byteData = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(dic));
 
                    await ZbGateway.RemoteMqttClient?.PublishAsync(new MQTTnet.MqttApplicationMessage { Topic = strTopic, Payload = byteData, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }
                    , System.Threading.CancellationToken.None);
 
                    if (HdlUserCenterResourse.HideOption.WriteGpsPoint == 1)
                    {
                        string txtvalue = "lon:" + lon + " lat:" + lat;
                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, txtvalue);
                        HdlLogLogic.Current.WriteLog(-1, "经纬度上报  " + txtvalue);
                    }
                }
                catch { };
            }, ShowErrorMode.NO);
        }
 
        #endregion
    }
}