/// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="verifyCode"></param>
        /// <returns></returns>
        public OVerifyCode Send(string phone, string verifyCode)
        {
            try {
                using (WebClient wc = new WebClient()) {
                    wc.Credentials = CredentialCache.DefaultCredentials;

                    string tk = new OTokenAPI(_appId, _accessToken).GetToken().Token;

                    SortedDictionary <string, string> args = new SortedDictionary <string, string>();
                    args.Add("app_id", _appId);
                    args.Add("access_token", _accessToken);
                    args.Add("token", tk);
                    args.Add("phone", phone);
                    args.Add("randcode", verifyCode);
                    args.Add("timestamp", OConfig189.GetTimeStamp());
                    args.Add("exp_time", "3");                     //可选

                    string sign = Utility189.DoSignature(args, OConfig189.AppSecret);

                    args.Add("sign", sign);

                    Logger.Debug("189 OVerifyCodeCustomAPI.Send:" + Utility189.GetUrlParameters(args));

                    string result = Utility189.PostWebRequest(_api, Utility189.GetUrlParameters(args), Encoding.UTF8);

                    Logger.Debug("189 OVerifyCodeCustomAPI.Result:" + result);

                    var verifyCodeObj = JsonKit.Deserialize <verify_code_obj>(result);
                    if (verifyCodeObj != null)
                    {
                        if (!string.IsNullOrEmpty(verifyCodeObj.identifier))
                        {
                            //转换
                            OVerifyCode verify = new OVerifyCode();
                            verify.Identifier = verifyCodeObj.identifier;
                            verify.CreateAt   = verifyCodeObj.create_at;

                            return(verify);
                        }
                        else
                        {
                            return(new OVerifyCode()
                            {
                                ResultCode = verifyCodeObj.res_code, ResultMessage = verifyCodeObj.res_message
                            });
                        }
                    }
                }
            } catch (Exception ex) {
                return(new OVerifyCode()
                {
                    ResultCode = -1, ResultMessage = ex.Message
                });
            }

            return(new OVerifyCode()
            {
                ResultCode = -1, ResultMessage = "接口没有获取到正确结果!"
            });
        }
Exemplo n.º 2
0
        public OToken GetToken()
        {
            try {
                using (WebClient wc = new WebClient()) {
                    wc.Credentials = CredentialCache.DefaultCredentials;

                    SortedDictionary <string, string> args = new SortedDictionary <string, string>();
                    args.Add("app_id", _appId);
                    args.Add("access_token", _accessToken);
                    args.Add("timestamp", OConfig189.GetTimeStamp());

                    string sign = Utility189.DoSignature(args, OConfig189.AppSecret);

                    args.Add("sign", sign);

                    string result = wc.DownloadString(_api + "?" + Utility189.GetUrlParameters(args));

                    Logger.Debug("189 OTokenAPI.GetToken:" + result);

                    var token = JsonKit.Deserialize <token_obj>(result);
                    if (token != null)
                    {
                        if (!string.IsNullOrEmpty(token.token))
                        {
                            //转换
                            OToken at = new OToken();
                            at.ResultCode = token.res_code;
                            at.Token      = token.token;

                            return(at);
                        }
                        else
                        {
                            return(new OToken()
                            {
                                ResultCode = token.res_code, ResultMessage = token.res_message
                            });
                        }
                    }
                }
            } catch (Exception ex) {
                return(new OToken()
                {
                    ResultCode = -1, ResultMessage = ex.Message
                });
            }

            return(new OToken()
            {
                ResultCode = -1, ResultMessage = "接口没有获取到正确结果!"
            });
        }