示例#1
0
        /// <summary>
        /// 创建卡券。
        /// </summary>
        /// <param name="model">卡券模型。</param>
        /// <returns>卡券Id。</returns>
        public string Create(CardModel model)
        {
            var url = "https://api.weixin.qq.com/card/create?access_token=" + _accountModel.GetAccessToken();
            var type = GetCardTypeString(model.Type);
            var postData = new
            {
                card = new
                {
                    card_type = type
                }
            };
            var postJson = JsonConvert.SerializeObject(postData);
            var postObj = JObject.Parse(postJson);
            postObj["card"][type.ToLower()] = JObject.Parse(JsonConvert.SerializeObject(model));
            var content = postObj.ToString();

            var json = WeiXinHttpHelper.PostString(url, Encoding.UTF8.GetBytes(content));

            return JObject.Parse(json)["card_id"].Value<string>();
        }