Explorar o código

增加天谕音响接口

lcl hai 1 ano
pai
achega
32ef019502
Modificáronse 2 ficheiros con 99 adicións e 2 borrados
  1. 95 0
      AppStart/Helper/TianYuVoiceHelper.cs
  2. 4 2
      Controllers/HomeController.cs

+ 95 - 0
AppStart/Helper/TianYuVoiceHelper.cs

@@ -0,0 +1,95 @@
+using System;
+using System.Threading;
+using System.Linq;
+using System.Data;
+using Library;
+using MySystem.Models;
+using LitJson;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+
+namespace MySystem
+{
+    public class TianYuVoiceHelper
+    {
+        public readonly static TianYuVoiceHelper Instance = new TianYuVoiceHelper();
+        private TianYuVoiceHelper()
+        {
+        }
+
+        string accesskeyld = "IOT_ACCOUNT_TEST_CSYH";
+        string accesskeySecret = "AtR4g5sa24fdy6GII3hts75_CSYH";
+        string reqUrl = "https://voicetest.tysmartpos.com/api/bank/pushmsg";
+
+        public void Start()//启动
+        {
+            Thread thread = new Thread(listen);
+            thread.IsBackground = true;
+            thread.Start();
+        }
+
+        public void listen()
+        {
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("TianYuVoiceQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    try
+                    {
+                        doSomething(content);
+                        Thread.Sleep(10);
+                    }
+                    catch (Exception ex)
+                    {
+                        LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "天喻云喇叭异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(1000);
+                }
+            }
+        }
+
+        public string doSomething(string content)
+        {
+            JsonData jsonObj = JsonMapper.ToObject(content);
+            SortedList<string, string> data = new SortedList<string, string>();
+            data.Add("accessKeyId", accesskeyld); //由本公司统一提供给客户的唯一识别码(同accessKeyId)
+            data.Add("requestId", jsonObj["OrderNo"].ToString()); //请求标识,用于唯一标识当前请求
+            data.Add("timestamp", function.ConvertDateTimeInt(DateTime.Now).ToString()); //请求时间戳,格式如:1593532800000
+            data.Add("deviceId", jsonObj["DeviceId"].ToString()); //设备编号
+            data.Add("content", "来客吧收款" + jsonObj["Amount"].ToString() + "元"); //(终端直接播报内容,支持 tts 设备可以直接播报汉字语音,不支持 tts 的设备要分开传 requestData、payType)
+            // data.Add("requestData", "0.01"); //播报金额((只送金额,单位:元)
+            // data.Add("payType", "01"); //播报类型:  01-XX银行收款成功    02-支付宝收款成功  03-微信收款成功 10-取消支付
+            string result = post(data);
+            return result;
+        }
+
+        private string post(SortedList<string, string> data)
+        {
+            string signString = function.BuildQueryString(data);
+            data.Add("sign", hmac_sha256(signString));
+            string req = Newtonsoft.Json.JsonConvert.SerializeObject(data);
+            string result = function.PostWebRequest(reqUrl, req, "application/json");
+            return result;
+        }
+
+        #region hmac_sha256算法
+
+        public string hmac_sha256(string message)
+        {
+            var encoding = new System.Text.UTF8Encoding();
+            byte[] keyByte = encoding.GetBytes(accesskeySecret);
+            byte[] messageBytes = encoding.GetBytes(message);
+            using (var hmacsha256 = new HMACSHA256(keyByte))
+            {
+                byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
+                return Convert.ToBase64String(hashmessage);
+            }
+        }
+
+        #endregion
+    }
+}

+ 4 - 2
Controllers/HomeController.cs

