mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 16:13:26 +08:00
60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using CoreCms.Net.Caching.AccressToken;
|
|
using CoreCms.Net.WeChat.Service.Options;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace CoreCms.Net.Web.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 微信公众号通用接口
|
|
/// </summary>
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class WeChatOffiaccountController : Controller
|
|
{
|
|
private readonly WeChatOptions _weChatOptions;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
/// <param name="weChatOptions"></param>
|
|
public WeChatOffiaccountController(IOptions<WeChatOptions> weChatOptions)
|
|
{
|
|
_weChatOptions = weChatOptions.Value;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// JS-SDK使用权限签名算法
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public IActionResult GetWeChatConfig()
|
|
{
|
|
//获取全局缓存的jsapi_ticket
|
|
var jsApiTicket = WeChatCacheAccessTokenHelper.GetWeChatJsApiTicket();
|
|
var nonceStr = CoreCms.Net.Utility.Helper.CommonHelper.GetSerialNumber();
|
|
var timestamp = CoreCms.Net.Utility.Helper.CommonHelper.GetTimeStampByTotalSeconds().ToString();
|
|
var url = Request.GetTypedHeaders().Referer;
|
|
//获取前面
|
|
var signatureStr = "jsapi_ticket=" + jsApiTicket + "&noncestr=" + nonceStr + "×tamp=" + timestamp + "&url=" + url;
|
|
var signature = CoreCms.Net.Utility.Helper.CommonHelper.Sha1Signature(signatureStr);
|
|
|
|
return Json(new
|
|
{
|
|
jsApiTicket,
|
|
appId = _weChatOptions.WeiXinAppId,
|
|
timestamp,
|
|
nonceStr,
|
|
signature,
|
|
url
|
|
});
|
|
}
|
|
|
|
|
|
}
|
|
}
|