using Microsoft.AspNetCore.Mvc; using SKIT.FlurlHttpClient.Wechat.Api; using SKIT.FlurlHttpClient.Wechat.Api.Models; using System.Web; using ZR.Model.Business.Dto; using ZR.Model.Business; using ZR.Service.Business.IBusinessService; namespace ZR.Admin.WebApi.Controllers { /// /// 微信公众号 /// [Route("[controller]/[action]")] [AllowAnonymous] public class WxOpenController : BaseController { private readonly WechatApiClient _client; public WxOpenController(WechatApiClient client) { _client = client; } /// /// 获取签名 /// /// /// [Log(Title = "获取微信签名")] [HttpGet] public IActionResult GetSignature(string url = "") { url = HttpUtility.UrlDecode(url); var appId = AppSettings.App(new string[] { "WxOpen", "AppID" }); var noncestr = Guid.NewGuid().ToString().Replace("-", ""); var timestamp = DateTimeHelper.GetUnixTimeSeconds(DateTime.Now); var ticketResult = WxHelper.GetTicket(); if (appId.IsEmpty()) return ToResponse(ResultCode.CUSTOM_ERROR, "appId未配置"); if (ticketResult?.errcode != 0) { return ToResponse(ResultCode.CUSTOM_ERROR, "获取配置失败"); } var signature = WxHelper.GetSignature(ticketResult.ticket, timestamp.ToString(), noncestr, url); return SUCCESS(new { appId, signature, noncestr, timestamp, url }); } } }