Exemple #1
0
        /// <summary>
        /// 请求发送验证码。
        /// </summary>
        /// <returns>是否发送成功。</returns>
        /// <param name="mobilePhoneNumber">手机号。</param>
        /// <param name="name">应用名称。</param>
        /// <param name="op">进行的操作名称。</param>
        /// <param name="ttl">验证码失效时间。</param>
        /// <param name="cancellationToken">Cancellation token。</param>
        public static Task <bool> RequestSMSCodeAsync(string mobilePhoneNumber, string name, string op, int ttl, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(mobilePhoneNumber))
            {
                throw new AVException(AVException.ErrorCode.MobilePhoneInvalid, "Moblie Phone number is invalid.", null);
            }

            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber },
            };

            if (!string.IsNullOrEmpty(name))
            {
                strs.Add("name", name);
            }
            if (!string.IsNullOrEmpty(op))
            {
                strs.Add("op", op);
            }
            if (ttl > 0)
            {
                strs.Add("ttl", ttl);
            }

            return(AVClient.RequestAsync("POST", "/requestSmsCode", null, strs, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
Exemple #2
0
 /// <summary>
 /// 调用云代码
 /// </summary>
 /// <returns>返回一个 Task String 的类型</returns>
 /// <param name="name">函数名</param>
 /// <param name="parameters">传入的参数字典</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 public static Task <string> CallFunctionAsync(string name, IDictionary <string, object> parameters, CancellationToken cancellationToken)
 {
     return(AVClient.RequestAsync("POST", new Uri(string.Format("/functions/{0}", Uri.EscapeUriString(name)), UriKind.Relative), AVUser.CurrentSessionToken, parameters, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, string>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
         IDictionary <string, object> strs = AVDecoder.Instance.Decode(t.Result.Item2) as IDictionary <string, object>;
         return strs["result"].ToString();
     }));
 }
Exemple #3
0
 internal Task DeleteAsync(CancellationToken cancellationToken)
 {
     lock (this.mutex)
     {
         string currentSessionToken = AVUser.CurrentSessionToken;
         return(AVClient.RequestAsync("DELETE", new Uri(string.Format("/files/{0}", this.ObjectId), UriKind.Relative), currentSessionToken, null, cancellationToken));
     }
 }
Exemple #4
0
        /// <summary>
        ///  请求重置密码,需要传入注册时使用的手机号。
        /// </summary>
        /// <param name="mobilePhoneNumber">注册时使用的手机号</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        public static Task RequestPasswordResetBySmsCode(string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            string currentSessionToken       = AVUser.CurrentSessionToken;
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber }
            };

            return(AVClient.RequestAsync("POST", "/requestPasswordResetBySmsCode", currentSessionToken, strs, cancellationToken));
        }
