You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.3 KiB
71 lines
2.3 KiB
using Senparc.Weixin.MP.CommonAPIs;
|
|
using Senparc.Weixin.MP.Containers;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Yitter.IdGenerator;
|
|
using Znyc.Admin.Commons.Const;
|
|
using Znyc.Admin.Commons.Entitys;
|
|
using Znyc.Admin.Commons.Log;
|
|
using Znyc.Admin.Commons.Mapping;
|
|
using Znyc.Admin.Commons.Pages;
|
|
using Znyc.Admin.Commons.Services;
|
|
using Znyc.Admin.Security.Dtos;
|
|
using Znyc.Admin.Security.Dtos.WxUserRelation;
|
|
using Znyc.Admin.Security.Entitys;
|
|
using Znyc.Admin.Security.Entitys.Dispatching;
|
|
using Znyc.Admin.Security.IRepositories;
|
|
using Znyc.Admin.Security.IServices;
|
|
|
|
namespace Znyc.Admin.Security.Services
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class WxUserRelationService : BaseService<WxUserRelation, WxUserRelationOutputDto, long>, IWxUserRelationService
|
|
{
|
|
private readonly IWxUserRelationRepository _repository;
|
|
|
|
public WxUserRelationService(IWxUserRelationRepository repository
|
|
) : base(repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="wxOpenId"></param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> UpdateAsync(string wxOpenId)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
await AccessTokenContainer.RegisterAsync("wx07c574aca93ae8d9", "2d202f91258131f63565e11bdb065f6b");
|
|
var wxUser = CommonApi.GetUserInfo("wx07c574aca93ae8d9", wxOpenId);
|
|
|
|
|
|
string where = string.Format("unionId='{0}'", wxUser.unionid);
|
|
var wxUserRelation = await GetWhereAsync(where);
|
|
if (wxUserRelation != null)
|
|
{
|
|
wxUserRelation.WxOfficialOpenId = wxOpenId;
|
|
wxUserRelation.ModifiedTime = DateTime.Now;
|
|
await _repository.UpdateAsync(wxUserRelation, wxUserRelation.Id);
|
|
}
|
|
else
|
|
{
|
|
await _repository.InsertAsync(new WxUserRelation()
|
|
{
|
|
Id = YitIdHelper.NextId(),
|
|
OpenId = "",
|
|
UnionId = wxUser.unionid,
|
|
WxOfficialOpenId = wxOpenId
|
|
});
|
|
|
|
}
|
|
|
|
result.Success = true;
|
|
return result;
|
|
}
|
|
}
|
|
}
|