示例#1
0
        //===============以下功能 未测试 有bug 自行改下=========================
        /// <summary>
        /// 读取充值卡类型列表
        /// </summary>
        /// <returns>充值卡类型列表</returns>
        public async static Task <List <CardType> > CardTypeList()
        {
            string timestamp = FreeYunUtil.ToTimeStamp(DateTime.Now).ToString();

            JObject dic = new JObject();

            dic.Add("timestamp", timestamp);
            dic.Add("macCode", macCode);
            dic.Add("secretKey", secretkey);


            var cardTypeList = new List <CardType>();
            var ret          = await Request(16, "");

            JObject json = (JObject)JsonConvert.DeserializeObject(ret);
            var     code = json["code"].ToString();

            if (code != "1035")
            {
                throw new Exception("读取卡类型失败,原因:" + GetMsg(code));
            }

            var cardList = FreeYunUtil.ToJArray((json["cardList"].ToString()));

            if (cardList != null && cardList.Count != 0)
            {
                for (var i = 0; i < cardList.Count; i++)
                {
                    var     str       = cardList[i].ToString();
                    JObject json_temp = (JObject)JsonConvert.DeserializeObject(str);
                    var     price     = FreeYunUtil.ToInt(json_temp["price"].ToString()) / 100;
                    var     name      = json_temp["name"].ToString();
                    var     id        = json_temp["id"].ToString();
                    var     value     = FreeYunUtil.ToInt(json_temp["value"].ToString());
                    cardTypeList.Add(new CardType(name, id, price, value));
                }
            }
            return(cardTypeList);
        }