Ejemplo n.º 1
0
        /// <summary>
        /// 发送推送消息
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userId"></param>
        public async Task OrderPushRemind(OrderPushModel model, string userId)
        {
            var userEntity = await _userRepository.GetForIdAsync(userId);

            var weiXinUser = await _weiXinUserRepository.GetAsync(userEntity.UnionId);

            try
            {
                var templateData = new
                {
                    first    = new TemplateDataItem("您好,您的订单" + model.Type),
                    keyword1 = new TemplateDataItem(model.Number),
                    keyword2 = new TemplateDataItem(model.CreateTime.ToString("yyyy年MM月dd日 HH:mm:ss")),
                    keyword3 = new TemplateDataItem(model.ReceiverName),
                    keyword4 = new TemplateDataItem(model.PaymentPrice.ToString()),
                    remark   = new TemplateDataItem(">>点击查看详情<<", "#FF0000")
                };
                var miniProgram = new TempleteModel_MiniProgram()
                {
                    appid    = GuoGuoCommunity_WxOpenAppId,
                    pagepath = "pages/orderDetail/orderDetail?id=" + model.Id
                };
                TemplateApi.SendTemplateMessage(AppId, weiXinUser?.OpenId, OrderTemplateId, null, templateData, miniProgram);
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        public async Task <ApiResult <WXLoginOutput> > Login([FromUri] string code, CancellationToken cancelToken)
        {
            try
            {
                var openIdResult = SnsApi.JsCode2Json(GuoGuoCommunity_WxOpenAppId, GuoGuoCommunity_WxOpenAppSecret, code);
                var user         = await _userRepository.GetForOpenIdAsync(new UserDto { OpenId = openIdResult.openid });

                if (user == null)
                {
                    user = await _userRepository.AddWeiXinAsync(new UserDto()
                    {
                        OpenId          = openIdResult.openid,
                        UnionId         = openIdResult.unionid,
                        OperationTime   = DateTimeOffset.Now,
                        OperationUserId = "system"
                    }, cancelToken);
                }
                //产生 Token
                var token = _tokenRepository.Create(user);

                //存入数据库
                await _userRepository.UpdateTokenAsync(
                    new UserDto
                {
                    Id           = user.Id.ToString(),
                    RefreshToken = token.Refresh_token
                });

                var weiXinUser = await _weiXinUserRepository.GetAsync(openIdResult.unionid, cancelToken);

                /*
                 * 一期只有一个认证
                 */
                var ownerCertificationList = await _ownerCertificationRecordRepository.GetListAsync(new OwnerCertificationRecordDto()
                {
                    UserId = user.Id.ToString()
                });

                //var isVipOwner = false;
                //if (ownerCertificationList.Any())
                //{
                //    var vipOwner = await _vipOwnerRepository.GetForSmallDistrictIdAsync(new VipOwnerDto { SmallDistrictId = ownerCertificationList.FirstOrDefault().Industry.BuildingUnit.Building.SmallDistrictId.ToString() });
                //    if (vipOwner != null)
                //    {
                //        var vipOwnerCertificationRecord = await _vipOwnerCertificationRecordRepository.GetForVipOwnerIdAsync(new VipOwnerCertificationRecordDto
                //        {
                //            VipOwnerId = vipOwner.Id.ToString(),
                //            UserId = user.Id.ToString()
                //        });
                //        if (vipOwnerCertificationRecord != null)
                //        {
                //            isVipOwner = true;
                //        }
                //    }
                //}
                return(new ApiResult <WXLoginOutput>(APIResultCode.Success, new WXLoginOutput()
                {
                    OpenId = user.OpenId,
                    Token = token.Access_token,
                    Headimgurl = weiXinUser?.Headimgurl,
                    Nickname = weiXinUser?.Nickname,
                    IsSubscription = weiXinUser == null ? false : true,
                    IsOwner = ownerCertificationList.Any(),
                    //IsVipOwner = isVipOwner
                }, APIResultMessage.Success));
            }
            catch (Exception e)
            {
                return(new ApiResult <WXLoginOutput>(APIResultCode.Success_NoB, new WXLoginOutput()
                {
                }, e.Message));
            }
        }