WeChatController.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. using System.IO;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("Api/[controller]/[action]")]
  18. public class WeChatController : BaseController
  19. {
  20. public WeChatController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. }
  23. #region 微信服务平台支付回调
  24. public Dictionary<string, string> Notice()
  25. {
  26. StreamReader sr = new StreamReader(Request.Body);
  27. string requestMes = sr.ReadToEnd();
  28. function.WriteLog(DateTime.Now.ToString() + "\r\n" + requestMes + "\r\n\r\n", "微信服务平台支付回调");
  29. RedisDbconn.Instance.AddList("WeChatPayBack", requestMes);
  30. Dictionary<string, string> dic = new Dictionary<string, string>();
  31. dic.Add("code", "SUCCESS");
  32. dic.Add("message", "");
  33. return dic;
  34. }
  35. #endregion
  36. public Dictionary<string, string> test()
  37. {
  38. string AppId = "wx5417e0770bb19c4e";
  39. string MchId = "1611167423";
  40. string SubMchId = "1619775262";
  41. string Description = "四川探火网络科技有限责任公司";
  42. string OpenId = "omawy5VjduiPpSo9GNldzYZlioZE";
  43. string Key = AppConfig.WeChatParam.AesGemKey;
  44. string NotifyUrl = Host + "api/wechat/notice";
  45. // Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Pay(AppId, MchId, SubMchId, 0.1M, DateTime.Now.ToString("yyyyMMddHHmmssfff"), Description, OpenId, Key, NotifyUrl);
  46. Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Refund(AppId, MchId, SubMchId, 1M, 1M, "2022020817492424848364549", DateTime.Now.ToString("yyyyMMddHHmmssfff"), Description, OpenId, Key, NotifyUrl);
  47. return dic;
  48. }
  49. }
  50. }