Пример #1
0
        private BaseCard GetCard(JObject result, string cardType)
        {
            JEnumerable <JToken> nodes = result["card"][cardType.ToLower()].Children();
            Type     type = _cardTypes[cardType];
            BaseCard card = (BaseCard)Activator.CreateInstance(type);

            PropertyInfo[] properties = type.GetProperties();
            foreach (JProperty item in nodes)
            {
                string name = item.Name;
                if (name == "base_info")
                {
                    card.base_info = this.ToBaseModel(item.Value, cardType);
                    continue;
                }
                if (name == "advanced_info")
                {
                    card.advanced_info = this.ToAdModel(item.Value, cardType);
                    continue;
                }

                PropertyInfo p   = properties.Where(t => t.Name == name).FirstOrDefault();
                object       val = item.Value.ToObject(p.PropertyType);
                p.SetValue(card, Convert.ChangeType(val, p.PropertyType), null);
            }
            return(card);
        }
Пример #2
0
        /// <summary>
        /// 创建卡券
        /// </summary>
        /// <param name="access_token">公众号access token</param>
        /// <param name="card_type">卡券类型</param>
        /// <param name="data">卡券数据</param>
        /// <returns>data字段为card_id</returns>
        public JsonResult <string> CreateCard(string access_token, string card_type, BaseCard data)
        {
            DynamicDictionary dic = new DynamicDictionary();

            dic.SetMember("card_type", card_type?.ToUpper());
            dic.SetMember(card_type?.ToLower(), data);
            var obj = new
            {
                card = dic.GetMembers()
            };
            string url = $"{Config.WxApi}card/create?access_token={access_token}";

            return(WxAPI.RequestData <string>(url, obj, Method.POST));
        }
Пример #3
0
        /// <summary>
        /// 更改卡券信息
        /// </summary>
        /// <param name="access_token">公众号access token</param>
        /// <param name="card_type">卡券类型 全大写</param>
        /// <param name="card_id">卡券id</param>
        /// <param name="data">卡券数据</param>
        /// <returns></returns>
        public JsonResult <bool> UpdateCard(string access_token, string card_type, string card_id, BaseCard data)
        {
            DynamicDictionary dic = new DynamicDictionary();

            dic.SetMember("card_id", card_id);
            dic.SetMember(card_type.ToLower(), data);
            string url = $"{Config.WxApi}card/update?access_token={access_token}";

            return(WxAPI.RequestData <bool>(url, dic.GetMembers(), Method.POST));
        }