public void CardApiTest_Add_ByJSON() { using (var fs = GetInputFile("qrcode.jpg")) { var result = _weChatApi.UploadImage("qrcode.jpg", fs); if (!result.IsSuccess()) { Assert.Fail("上传图片失败,返回结果如下:" + result.DetailResult + ";Msg:" + result.GetFriendlyMessage()); } var jsonStr = @" { ""card_type"": ""GROUPON"", ""groupon"":{ ""base_info"": { ""logo_url"": ""{logo_url}"", ""brand_name"": ""Test"", ""code_type"": ""CODE_TYPE_QRCODE"", ""title"": ""Test"", ""sub_title"": ""Test"", ""color"": ""Color020"", ""notice"": ""Test"", ""service_phone"": ""Test"", ""description"": ""阿达啥的"", ""date_info"": { ""type"": ""DATE_TYPE_FIX_TIME_RANGE"", ""begin_time"": ""2016-11-09"", ""end_time"": ""2017-11-09"", ""fixed_term"": 15, ""fixed_begin_term"": 0 }, ""sku"": { ""quantity"": 500000 }, ""get_limit"": 0, ""use_custom_code"": false, ""bind_openid"": false, ""can_share"": true, ""can_give_friend"": true, ""location_id_list"": [], ""center_title"": ""撒啊"", ""center_sub_title"": ""啊啊啊"", ""center_url"": """", ""custom_url_name"": """", ""custom_url"": """", ""custom_url_sub_title"": """", ""promotion_url_name"": """", ""promotion_url"": """", ""source"": """" }, ""advanced_info"": { ""use_condition"": { ""accept_category"": """", ""reject_category"": """", ""least_cost"": 0, ""object_use_for"": """", ""can_use_with_other_discount"": true }, ""abstract"": { ""abstract"": """", ""icon_url_list"": [] }, ""text_image_list"": [], ""time_limit"": [ { ""type"": ""MONDAY"", ""begin_hour"": 0, ""end_hour"": 10, ""begin_minute"": 10, ""end_minute"": 59 }, { ""type"": ""HOLIDAY"" } ], ""business_service"": [ ""BIZ_SERVICE_FREE_WIFI"", ""BIZ_SERVICE_WITH_PET"", ""BIZ_SERVICE_FREE_PARK"", ""BIZ_SERVICE_DELIVER"" ] }, ""default_detail"": """", ""gift"": """", ""discount"": 30, ""reduce_cost"": 10, ""least_cost"": 0, ""deal_detail"": ""Test"" } }"; jsonStr = jsonStr.Replace("{logo_url}", result.Url); var obj = _weChatApi.GetCardInfoByJson(jsonStr); if (obj == null) { Assert.Fail("反序列化对象失败!"); } if (obj is Groupon) { var groupon = obj as Groupon; if (groupon.Groupon_.BaseInfo.DateInfo is FixTimeRangeDateInfo) { var cardResult = _weChatApi.Add(obj); if (!cardResult.IsSuccess()) { Assert.Fail("创建卡券失败,返回结果如下:" + cardResult.DetailResult + ";Msg:" + cardResult.GetFriendlyMessage()); } } else { Assert.Fail("反序列化对象失败!"); } } else { Assert.Fail("反序列化对象失败!"); } } }