94 lines
2.7 KiB
C#
94 lines
2.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using YD_XinWei.Commons;
|
|
using YD_XinWei.Commons.Exceptions;
|
|
using TGJ.NetworkFreight.SeckillAggregateServices.Pos.UserService;
|
|
using YD_XinWei.Api.Utilities;
|
|
using YD_XinWei.Api.WeChat.Lib;
|
|
using YD_XinWei.Api.Services.Interface;
|
|
using YD_XinWei.Api.WeChat;
|
|
|
|
namespace YD_XinWei.Api.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 用户
|
|
/// </summary>
|
|
[ApiController]
|
|
[ApiExplorerSettings(GroupName = "v1")]
|
|
[Route("[controller]")]
|
|
public class UserController : ControllerBase
|
|
{
|
|
private readonly IUserService _userService;
|
|
public UserController(IUserService userService)
|
|
{
|
|
_userService = userService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取微信信息
|
|
/// </summary>
|
|
/// <param name="wXLoginPo"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("WXUserInfo")]
|
|
public WechatUserInfo GetWXUserInfo(WXLoginPo wXLoginPo)
|
|
{
|
|
var wli = new WechatLoginInfo();
|
|
wli.code = wXLoginPo.code;
|
|
wli.encryptedData = wXLoginPo.encryptedData;
|
|
wli.iv = wXLoginPo.iv;
|
|
wli.rawData = wXLoginPo.rawData;
|
|
wli.signature = wXLoginPo.signature;
|
|
|
|
wli.appid = AppSettings.WeChat.Appid;
|
|
wli.secret = AppSettings.WeChat.Appid;
|
|
|
|
|
|
WechatUserInfo wechatResult = new WeChatAppDecrypt().Decrypt(wli);
|
|
|
|
if (wechatResult == null || string.IsNullOrWhiteSpace(wechatResult.openId))
|
|
{
|
|
throw new BizException("用户信息获取失败");
|
|
}
|
|
|
|
return wechatResult;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 用户名密码登录
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost(nameof(Login))]
|
|
[AllowAnonymous]
|
|
public async Task<IActionResult> Login([FromBody] LoginInfo paramDto)
|
|
{
|
|
var res = await _userService.Login(paramDto);
|
|
return Ok(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 微信用户登录
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("WxLogin")]
|
|
[AllowAnonymous]
|
|
public async Task<IActionResult> WxLogin(WXLoginPo loginPo)
|
|
{
|
|
//var id = UserLoginContext.Current.UserId;
|
|
var res = await _userService.WxLogin(loginPo);
|
|
return Ok(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关联账号
|
|
/// </summary>
|
|
/// <param name="relevanceId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("RelatedAccounts")]
|
|
public async Task<List<RelatedAccountsDto>> RelatedAccounts(Guid relevanceId)
|
|
{
|
|
var res = await _userService.RelatedAccounts(relevanceId);
|
|
return res;
|
|
}
|
|
}
|
|
} |