WeChatController.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #region 微信服务平台支付回调(好哒)
  37. public Dictionary<string, string> HdNotice()
  38. {
  39. StreamReader sr = new StreamReader(Request.Body);
  40. string requestMes = sr.ReadToEnd();
  41. function.WriteLog(DateTime.Now.ToString() + "\r\n" + requestMes + "\r\n\r\n", "微信服务平台支付回调(好哒)");
  42. RedisDbconn.Instance.AddList("WeChatPayBackHd", requestMes);
  43. Dictionary<string, string> dic = new Dictionary<string, string>();
  44. dic.Add("resultCode", "1");
  45. return dic;
  46. }
  47. #endregion
  48. public Dictionary<string, string> test()
  49. {
  50. string AppId = "wx5417e0770bb19c4e";
  51. string MchId = "1611167423";
  52. string SubMchId = "1619775262";
  53. string Description = "四川探火网络科技有限责任公司";
  54. string OpenId = "omawy5VjduiPpSo9GNldzYZlioZE";
  55. string Key = AppConfig.WeChatParam.AesGemKey;
  56. string NotifyUrl = Host + "api/wechat/notice";
  57. // Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Pay(AppId, MchId, SubMchId, 0.1M, DateTime.Now.ToString("yyyyMMddHHmmssfff"), Description, OpenId, Key, NotifyUrl);
  58. Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Refund(AppId, MchId, SubMchId, 1M, 1M, "2022020817492424848364549", DateTime.Now.ToString("yyyyMMddHHmmssfff"), Description, OpenId, Key, NotifyUrl);
  59. return dic;
  60. }
  61. }
  62. }