Пример #1
0
        /// <summary>
        /// 发送普通短信
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <OperationResult <int> > SendSmsAsync(SendTemplateSmsRequest request)
        {
            var result = await _Client.SendSmsAsync(request).ConfigureAwait(false);

            result.ThrowIfException(true);
            if (!result.Success)
            {
                _logger.Error($"SmsService SendSmsAsync fail => ErrorCode ={result.ErrorCode} & ErrorMessage ={result.ErrorMessage}");
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="couponRuleList"></param>
        /// <param name="user"></param>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <bool> SendNoyificationAsync(List <PromotionTaskPromotionListModel> couponRuleList, User user, SendCouponRequest request, CancellationToken cancellationToken)
        {
            try
            {
                List <string> smsParam   = JsonConvert.DeserializeObject <List <string> >(request.SmsParam ?? "");
                string        msgUrl     = string.Empty;                         //追踪短信链接
                string        msgBatchs  = string.Empty;                         //追踪短信批次
                string        msgSubject = string.Empty;                         //追踪短信主题

                if (request.SmsId > 0 && smsParam.Any())                         //判断是否发送短信
                {
                    if (smsParam.FirstOrDefault().ToLower().Contains("tuhu.cn")) //发送追踪短信
                    {
                        msgUrl = smsParam[0];
                        smsParam.RemoveAt(0);
                        msgBatchs  = $"CouponTask_{request.PromotionTaskId}_{DateTime.Now.ToString("yyyyMMdd")}";
                        msgSubject = $"优惠券任务:{request.PromotionTaskId}";

                        var biSmsRequest = new BiSmsRequest()
                        {
                            PhoneNumber = user.MobileNumber,
                            MsgBatchs   = msgBatchs,
                            MsgSubject  = msgSubject,
                            MsgBody     = smsParam.ToArray(),
                            MsgUrl      = msgUrl,
                            RelatedUser = request.Creater,
                            TemplateId  = request.SmsId
                        };
                        await smsService.SendBiSmsAsync(biSmsRequest, cancellationToken).ConfigureAwait(false);
                    }
                    else //发送普通短信
                    {
                        var smsRequest = new SendTemplateSmsRequest()
                        {
                            Cellphone         = user.MobileNumber,
                            TemplateId        = request.SmsId,
                            TemplateArguments = smsParam.ToArray()
                        };
                        await smsService.SendSmsAsync(smsRequest).ConfigureAwait(false);
                    }
                }

                foreach (var couponRule in couponRuleList.Where(p => p.IsRemind == "1"))
                {
                    PushTemplateLog pushTemplateLog = new PushTemplateLog()
                    {
                        Replacement = JsonConvert.SerializeObject(
                            new Dictionary <string, string>
                        {
                            ["{{currenttime}}"]  = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm"),
                            ["{{couponamount}}"] = couponRule.DiscountMoney.ToString(CultureInfo.InvariantCulture),
                            ["{{couponname}}"]   = couponRule.PromotionDescription
                        })
                    };
                    await pushService.PushByUserIDAndBatchIDAsync(new List <string> {
                        user.MobileNumber
                    }, 1509, pushTemplateLog).ConfigureAwait(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                logger.LogWarning("SendNoyificationAsync Exception", ex);
            }
            return(false);
        }