123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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_PROD_W966HG08MCOXHNT2";
- string accesskeySecret = "F2jzl8vGkm0fMeDLyYo40wEbzdaiTX2ywj3YNgszJHAbVbcAYIJL9bzzS9lVPPL6";
- string reqUrl = "https://voice.tysmartpos.com/api/bank/pushmsg";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public string doSomething(string OrderNo, string DeviceId, string Amount)
- {
- string result = "";
- try
- {
- SortedList<string, string> data = new SortedList<string, string>();
- data.Add("accessKeyId", accesskeyld);
- data.Add("requestId", OrderNo);
- data.Add("timestamp", function.GetCurTimestamp().ToString());
- data.Add("deviceId", DeviceId);
- data.Add("content", "来客八收款" + Amount + "元");
-
-
- result = post(data);
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "天喻云喇叭异常");
- }
- 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);
- function.WriteLog("请求地址:" + reqUrl, "天谕音响日志");
- function.WriteLog("请求参数:" + req, "天谕音响日志");
- string result = function.PostWebRequest(reqUrl, req, "application/json");
- function.WriteLog("响应数据:" + result, "天谕音响日志");
- 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
- }
- }
|