@@ -197,8 +197,8 @@ namespace MySystem.Controllers
             // string result = AliIotFunction.Instance.IotUnBind("2088720723136476", "018271007948");
             // string result = AliIotFunction.Instance.IotDeviceQuery("018271007948");
             //{"alipay_commerce_iot_device_baseinfo_query_response":{"code":"10000","msg":"Success","device_id":"01010VO0cD5XzXQdca5i38e2I4wLHskg23hiuvEBASuHHvGKq982oko"},"sign":"hlGINohkf2g/ZqLNMH5FjVAXXxZYIHpOy8qSLBf3LJhTF1IH11oFsBPlNq5CWfI351tsoewB9aQ1CnqI0CwIeWV3fk+Bxc+n0GqJ0ePlvumdUJDwcMFUyE6xzmO0iepHbTE3akQVvHEsnwxOVJ4TD/NEwfacJi5WaoQKJnZcOzbVJmpmb5q67QObQTjsGdeV89/B+xK2JDcIBulorL+oUIALH0I8wrarJI8PpSATtZr6PEXjRzLaoYrTVnRVLj62DlSDhAlbrKx8924O8iW+j5rs16XZbdLk9kej884vCntks+6WwUaymM1YDS2xXhxTZPxrQow9h0WJ8R9EBavQFw=="}
-            string result = AliIotFunction.Instance.IotTradeVoice("01010VO0cD5XzXQdca5i38e2I4wLHskg23hiuvEBASuHHvGKq982oko", "2088720723136476", "55555", money, "OTHER");
-            return result;
+            // string result = AliIotFunction.Instance.IotTradeVoice("01010VO0cD5XzXQdca5i38e2I4wLHskg23hiuvEBASuHHvGKq982oko", "2088720723136476", "55555", money, "OTHER");
+            // return result;
             //{"alipay_merchant_indirect_authorder_create_response":{"code":"10000","msg":"Success","order_no":"202308011033330180","order_status":"AUDITING"},"sign":"FINNZ7lw92Igku4KfNp5+ETLLyBKgR0faoGU4mceiiAwe85jbslbwAuxqgewGxmrPys7iGkwTNkgK7D7mx+sjF1mHtPXBszb1WAeD5kF764/qQ7r1ziXI252D8+qN/GfUxtnaR1mFRHbXpeh9z3Hjiey0xtThPCRZO63rgNICa9oJ/kRTQ5AZpn1Ih+hWaSFVDHDhBTBJ/j1uzs4PedrVZqqUUXtFf+o0XI0mctdHjaXomSr5bx9wsc8asEveXDSP4s1JksqJy0Gi0x/Oqc9aq03eV1cwO+Hk5YMwML9Rm+mZDUrIDwUK5gsioM0wGVqJy19o2O2wAecOYtCFRNXnA=="}
 
             //{"alipay_merchant_indirect_authorder_querystatus_response":{"code":"10000","msg":"Success","order_no":"202308011033330180","order_status":"CONTACT_CONFIRM","qr_code":"https:\/\/mobilecodec.alipay.com\/show.htm?code=2ie16321tmy5uxwph8qze93"},"sign":"acEG5SvoUwjNgF8Ge/pGFTnLbbFCodyoVYrNV2WiKoGs81509JEPtLdZYl05ck+UI9qZ4GqWGqMBKP6hjk8GsVaQ53NvRTdvxmHFdEx6iskI5+WohM0m6HZMZgvDPvrqivqyQIkylX/uM/GKhQVK0/wMiRcfRuTQ/17OKJqd6fSA0mSgE27NI1K0JuIiJulL4V447RVIOVb5rW7QFFqf+7+vAu5/XaeUbboGPq68GvUUAOjIj3RMdHo+NiHRUcRaH5ajP+fkDrjMP5MjBwpCU6WOhv5pVi1cdEMO3kG0ga3pZQr1YWqWgW1HH/p8wAUJhmNsh8+eHeOi+6a6mkraQg=="}
@@ -210,6 +210,8 @@ namespace MySystem.Controllers
             
             // return WeChatFunctionForHD.Instance.AesGcmDecrypt("certificate", "fdc941b6d56c", content);
             // return "ok";
+
+            return TianYuVoiceHelper.Instance.doSomething("{\"OrderNo\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "\",\"DeviceId\":\"010857203321\",\"Amount\":\"100\"}");
         }
     
     }