Beispiel #1
0
        /// <summary>
        /// 按ID查询订阅记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BCSubscription querySubscriptionByID(string id)
        {
            long timestamp = BCUtil.GetTimeStamp(DateTime.Now);

            string subscriptionURL = BCPrivateUtil.getHost() + BCConstants.version + BCConstants.bcsubscriptionURL + "/" + id;
            subscriptionURL += "?app_id=" + BCCache.Instance.appId + "&app_sign=" + BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString()) + "&timestamp=" + timestamp;

            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")
                {
                    BCSubscription sub = new BCSubscription();
                    sub.ID = responseData["subscription"]["id"].ToString();
                    sub.buyerID = responseData["subscription"]["buyer_id"].ToString();
                    sub.planID = responseData["subscription"]["plan_id"].ToString();
                    sub.cardID = responseData["subscription"]["card_id"].ToString();
                    sub.bankName = responseData["subscription"]["bank_name"].ToString();
                    sub.IDName = responseData["subscription"]["id_name"].ToString();
                    sub.IDNo = responseData["subscription"]["id_no"].ToString();
                    sub.mobile = responseData["subscription"]["mobile"].ToString();
                    sub.amount = (double)responseData["subscription"]["amount"];
                    sub.couponID = responseData["subscription"]["coupon_id"].ToString();
                    sub.trialEnd = (long)responseData["subscription"]["trial_end"];
                    sub.optional = JsonMapper.ToObject<Dictionary<string, string>>(responseData["subscription"]["optional"].ToJson().ToString());

                    sub.last4 = responseData["subscription"]["last4"].ToString();
                    sub.status = responseData["subscription"]["status"].ToString();
                    sub.valid = (bool)responseData["subscription"]["valid"];
                    sub.cancelAtPeriodEnd = (bool)responseData["subscription"]["cancel_at_period_end"];
                    return sub;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            catch (Exception e)
            {
                var ex = new BCException(e.Message);
                throw ex;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 按条件查询用户订阅
        /// </summary>
        /// <param name="buyerID">用户ID</param>
        /// <param name="planID">订阅计划ID</param>
        /// <param name="cardID">用户卡ID</param>
        /// <param name="createdBefore">创建时间前</param>
        /// <param name="createdAfter">创建时间后</param>
        /// <param name="skip">跳过数量</param>
        /// <param name="limit">查询限量</param>
        /// <param name="countOnly">设置为true时只返回数量,设置为false时只返回plan记录</param>
        /// <returns></returns>
        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;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 创建订阅记录
        /// </summary>
        /// <param name="smsID">用户短信ID,通过sendSMS方法发送给用户手机时获得</param>
        /// <param name="smsCode">用户短信验证码</param>
        /// <param name="subscription">设置订阅参数</param>
        /// <returns></returns>
        public static BCSubscription createSubscription(string smsID, string smsCode, BCSubscription subscription)
        {
            long timestamp = BCUtil.GetTimeStamp(DateTime.Now);

            JsonData data = new JsonData();
            data["app_id"] = BCCache.Instance.appId;

            data["app_sign"] = BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString());

            data["timestamp"] = timestamp;
            data["sms_id"] = smsID;
            data["sms_code"] = smsCode;
            data["buyer_id"] = subscription.buyerID;
            data["plan_id"] = subscription.planID;
            data["card_id"] = subscription.cardID;
            data["bank_name"] = subscription.bankName;
            data["card_no"] = subscription.cardNo;
            data["id_name"] = subscription.IDName;
            data["id_no"] = subscription.IDNo;
            data["amount"] = subscription.amount;
            data["coupon_id"] = subscription.couponID;
            data["trial_end"] = subscription.trialEnd;
            data["mobile"] = subscription.mobile;

            if (subscription.optional != null && subscription.optional.Count > 0)
            {
                data["optional"] = new JsonData();
                foreach (string key in subscription.optional.Keys)
                {
                    data["optional"][key] = subscription.optional[key];
                }
            }

            string paraString = data.ToJson();

            string subscriptionURL = BCPrivateUtil.getHost() + BCConstants.version + BCConstants.bcsubscriptionURL;

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

                string respString = BCPrivateUtil.GetResponseString(response);

                JsonData responseData = JsonMapper.ToObject(respString);

                if (responseData["result_code"].ToString() == "0")
                {
                    subscription.ID = responseData["subscription"]["id"].ToString();
                    subscription.buyerID = responseData["subscription"]["buyer_id"].ToString();
                    subscription.planID = responseData["subscription"]["plan_id"].ToString();
                    subscription.bankName = responseData["subscription"]["bank_name"].ToString();
                    subscription.IDName = responseData["subscription"]["id_name"].ToString();
                    subscription.IDNo = responseData["subscription"]["id_no"].ToString();
                    subscription.mobile = responseData["subscription"]["mobile"].ToString();
                    subscription.amount = (double)responseData["subscription"]["amount"];
                    subscription.couponID = responseData["subscription"]["coupon_id"].ToString();
                    subscription.trialEnd = (long)responseData["subscription"]["trial_end"];
                    subscription.optional = JsonMapper.ToObject<Dictionary<string, string>>(responseData["subscription"]["optional"].ToJson().ToString());
                    subscription.last4 = responseData["subscription"]["last4"].ToString();
                    subscription.status = responseData["subscription"]["status"].ToString();
                    subscription.valid = (bool)responseData["subscription"]["valid"];
                    subscription.cancelAtPeriodEnd = (bool)responseData["subscription"]["cancel_at_period_end"];
                    return subscription;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            catch (Exception e)
            {
                var ex = new BCException(e.Message);
                throw ex;
            }
        }