48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.Extensions.Logging;
|
||
using YD_Event.Application.Client.Dtos;
|
||
using YD_Event.Core.Infrastructure.WeChat;
|
||
|
||
namespace YD_Event.Application.Client;
|
||
|
||
/// <summary>
|
||
/// 微信小程序接口
|
||
/// </summary>
|
||
[ApiDescriptionSettings("微信小程序接口")]
|
||
[AllowAnonymous]
|
||
public class WeChatController : IDynamicApiController
|
||
{
|
||
private readonly WeChatService _weChatService;
|
||
private readonly ILogger<WeChatController>_logger;
|
||
|
||
public WeChatController(
|
||
WeChatService weChatService,
|
||
ILogger<WeChatController>logger)
|
||
{
|
||
_weChatService = weChatService;
|
||
_logger = logger;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 小程序 code 换取 openid 和 session_key
|
||
/// </summary>
|
||
/// <param name="input">包含 code 的输入参数</param>
|
||
/// <returns>openid、session_key 等信息</returns>
|
||
[HttpPost("jscode2session")]
|
||
[DisplayName("小程序 code 换取 openid")]
|
||
public async Task<WeChatCode2SessionOutput> Code2Session([FromBody] WeChatCode2SessionInput input)
|
||
{
|
||
_logger.LogInformation("开始调用微信 code2session 接口");
|
||
|
||
var result = await _weChatService.Code2Session(input.Code);
|
||
|
||
_logger.LogInformation("微信 code2session 接口调用成功,OpenId={OpenId}", result.OpenId);
|
||
|
||
return new WeChatCode2SessionOutput
|
||
{
|
||
OpenId = result.OpenId,
|
||
SessionKey = result.SessionKey,
|
||
UnionId = result.UnionId
|
||
};
|
||
}
|
||
} |