Exemple #5
0
        /// <summary>
        /// 验证是否是有效短信验证码。
        /// </summary>
        /// <returns>是否验证通过。</returns>
        /// <param name="code">验证码。</param>
        /// <param name="mobilePhoneNumber">手机号</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public static Task <bool> VerifySmsCodeAsync(string code, string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "code", code.Trim() },
                { "mobilePhoneNumber", mobilePhoneNumber.Trim() },
            };

            return(AVClient.RequestAsync("POST", "/verifySmsCode/" + code.Trim() + "?mobilePhoneNumber=" + mobilePhoneNumber.Trim(), null, null, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
Exemple #6
0
        /// <summary>
        /// 发送认证码到需要认证的手机上
        /// </summary>
        /// <param name="mobilePhoneNumber">手机号</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns></returns>
        public static Task <bool> RequestMobilePhoneVerifyAsync(string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            string currentSessionToken       = AVUser.CurrentSessionToken;
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber }
            };

            return(AVClient.RequestAsync("POST", "/requestMobilePhoneVerify", currentSessionToken, strs, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
Exemple #7
0
        /// <summary>
        /// 通过验证码重置密码。
        /// </summary>
        /// <param name="newPassword">新密码</param>
        /// <param name="smsCode">6位数验证码</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        public static Task <bool> ResetPasswordBySmsCodeAsync(string newPassword, string smsCode, CancellationToken cancellationToken)
        {
            string currentSessionToken       = AVUser.CurrentSessionToken;
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "password", newPassword }
            };

            return(AVClient.RequestAsync("PUT", "/resetPasswordBySmsCode/" + smsCode, currentSessionToken, strs, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
Exemple #8
0
        internal static Task <Tuple <HttpStatusCode, string> > RequestAsync(Uri uri, string method, IList <KeyValuePair <string, string> > headers, IDictionary <string, object> body, string contentType, CancellationToken cancellationToken)
        {
            //HttpRequest request = new HttpRequest()
            //{
            //    Data = data != null ? new MemoryStream(Encoding.UTF8.GetBytes(Json.Encode(data))) : null,
            //    Headers = headers,
            //    Method = method,
            //    Uri = uri
            //};
            var dataStream = body != null ? new MemoryStream(Encoding.UTF8.GetBytes(Json.Encode(body))) : null;

            return(AVClient.RequestAsync(uri, method, headers, dataStream, contentType, cancellationToken));
            //return AVPlugins.Instance.HttpClient.ExecuteAsync(request, null, null, cancellationToken);
        }
Exemple #9
0
        /// <summary>
        /// Requests the login SMS code asynchronous.
        /// </summary>
        /// <param name="mobilePhoneNumber">The mobile phone number.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <bool> RequestLoginSmsCodeAsync(string mobilePhoneNumber, CancellationToken cancellationToken)
        {
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber }
            };
            var command = new AVCommand("/requestLoginSmsCode",
                                        method: "POST",
                                        sessionToken: CurrentSessionToken,
                                        data: null);

            return(AVClient.RequestAsync("POST", "/requestLoginSmsCode", null, strs, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mobilePhoneNumber"></param>
        /// <returns></returns>
        public static Task <bool> RequestVoiceCodeAsync(string mobilePhoneNumber)
        {
            if (string.IsNullOrEmpty(mobilePhoneNumber))
            {
                throw new AVException(AVException.ErrorCode.MobilePhoneInvalid, "Moblie Phone number is invalid.", null);
            }
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber },
                { "smsType", "voice" },
                { "IDD", "+86" }
            };

            return(AVClient.RequestAsync("POST", "/requestSmsCode", null, strs, CancellationToken.None).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
Exemple #11
0
        /// <summary>
        /// 根据 ObjectId 获取文件
        /// </summary>
        /// <remarks>获取之后并没有实际执行下载,只是加载了文件的元信息以及物理地址(Url)
        /// </remarks>
        public static Task <AVFile> GetFileWithObjectIdAsync(string objectId, CancellationToken cancellationToken)
        {
            string currentSessionToken = AVUser.CurrentSessionToken;

            return(AVClient.RequestAsync("GET", new Uri(string.Format("/files/{0}", objectId), UriKind.Relative), currentSessionToken, null, cancellationToken).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, AVFile>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) =>
            {
                AVFile rtn = null;
                if (AVClient.IsSuccessStatusCode(t.Result.Item1))
                {
                    var metaData = t.Result.Item2["metaData"] as IDictionary <string, object>;

                    rtn = new AVFile(t.Result.Item2["name"] as string, t.Result.Item2["url"] as string, metaData);
                    rtn.MergeFromJSON(t.Result.Item2);
                }
                return rtn;
            }));
        }
Exemple #12
0
 public static Task <DateTime> GetServerDateTime()
 {
     return(AVClient.RequestAsync("GET", "/date", null, null, CancellationToken.None).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, DateTime>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
         DateTime rtn = DateTime.MinValue;
         if (AVClient.IsSuccessStatusCode(t.Result.Item1))
         {
             var date = AVDecoder.Instance.Decode(t.Result.Item2);
             if (date != null)
             {
                 if (date is DateTime)
                 {
                     rtn = (DateTime)date;
                 }
             }
         }
         return rtn;
     }));
 }
Exemple #13
0
        /// <summary>
        ///
        // 发送手机短信,并指定模板以及传入模板所需的参数。
        //
        // Exceptions:
        //   AVOSCloud.AVException:
        //   手机号为空。
        ///
        /// <param name="mobilePhoneNumber"></param>
        /// <param name="template"></param>
        /// <param name="env"></param>
        /// <returns></returns>
        public static Task <bool> RequestSMSCodeAsync(string mobilePhoneNumber, string template, IDictionary <string, object> env)
        {
            if (string.IsNullOrEmpty(mobilePhoneNumber))
            {
                throw new AVException(AVException.ErrorCode.MobilePhoneInvalid, "Moblie Phone number is invalid.", null);
            }
            Dictionary <string, object> strs = new Dictionary <string, object>()
            {
                { "mobilePhoneNumber", mobilePhoneNumber },
            };

            strs.Add("template", template);
            foreach (var key in env.Keys)
            {
                strs.Add(key, env[key]);
            }
            return(AVClient.RequestAsync("POST", "/requestSmsCode", null, strs, CancellationToken.None).OnSuccess <Tuple <HttpStatusCode, IDictionary <string, object> >, bool>((Task <Tuple <HttpStatusCode, IDictionary <string, object> > > t) => {
                return AVClient.IsSuccessStatusCode(t.Result.Item1);
            }));
        }
Exemple #14
0
 /// <summary>
 /// Convenience alias for RequestAsync that takes a string instead of a Uri.
 /// </summary>
 internal static Task <Tuple <HttpStatusCode, IDictionary <string, object> > > RequestAsync(string method, string relativeUri, string sessionToken, IDictionary <string, object> data, CancellationToken cancellationToken)
 {
     return(AVClient.RequestAsync(method, new Uri(relativeUri, UriKind.Relative), sessionToken, data, cancellationToken));
 }