Exemple #1
0
        /// <summary>
        /// 创建卡券
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="cardInfo">创建卡券需要的数据,格式可以看CardCreateData.cs</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static CardCreateResultJson CreateCard(string accessTokenOrAppId, BaseCardInfo cardInfo, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var urlFormat = string.Format("https://api.weixin.qq.com/card/create?access_token={0}", accessToken);

                CardCreateInfo cardData = null;
                CardType cardType = cardInfo.GetCardType();

                switch (cardType)
                {
                case CardType.GENERAL_COUPON:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_GeneralCoupon()
                        {
                            card_type = cardType.ToString(),
                            general_coupon = cardInfo as Card_GeneralCouponData
                        }
                    };
                    break;

                case CardType.GROUPON:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Groupon()
                        {
                            card_type = cardType.ToString(),
                            groupon = cardInfo as Card_GrouponData
                        }
                    };
                    break;

                case CardType.GIFT:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Gift()
                        {
                            card_type = cardType.ToString(),
                            gift = cardInfo as Card_GiftData
                        }
                    };
                    break;

                case CardType.CASH:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_Cash()
                        {
                            card_type = cardType.ToString(),
                            cash = cardInfo as Card_CashData
                        }
                    };
                    break;

                case CardType.DISCOUNT:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_DisCount()
                        {
                            card_type = cardType.ToString(),
                            discount = cardInfo as Card_DisCountData
                        }
                    };
                    break;

                case CardType.MEMBER_CARD:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MemberCard()
                        {
                            card_type = cardType.ToString(),
                            member_card = cardInfo as Card_MemberCardData
                        }
                    };
                    break;

                case CardType.SCENIC_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_ScenicTicket()
                        {
                            card_type = cardType.ToString(),
                            scenic_ticket = cardInfo as Card_ScenicTicketData
                        }
                    };
                    break;

                case CardType.MOVIE_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MovieTicket()
                        {
                            card_type = cardType.ToString(),

                            movie_ticket = cardInfo as Card_MovieTicketData
                        }
                    };
                    break;

                case CardType.BOARDING_PASS:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_BoardingPass()
                        {
                            card_type = cardType.ToString(),
                            boarding_pass = cardInfo as Card_BoardingPassData
                        }
                    };
                    break;

                case CardType.LUCKY_MONEY:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_LuckyMoney()
                        {
                            card_type = cardType.ToString(),
                            lucky_money = cardInfo as Card_LuckyMoneyData
                        }
                    };
                    break;

                case CardType.MEETING_TICKET:
                    cardData = new CardCreateInfo()
                    {
                        card = new Card_MeetingTicket()
                        {
                            card_type = cardType.ToString(),
                            meeting_ticket = cardInfo as Card_MeetingTicketData
                        }
                    };
                    break;

                default:
                    break;
                }

                var jsonSetting = new JsonSetting(true, null,
                                                  new List <Type>()
                {
                    //typeof (Modify_Msg_Operation),
                    //typeof (CardCreateInfo),
                    typeof(Card_BaseInfoBase)     //过滤Modify_Msg_Operation主要起作用的是这个
                });

                var result = CommonJsonSend.Send <CardCreateResultJson>(null, urlFormat, cardData, timeOut: timeOut,
                                                                        //针对特殊字段的null值进行过滤
                                                                        jsonSetting: jsonSetting);
                return result;
            }, accessTokenOrAppId));
        }
Exemple #2
0
        /// <summary>
        /// 创建卡券
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="cardInfo">创建卡券需要的数据,格式可以看CardCreateData.cs</param>
        /// <returns></returns>
        public static CardCreateResultJson CreateCard(string accessToken, BaseCardInfo cardInfo)
        {
            var urlFormat = string.Format("https://api.weixin.qq.com/card/create?access_token={0}", accessToken);

            CardCreateInfo cardData = null;
            CardType       cardType = cardInfo.CardType;

            switch (cardType)
            {
            case CardType.GENERAL_COUPON:
                cardData = new CardCreateInfo()
                {
                    card = new Card_GeneralCoupon()
                    {
                        card_type      = cardType,
                        general_coupon = cardInfo as Card_GeneralCouponData
                    }
                };
                break;

            case CardType.GROUPON:
                cardData = new CardCreateInfo()
                {
                    card = new Card_Groupon()
                    {
                        card_type = cardType,
                        groupon   = cardInfo as Card_GrouponData
                    }
                };
                break;

            case CardType.GIFT:
                cardData = new CardCreateInfo()
                {
                    card = new Card_Gift()
                    {
                        card_type = cardType,
                        gift      = cardInfo as Card_GiftData
                    }
                };
                break;

            case CardType.CASH:
                cardData = new CardCreateInfo()
                {
                    card = new Card_Cash()
                    {
                        card_type = cardType,
                        cash      = cardInfo as Card_CashData
                    }
                };
                break;

            case CardType.DISCOUNT:
                cardData = new CardCreateInfo()
                {
                    card = new Card_DisCount()
                    {
                        card_type = cardType,
                        discount  = cardInfo as Card_DisCountData
                    }
                };
                break;

            case CardType.MEMBER_CARD:
                cardData = new CardCreateInfo()
                {
                    card = new Card_MemberCard()
                    {
                        card_type   = cardType,
                        member_card = cardInfo as Card_MemberCardData
                    }
                };
                break;

            case CardType.SCENIC_TICKET:
                cardData = new CardCreateInfo()
                {
                    card = new Card_ScenicTicket()
                    {
                        card_type     = cardType,
                        scenic_ticket = cardInfo as Card_ScenicTicketData
                    }
                };
                break;

            case CardType.MOVIE_TICKET:
                cardData = new CardCreateInfo()
                {
                    card = new Card_MovieTicket()
                    {
                        card_type = cardType,

                        movie_ticket = cardInfo as Card_MovieTicketData
                    }
                };
                break;

            case CardType.BOARDING_PASS:
                cardData = new CardCreateInfo()
                {
                    card = new Card_BoardingPass()
                    {
                        card_type     = cardType,
                        boarding_pass = cardInfo as Card_BoardingPassData
                    }
                };
                break;

            case CardType.LUCKY_MONEY:
                cardData = new CardCreateInfo()
                {
                    card = new Card_LuckyMoney()
                    {
                        card_type   = cardType,
                        lucky_money = cardInfo as Card_LuckyMoneyData
                    }
                };
                break;

            default:
                break;
            }

            return(CommonJsonSend.Send <CardCreateResultJson>(null, urlFormat, cardData));
        }