mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-05 10:19:48 +08:00
【修复】修复appsetting.json微信公众号配置项命名错误的问题。
【新增】增加微信公众号获取JS-Token并且全局缓存功能。 【新增】增加微信公众号获取JS-SDK使用权限签名算法。
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user