Beispiel #1
0
        /// <summary>
        /// 发送验证码短信,操作成功返回流水号
        /// </summary>
        /// <param name="codeType">代码类型</param>
        /// <param name="accountNo">用户账号</param>
        /// <param name="phone">手机号码</param>
        /// <param name="code">验证码</param>
        /// <param name="item">活动名称</param>
        /// <returns></returns>
        public MessageRecorder <string> SendCode(CodeType codeType, string accountNo, string phone, string code, string item = null)
        {
            var r = new MessageRecorder <string>();

            try
            {
                var signName = Dict["Alidayu.Sign." + codeType];
                var tplNo    = Dict["Alidayu.Tpl." + codeType];

                if (string.IsNullOrEmpty(signName))
                {
                    r.Error("没有设置签名");
                }
                if (string.IsNullOrEmpty(tplNo))
                {
                    r.Error("没有设置模板编号");
                }
                if (string.IsNullOrEmpty(phone))
                {
                    r.Error("没有设置手机号码");
                }
                if (string.IsNullOrEmpty(code))
                {
                    r.Error("没有设置验证码");
                }
                if (r.HasError)
                {
                    return(r);
                }

                var req = new AlibabaAliqinFcSmsNumSendRequest
                {
                    Extend          = accountNo,
                    SmsType         = "normal",
                    SmsFreeSignName = signName,
                    SmsParam        = string.IsNullOrEmpty(item) ?
                                      string.Concat("{", $"\"code\": \"{code}\",\"product\": \"{ProductName}\"", "}") :
                                      string.Concat("{", $"\"code\": \"{code}\",\"product\": \"{ProductName}\",\"item\": \"{item}\"", "}"),
                    RecNum          = phone,
                    SmsTemplateCode = tplNo
                };
                var rsp = _client.Execute(req);
                _client = null;
                if (rsp == null)
                {
                    return(r.Error("发送无返回结果"));
                }
                if (rsp.IsError)
                {
                    return(r.Error(rsp.ErrMsg));
                }

                // {"alibaba_aliqin_fc_sms_num_send_response":{"result":{"err_code":"0","model":"100717449333^1101135565756","success":true},"request_id":"iv15pyenlo5r"}}
                // {"error_response":{"code":15,"msg":"Remote service error","sub_code":"isv.SMS_SIGNATURE_ILLEGAL","sub_msg":"短信签名不合法","request_id":"16ceaw87jeegp"}}

                return(r.Info("发送短信成功").SetValue(rsp.Result.Model));
            }
            catch (Exception ex)
            {
                return(r.Error($"发送短信失败. 原因:{ex.Message}"));
            }
        }