Ejemplo n.º 1
0
        /// <summary>
        /// Step2:获取授权过的Access Token
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static AliPay_AccessToken_ResultEntity AccessToken(AliPay_AccessToken_RequestEntity entity)
        {
            Signature(entity);

            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            string pars   = LoginBase.EntityToPars(entity);
            string result = Core.HttpTo.Get(AliPayConfig.API_Gateway + "?" + pars);

            AliPay_AccessToken_ResultEntity outmo = null;

            if (result.Contains("alipay_system_oauth_token_response"))
            {
                outmo = result.ToJObject()["alipay_system_oauth_token_response"].ToJson().ToEntity <AliPay_AccessToken_ResultEntity>();
            }

            if (result.Contains("error_response"))
            {
                outmo = result.ToJObject()["error_response"].ToJson().ToEntity <AliPay_AccessToken_ResultEntity>();
            }

            return(outmo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Step2:获取授权过的Access Token
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static AliPay_AccessToken_ResultEntity AccessToken(AliPay_AccessToken_RequestEntity entity)
        {
            Signature(entity);

            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            string pars   = LoginBase.EntityToPars(entity);
            string result = NetnrCore.HttpTo.Get(AliPayConfig.API_Gateway + "?" + pars);

            string jkey = string.Empty;

            if (result.Contains("alipay_system_oauth_token_response"))
            {
                jkey = "alipay_system_oauth_token_response";
            }
            if (result.Contains("error_response"))
            {
                jkey = "error_response";
            }
            if (!string.IsNullOrEmpty(jkey))
            {
                var outmo = NetnrCore.ToEntity <AliPay_AccessToken_ResultEntity>(NetnrCore.ToJson(JObject.Parse(result)[jkey]));
                return(outmo);
            }

            return(null);
        }