AliIotFunction.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using Aop.Api;
  4. using Library;
  5. using Microsoft.AspNetCore.Http;
  6. using Aop.Api.Request;
  7. using Aop.Api.Response;
  8. using Aop.Api.Util;
  9. using MySystem.Models;
  10. using System.Linq;
  11. namespace MySystem
  12. {
  13. public class AliIotFunction
  14. {
  15. public readonly static AliIotFunction Instance = new AliIotFunction();
  16. private AliIotFunction()
  17. { }
  18. // public string Pid = "2088720140260314";
  19. private string AppId = "2021004109682585";
  20. private string PrivateKey = "MIIEpAIBAAKCAQEAvf75JGQL9IDg8xu2C6qWrIO3H4roSwpvwUeh6y2kQ8iH0gqQXlyLj13ku8pzY1H9JTSeARCsHSD/VJFxMoPOBO+/xGDV3CSdxhOE5Fu5E30ZZMA5XmnMKyN8q+MEh7refGuCmldedTmzr9mNw4HDjS1uqJoqYRl3eUEaC/Syl620iiaSh7Q9/rsT/qNcnP5hO9P3DWionNt78elmjLt0sBdBkQ10o2XwC5RuzBfP8DCBEdL/DPOOE4vtmLP1IdDI7qtjBhX8PdL+/IRxe/4OGvYSPnHW7JNlN970h2UN5i0Yu0AkidJvlS59nX9C1WJ4U37HiMnkMNXLB/Ubi5BkgQIDAQABAoIBAQC1itVKpWIa/a5z/Q2EtjqEmtK2jAcL9Ov11dlsm07zCcBlvXxW/bzIf6IYogiBZY0qKM21HNYoeygeCV8NMo3/f4pQPWr7j+1Fn88CWHZOneFOuLHYeeUBb0YoA6KHgtImNqAzk7oI7tq383uWzP4qfrfW2IAYCbp0HPWjaOvhKw7qrejcTPW0oCsPjm6nkjzW6FzjkPCwiiivvpC67EzpXKF8HnYyF1KMEuH6h7qZl4jtloW8CkgkwnBhc9iYhN/ygllYdPU9aRdThG7tFVCHft7cIq5F54pJoUm/ML3fpdVjFDAVGZFbkZyg4gkIYCLIEg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mzr9mNw4HDjS1uqJoqYRl3eUEaC/Syl620iiaSh7Q9/rsT/qNcnP5hO9P3DWionNt78elmjLt0sBdBkQ10o2XwC5RuzBfP8DCBEdL/DPOOE4vtmLP1IdDI7qtjBhX8PdL+/IRxe/4OGvYSPnHW7JNlN970h2UN5i0Yu0AkidJvlS59nX9C1WJ4U37HiMnkMNXLB/Ubi5BkgQIDAQAB";
  22. public string AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiXVtTk6opnYllnH/X40k/jSw/82WZ+lGbYQLYH/nVONFJ7Gr9C/dlKpJFIbS+vNDn+YLtM923KmEVSgf8zU0WrTkRjWvKEiyLswWZVqSZW5Jfon1e2SfjNrAVi6XBZa7urAItKQsdD2vFFuyG/ohlXBL103xC1wnjvECD/iholoruEFOLyfobJKTY/6iyrKeOElem1V7OWl6gdjG2oozj3nbVZhtkQvPJECYlolH96eK2mieTkFK82aZ5Tdzx1LPk/3hxRAmzz/9X7xfXdOly88hKBmW8LC9RhTlOWbrXJhhFz13A4brnbnOiY/X7b2OkAYifammc2uh0AIJlCmBTQIDAQAB";
  23. //"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";
  24. #region 间连iot设备和间连商户绑定
  25. public string IotBind(string Smid, string DeviceId)
  26. {
  27. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  28. AlipayMerchantIndirectIotBindRequest request = new AlipayMerchantIndirectIotBindRequest() ;
  29. request.BizContent="{" +
  30. " \"smid\":\"" + Smid + "\"," +
  31. " \"mode\":\"ALIYUN\"," +
  32. " \"device_id\":\"" + DeviceId + "\"" +
  33. // " \"supplier_id\":\"2022043454334\"" +
  34. "}";
  35. LogHelper.Instance.WriteLog(request.BizContent, "间连iot设备和间连商户绑定");
  36. string result = "";
  37. try
  38. {
  39. AlipayMerchantIndirectIotBindResponse response=client.Execute(request);
  40. result = response.Body;
  41. }
  42. catch (Exception ex)
  43. {
  44. LogHelper.Instance.WriteLog(ex.ToString(), "间连iot设备和间连商户绑定异常");
  45. result = "";
  46. }
  47. return result;
  48. }
  49. #endregion
  50. #region 到账播报
  51. public string IotTradeVoice(string BizTid, string Smid, string Amount, string TradeType = "ALIPAY_TRADE")
  52. {
  53. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  54. AlipayCommerceIotDeviceTradevoiceSendRequest request= new AlipayCommerceIotDeviceTradevoiceSendRequest() ;
  55. request.BizContent="{" +
  56. " \"biz_tid\":\"" + BizTid + "\"," +
  57. " \"smid\":\"" + Smid + "\"," +
  58. " \"trade_type\":\"" + TradeType + "\"," +
  59. " \"trade_id\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\"," +
  60. " \"amount\":\"" + Amount + "\"," +
  61. " \"msg_id\":\"202309190006284875\"" +
  62. "}";
  63. LogHelper.Instance.WriteLog(request.BizContent, "到账播报");
  64. string result = "";
  65. try
  66. {
  67. AlipayCommerceIotDeviceTradevoiceSendResponse response=client.Execute(request);
  68. result = response.Body;
  69. LogHelper.Instance.WriteLog(result + "\n\n", "到账播报");
  70. }
  71. catch (Exception ex)
  72. {
  73. LogHelper.Instance.WriteLog(ex.ToString(), "到账播报异常");
  74. result = "";
  75. }
  76. return result;
  77. }
  78. #endregion
  79. #region 图片上传
  80. public string UploadPic(string path)
  81. {
  82. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
  83. string fileName = path.Substring(path.LastIndexOf("/") + 1);
  84. string imageBase64 = function.imageToBase64String(function.getPath(path));
  85. // imageBase64 = imageBase64.Substring(imageBase64.IndexOf(";base64,") + 8);
  86. AntMerchantExpandIndirectImageUploadRequest request = new AntMerchantExpandIndirectImageUploadRequest();
  87. FileItem imageContent = new FileItem(fileName,Convert.FromBase64String(imageBase64));
  88. request.ImageContent = imageContent;
  89. request.ImageType = "jpg";
  90. AntMerchantExpandIndirectImageUploadResponse response = client.Execute(request);
  91. return fileName;
  92. }
  93. #endregion
  94. }
  95. }