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
using Dapper;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using VueWebCoreApi.Models;
using VueWebCoreApi.Tools;
using VueWebCoreApi.Util;
 
namespace VueWebCoreApi.Controllers
{
    [ApiExplorerSettings(GroupName = "畅捷通授权管理")]
    [ApiController]
    [Route("api/[controller]")]
    public class ErpMessageController : Controller
    {
       
        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);
            String decryptMsg = OpenapiHelper.AesDecrypt(enMsg, config.Key_encryptKey);
            LogHelper.WriteLogData2("解密后消息:" + decryptMsg);
 
            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)
        {
            AppTicketContent content = JsonConvert.DeserializeObject<AppTicketContent>(message.bizContent.ToString());
            LogHelper.WriteLogData($"AppTicket:{content.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 JsonResult 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 Json(mes);
        }
    }
}