BeeCloud.BCPay.querySubscriptionsByCondition C# (CSharp) Метод

querySubscriptionsByCondition() публичный статический Метод

按条件查询用户订阅
public static querySubscriptionsByCondition ( string buyerID, string planID, string cardID, long createdBefore, long createdAfter, int skip, int limit, bool countOnly ) : List
buyerID string 用户ID
planID string 订阅计划ID
cardID string 用户卡ID
createdBefore long 创建时间前
createdAfter long 创建时间后
skip int 跳过数量
limit int 查询限量
countOnly bool 设置为true时只返回数量,设置为false时只返回plan记录
Результат List
        public static List<BCSubscription> querySubscriptionsByCondition(string buyerID, string planID, string cardID, long? createdBefore, long? createdAfter, int? skip, int? limit, bool countOnly)
        {
            long timestamp = BCUtil.GetTimeStamp(DateTime.Now);

            string subscriptionURL = BCPrivateUtil.getHost() + BCConstants.version + BCConstants.bcsubscriptionURL;
            subscriptionURL += "?app_id=" + BCCache.Instance.appId + "&app_sign=" + BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString()) + "&timestamp=" + timestamp;
            if (buyerID != null)
            {
                subscriptionURL += "&buyer_id=" + buyerID;
            }
            if (planID != null)
            {
                subscriptionURL += "&plan_id=" + planID;
            }
            if (cardID != null)
            {
                subscriptionURL += "&card_id=" + cardID;
            }
            if (createdBefore.HasValue)
            {
                subscriptionURL += "&created_before=" + createdBefore.Value;
            }
            if (createdAfter.HasValue)
            {
                subscriptionURL += "&created_after=" + createdAfter.Value;
            }
            if (skip.HasValue)
            {
                subscriptionURL += "&skip=" + skip.Value;
            }
            if (limit.HasValue)
            {
                subscriptionURL += "&limit=" + limit.Value;
            }
            subscriptionURL += "&count_only=" + countOnly;

            try
            {
                HttpWebResponse response = BCPrivateUtil.CreateGetHttpResponse(subscriptionURL, BCCache.Instance.networkTimeout);

                string respString = BCPrivateUtil.GetResponseString(response);

                JsonData responseData = JsonMapper.ToObject(respString);

                if (responseData["result_code"].ToString() == "0")
                {
                    List<BCSubscription> subscriptions = new List<BCSubscription>();
                    if (responseData["subscriptions"].IsArray)
                    {
                        foreach (JsonData subData in responseData["subscriptions"])
                        {
                            BCSubscription sub = new BCSubscription();
                            sub.ID = subData["id"].ToString();
                            sub.buyerID = subData["buyer_id"].ToString();
                            sub.planID = subData["plan_id"].ToString();
                            sub.cardID = subData["card_id"].ToString();
                            sub.bankName = subData["bank_name"].ToString();
                            sub.IDName = subData["id_name"].ToString();
                            sub.IDNo = subData["id_no"].ToString();
                            sub.mobile = subData["mobile"].ToString();
                            sub.amount = (double)subData["amount"];
                            sub.couponID = subData["coupon_id"].ToString();
                            sub.trialEnd = (long)subData["trial_end"];
                            sub.optional = JsonMapper.ToObject<Dictionary<string, string>>(subData["optional"].ToJson().ToString());

                            sub.last4 = subData["last4"].ToString();
                            sub.status = subData["status"].ToString();
                            sub.valid = (bool)subData["valid"];
                            sub.cancelAtPeriodEnd = (bool)subData["cancel_at_period_end"];

                            subscriptions.Add(sub);
                        }
                    }
                    return subscriptions;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            catch (Exception e)
            {
                var ex = new BCException(e.Message);
                throw ex;
            }
        }