季铭对接T+畅捷通,看板API
yl
2023-12-25 a0d937e939fc11713021a146b925cd7035d9a744
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using Dapper;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Web.Http;
using VueWebApi.Models;
using VueWebApi.Tools;
using VueWebApi.Util;
 
namespace VueWebApi.Controllers
{
    [RoutePrefix(prefix: "api/Message")]
    [ControllerGroup("T8授权管理", "在线接口")]
    public class MessageController : ApiController
    {
        public static ToMessage mes = new ToMessage(); //定义全局返回信息对象
 
        [Route(template: "OAuth")]
        [HttpGet]
        public string OAuth(string code, string state)
        {
            Console.WriteLine($"Code:{code}");
            LogHelper.WriteLogData("code:" + code);
            return code;
        }
 
        [Route(template: "Receive")]
        [HttpPost]
        public dynamic Receive([FromBody] ChanjetEncryptMsg encryptMsg)
        {
            string enMsg = encryptMsg.GetEncryptMsg();
            LogHelper.WriteLogData("解密前的消息enMsg:" + enMsg);
            Console.WriteLine($"解密前的消息{enMsg}");
            String decryptMsg = OpenapiHelper.AesDecrypt(enMsg, config.Key_encryptKey);
            LogHelper.WriteLogData2("解密后消息:" + decryptMsg);
            Console.WriteLine($"解密前的消息{enMsg}");
 
            MessageBase message = JsonConvert.DeserializeObject<MessageBase>(decryptMsg);
            object retObj = null;
            try
            {
                switch (message.msgType)
                {
                    case "APP_TEST":
                        LogHelper.WriteLogData("消息类型msgType:" + message.msgType);
                        retObj = DealTestMsg(message);
                        break;
                    case "APP_TICKET":
                        LogHelper.WriteLogData("消息类型msgType:" + message.msgType);
                        retObj = DealTicketMsg(message);
                        break;
                    case "TEMP_AUTH_CODE":
                        LogHelper.WriteLogData("消息类型msgType:" + message.msgType);
                        retObj = DealOrgTempAuthMsg(message);
                        break;
                    case "PAY_ORDER_SUCCESS":
                        LogHelper.WriteLogData("消息类型msgType:" + message.msgType);
                        retObj = DealOrderPayMsg(message);
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return retObj;
        }
 
        private object DealOrderPayMsg(MessageBase message)
        {
            //throw new NotImplementedException();
            Dictionary<string, string> dic = new Dictionary<string, string>
            {
                { "result","success"}
            };
            return dic;
        }
 
        private object DealOrgTempAuthMsg(MessageBase message)
        {
            LogHelper.WriteLogData("开始OrgTempAuthContent");
            OrgTempAuthContent content = JsonConvert.DeserializeObject<OrgTempAuthContent>(message.bizContent.ToString());
            Console.WriteLine($"OrgTempAuthCode:{content.tempAuthCode}");
            LogHelper.WriteLogData("结束OrgTempAuthContent");
            return $"OrgTempAuthCode:{content.tempAuthCode}";
        }
 
        private object DealTicketMsg(MessageBase message)
        {
            LogHelper.WriteLogData("开始AppTicket");
            AppTicketContent content = JsonConvert.DeserializeObject<AppTicketContent>(message.bizContent.ToString());
            LogHelper.WriteLogData($"AppTicket:{content.appTicket}");
            LogHelper.WriteLogData("结束AppTicket");
 
            var dynamicParams = new DynamicParameters();
            var sql = @"update T_AppTicket set AppTicket=@AppTicket,lm_date=@lm_date";
            dynamicParams.Add("@AppTicket", content.appTicket);
            dynamicParams.Add("@lm_date", DateTime.Now.ToString());
            int cont = DapperHelper.SQL(sql, dynamicParams);
            if (cont > 0)
            {
                Dictionary<string, string> dic = new Dictionary<string, string>
                {
                   { "result","success"}
                };
                return dic;
            }
            else
            {
                Dictionary<string, string> dic = new Dictionary<string, string>
                {
                   { "result","success"}
                };
                return dic;
            }
        }
 
        private object DealTestMsg(MessageBase message)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>
            {
                { "result","success"}
            };
            LogHelper.WriteLogData1(JsonConvert.SerializeObject(dic));
            return dic;
        }
 
        /// <summary>
        /// 获取AppTicket
        /// </summary>
        /// <returns></returns>
        [Route(template: "AppTicketSelect")]
        [HttpGet]
        public HttpResponseMessage AppTicketSelect()
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //获取车间下拉框数据
                sql = @"select *   from T_AppTicket ";
                var data = DapperHelper.selecttable(sql);
                if (data.Rows.Count > 0)
                {
                    mes.code = "200";
                    mes.Message = "查询成功!";
                    mes.data = data;
                }
                else
                {
                    mes.code = "300";
                    mes.Message = "查询失败!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return TJson.toJson(mes);
        }
 
    }
}