public void CreateCardTest() { var accessToken = AccessTokenContainer.GetToken(_appId); var data = new Card_GrouponData() { base_info = _BaseInfo, deal_detail = "测试" }; var result = CardApi.CreateCard(accessToken, data); Console.Write(result); Assert.IsNotNull(result); }
public void CreateCardTest() { //var accessToken = AccessTokenContainer.GetAccessToken("wx4f8e94b7a153ff43"); string accessToken = "11_jFGzse3a4wGPBq8cCTsKUMGabo2V_dmJVKHKiltmkNmhTSKHv8J6BaJ5nTQ6-eTeNhdh1LNNOcGEkbYelx6DlFaSx9wIcOIlaKGMMJujb9BptSNhWnDq7Vpyb_oQuFT_nYJpp7bOnT5ew1kESKBcACAMEV"; var data = new Card_MemberCardData() { base_info = _BaseInfo, supply_bonus = true, supply_balance = false, prerogative = "123123", bind_old_card_url = "www.daidu.com", wx_activate = true }; var result = CardApi.CreateCard(accessToken, data); //var data = new Card_GrouponData() // { // base_info = _BaseInfo, // deal_detail = "测试" // }; //var result = CardApi.CreateCard(accessToken, data); //Console.Write(result); //Assert.IsNotNull(result); //var data3 = new Card_CashData() //{ // base_info = _BaseInfo, // least_cost = 11, // reduce_cost = 11 //}; //var result3 = CardApi.CreateCard(accessToken, data3); //Console.WriteLine(result3); //Assert.IsNotNull(result3); //var data2 = new Card_MeetingTicketData() // { // base_info = _BaseInfo, // //map_url = "http://localhost:18666/images/v2/logo%20.png", // meeting_detail = "测试asdsasdsasdsa" // }; //var result2 = CardApi.CreateCard(accessToken, data2); //Assert.IsNotNull(result2); //Console.WriteLine(result2.errmsg); }
public IEnumerable <string> Get() { try { AccessTokenContainer.Register("wx4f8e94b7a153ff43", "700fcec799b8ff8f1463eb31585eafbc"); var accessToken = AccessTokenContainer.GetAccessToken("wx4f8e94b7a153ff43"); Card_GrouponData data1 = new Card_GrouponData() { base_info = _BaseInfo, deal_detail = "测试" }; //string json = JsonConvert.SerializeObject(card_BaseInfoBase); var result1 = CardApi.CreateCard(accessToken, data1); var data = new Card_MemberCardData() { base_info = _BaseInfo, supply_bonus = true, supply_balance = false, prerogative = "123123", bind_old_card_url = "www.daidu.com", wx_activate = true }; var result = CardApi.CreateCard(accessToken, data); } catch (Exception ex) { throw; } return(new string[] { "value1", "value2" }); }
public void CreateCardTest() { var accessToken = AccessTokenContainer.GetAccessToken(_appId); var data = new Card_GrouponData() { base_info = _BaseInfo, deal_detail = "测试" }; var result = CardApi.CreateCard(accessToken, data); Console.Write(result); Assert.IsNotNull(result); var data3 = new Card_CashData() { base_info = _BaseInfo, least_cost = 11, reduce_cost = 11 }; var result3 = CardApi.CreateCard(accessToken, data3); Console.WriteLine(result3); Assert.IsNotNull(result3); var data2 = new Card_MeetingTicketData() { base_info = _BaseInfo, //map_url = "http://localhost:18666/images/v2/logo%20.png", meeting_detail = "测试asdsasdsasdsa" }; var result2 = CardApi.CreateCard(accessToken, data2); Assert.IsNotNull(result2); Console.WriteLine(result2.errmsg); }
public JsonResult Create([FromBody] Card_CashData info) { //Card_CashData info = new Card_CashData(); info.least_cost = 100000; info.reduce_cost = 100000; info.base_info = new Card_BaseInfoBase(); info.base_info.brand_name = "测试商户名称"; info.base_info.can_share = false; info.base_info.code_type = Senparc.Weixin.MP.Card_CodeType.CODE_TYPE_QRCODE; info.base_info.color = "Color040"; //info.base_info.custom_url = "https://yufaquan.cn"; //info.base_info.custom_url_name = "自定义跳转地址测试"; //info.base_info.custom_url_sub_title = "点击进入自定义跳转地址"; info.base_info.date_info = new Card_BaseInfo_DateInfo(); info.base_info.date_info.fixed_begin_term = 0; info.base_info.date_info.fixed_term = 7; info.base_info.date_info.type = "2"; info.base_info.description = "长文本描述\r\n可以换行。最长一千字。"; info.base_info.get_limit = 1; //info.base_info.location_id_list= info.base_info.logo_url = "http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0"; info.base_info.notice = "此处为使用提醒消费时从这付款"; info.base_info.sku = new Card_BaseInfo_Sku(); info.base_info.sku.quantity = 100; info.base_info.sku.total_quantity = 100; info.base_info.sub_title = "券名副标题上限18字"; info.base_info.title = "券名1000元代金券"; info.base_info.use_all_locations = true; info.base_info.use_limit = 1; //info.base_info.promotion_url = "https://yufaquan.cn"; //info.base_info.promotion_url_name = "自定义外链跳转地址测试"; //info.base_info.promotion_url_sub_title = "点击进入自定义跳转外链地址"; var result = CardApi.CreateCard(AppId, info); return(new JsonResult(HttpResult.Success(result))); }
public void ConvertTest() { try { var appId = ""; var appSecret = ""; var accessToken = AccessTokenContainer.TryGetAccessToken(appId, appSecret); Card_GrouponData data1 = new Card_GrouponData() { base_info = _BaseInfo, deal_detail = "测试" }; //这个位置报错 var result1 = CardApi.CreateCard(accessToken, data1); var data = new Card_MemberCardData() { base_info = _BaseInfo, supply_bonus = true, supply_balance = false, prerogative = "123123", bind_old_card_url = "www.senparc.com", wx_activate = true }; var result = CardApi.CreateCard(accessToken, data); System.Console.WriteLine(result.ToJson()); } catch (Exception ex) { //这里如果刨除微信层面的异常,说明之前发送阶段已经测试通过 Assert.IsInstanceOfType(ex, typeof(WeixinException)); } }
/// <summary> /// 添加卡券 /// </summary> /// <param name="info"></param> public bool Add(WXCardLogInfo info) { bool issuccess = false; string acctoken = ""; string curHost = "http://" + Core.Helper.WebHelper.GetHost(); string imagefile = "/images/defaultwxlogo.png"; string wxlogo = Core.HimallIO.GetImagePath(imagefile); if (wxlogo.IndexOf("http") < 0) { wxlogo = curHost + imagefile; } var siteSetting = ServiceProvider.Instance <ISiteSettingService> .Create.GetSiteSettings(); var shopser = ServiceProvider.Instance <IShopService> .Create; var vshopser = ServiceProvider.Instance <IVShopService> .Create; CardCreateResultJson wxResultJson = new CardCreateResultJson(); #region 组织数据 //基础数据 Card_BaseInfoBase _BaseInfo = new Card_BaseInfoBase() { logo_url = wxlogo, brand_name = siteSetting.SiteName, code_type = Card_CodeType.CODE_TYPE_BARCODE, title = info.CardTitle, sub_title = info.CardSubTitle, color = info.CardColor, notice = "专供" + siteSetting.SiteName + "使用", description = @"" + (info.LeastCost > 0 ? "满¥" + (info.LeastCost / 100).ToString("F2") + "使用" : "无门槛使用") + ",有效期至" + info.BeginTime.ToString("yyyy年MM月dd日") + "-" + info.EndTime.ToString("yyyy年MM月dd日"), date_info = new Card_BaseInfo_DateInfo() { type = Card_DateInfo_Type.DATE_TYPE_FIX_TIME_RANGE.ToString(), begin_timestamp = DateTimeHelper.GetWeixinDateTime(info.BeginTime), end_timestamp = DateTimeHelper.GetWeixinDateTime(info.EndTime), }, sku = new Card_BaseInfo_Sku() { quantity = info.Quantity == 0 ? MaxStock : info.Quantity }, get_limit = info.GetLimit == 0 ? MaxStock : info.GetLimit, use_custom_code = false, bind_openid = false, can_share = false, can_give_friend = false, custom_url_name = "立即使用", }; //代金券数据 var cardData = new Card_GeneralCouponData() { base_info = _BaseInfo, default_detail = info.DefaultDetail }; #endregion #region 诊所发布 if (info.ShopId > 0) { _BaseInfo.custom_url = curHost + "/Shop/Home/" + info.ShopId.ToString(); } var vshopSetting = vshopser.GetVShopSetting(info.ShopId); var vshopinfo = vshopser.GetVShopByShopId(info.ShopId); var shopinfo = shopser.GetShop(info.ShopId); if (vshopSetting != null && shopinfo != null && vshopinfo != null) { if (!string.IsNullOrWhiteSpace(vshopSetting.AppId) && !string.IsNullOrWhiteSpace(vshopSetting.AppSecret)) { acctoken = GetAccessToken(vshopSetting.AppId, vshopSetting.AppSecret); if (!string.IsNullOrWhiteSpace(acctoken)) { _BaseInfo.brand_name = shopinfo.ShopName; if (!string.IsNullOrWhiteSpace(vshopinfo.WXLogo)) { wxlogo = curHost + vshopinfo.WXLogo; _BaseInfo.logo_url = wxlogo; } wxResultJson = CardApi.CreateCard(acctoken, cardData); if (wxResultJson.errcode == Senparc.Weixin.ReturnCode.请求成功) { info.AppId = vshopSetting.AppId; info.AppSecret = vshopSetting.AppSecret; info.CardId = wxResultJson.card_id; issuccess = true; } } } } #endregion if (!issuccess) { #region 平台发布 if (!string.IsNullOrWhiteSpace(siteSetting.WeixinAppId) && !string.IsNullOrWhiteSpace(siteSetting.WeixinAppSecret)) { acctoken = GetAccessToken(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret); if (!string.IsNullOrWhiteSpace(acctoken)) { _BaseInfo.brand_name = shopinfo.ShopName; if (!string.IsNullOrWhiteSpace(siteSetting.WXLogo)) { wxlogo = curHost + siteSetting.WXLogo; _BaseInfo.logo_url = wxlogo; } wxResultJson = CardApi.CreateCard(acctoken, cardData); if (wxResultJson.errcode == Senparc.Weixin.ReturnCode.请求成功) { info.AppId = siteSetting.WeixinAppId; info.AppSecret = siteSetting.WeixinAppSecret; info.CardId = wxResultJson.card_id; issuccess = true; } } } if (info.ShopId < 1) { _BaseInfo.custom_url = curHost + "/"; } #endregion } if (issuccess) { info.AuditStatus = (int)WXCardLogInfo.AuditStatusEnum.Auditin; //初始审核状态 //数据入库 Context.WXCardLogInfo.Add(info); Context.SaveChanges(); } return(issuccess); }
public bool Add(WXCardLogInfo info) { string str; bool flag = false; string accessToken = ""; string str1 = string.Concat("http://", WebHelper.GetHost()); string str2 = string.Concat(str1, "/images/defaultwxlogo.png"); SiteSettingsInfo siteSettings = Instance <ISiteSettingService> .Create.GetSiteSettings(); IShopService create = Instance <IShopService> .Create; IVShopService vShopService = Instance <IVShopService> .Create; CardCreateResultJson cardCreateResultJson = new CardCreateResultJson(); Card_BaseInfoBase cardBaseInfoBase = new Card_BaseInfoBase() { logo_url = str2, brand_name = siteSettings.SiteName, code_type = Card_CodeType.CODE_TYPE_BARCODE, title = info.CardTitle, sub_title = info.CardSubTitle, color = info.CardColor, notice = string.Concat("专供", siteSettings.SiteName, "使用") }; Card_BaseInfoBase cardBaseInfoBase1 = cardBaseInfoBase; string[] strArrays = new string[5]; string[] strArrays1 = strArrays; if (info.LeastCost > 0) { int leastCost = info.LeastCost / 100; str = string.Concat("满¥", leastCost.ToString("F2"), "使用"); } else { str = "无门槛使用"; } strArrays1[0] = str; strArrays[1] = ",有效期至"; strArrays[2] = info.BeginTime.ToString("yyyy年MM月dd日"); strArrays[3] = "-"; strArrays[4] = info.EndTime.ToString("yyyy年MM月dd日"); cardBaseInfoBase1.description = string.Concat(strArrays); Card_BaseInfo_DateInfo cardBaseInfoDateInfo = new Card_BaseInfo_DateInfo() { type = Card_DateInfo_Type.DATE_TYPE_FIX_TIME_RANGE.ToString(), begin_timestamp = Senparc.Weixin.Helpers.DateTimeHelper.GetWeixinDateTime(info.BeginTime), end_timestamp = Senparc.Weixin.Helpers.DateTimeHelper.GetWeixinDateTime(info.EndTime) }; cardBaseInfoBase.date_info = cardBaseInfoDateInfo; Card_BaseInfoBase cardBaseInfoBase2 = cardBaseInfoBase; Card_BaseInfo_Sku cardBaseInfoSku = new Card_BaseInfo_Sku() { quantity = (info.Quantity == 0 ? MaxStock : info.Quantity) }; cardBaseInfoBase2.sku = cardBaseInfoSku; cardBaseInfoBase.get_limit = (info.GetLimit == 0 ? MaxStock : info.GetLimit); cardBaseInfoBase.use_custom_code = false; cardBaseInfoBase.bind_openid = false; cardBaseInfoBase.can_share = false; cardBaseInfoBase.can_give_friend = false; cardBaseInfoBase.custom_url_name = "立即使用"; Card_BaseInfoBase shopName = cardBaseInfoBase; Card_GeneralCouponData cardGeneralCouponDatum = new Card_GeneralCouponData() { base_info = shopName, default_detail = info.DefaultDetail }; Card_GeneralCouponData cardGeneralCouponDatum1 = cardGeneralCouponDatum; if (info.ShopId > 0) { long shopId = info.ShopId; shopName.custom_url = string.Concat(str1, "/Shop/Home/", shopId.ToString()); } WXShopInfo vShopSetting = vShopService.GetVShopSetting(info.ShopId); VShopInfo vShopByShopId = vShopService.GetVShopByShopId(info.ShopId); ShopInfo shop = create.GetShop(info.ShopId, false); if (vShopSetting != null && shop != null && vShopByShopId != null && !string.IsNullOrWhiteSpace(vShopSetting.AppId) && !string.IsNullOrWhiteSpace(vShopSetting.AppSecret)) { accessToken = GetAccessToken(vShopSetting.AppId, vShopSetting.AppSecret); if (!string.IsNullOrWhiteSpace(accessToken)) { shopName.brand_name = shop.ShopName; if (!string.IsNullOrWhiteSpace(vShopByShopId.WXLogo)) { shopName.logo_url = string.Concat(str1, vShopByShopId.WXLogo); } cardCreateResultJson = CardApi.CreateCard(accessToken, cardGeneralCouponDatum1, 10000); if (cardCreateResultJson.errcode == ReturnCode.请求成功) { info.AppId = vShopSetting.AppId; info.AppSecret = vShopSetting.AppSecret; info.CardId = cardCreateResultJson.card_id; flag = true; } } } if (!flag) { if (!string.IsNullOrWhiteSpace(siteSettings.WeixinAppId) && !string.IsNullOrWhiteSpace(siteSettings.WeixinAppSecret)) { accessToken = GetAccessToken(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret); if (!string.IsNullOrWhiteSpace(accessToken)) { shopName.brand_name = shop.ShopName; if (!string.IsNullOrWhiteSpace(siteSettings.WXLogo)) { shopName.logo_url = string.Concat(str1, siteSettings.WXLogo); } cardCreateResultJson = CardApi.CreateCard(accessToken, cardGeneralCouponDatum1, 10000); if (cardCreateResultJson.errcode == ReturnCode.请求成功) { info.AppId = siteSettings.WeixinAppId; info.AppSecret = siteSettings.WeixinAppSecret; info.CardId = cardCreateResultJson.card_id; flag = true; } } } if (info.ShopId < 1) { shopName.custom_url = string.Concat(str1, "/"); } } if (flag) { info.AuditStatus = new int?(0); context.WXCardLogInfo.Add(info); context.SaveChanges(); } return(flag); }
protected void sub_save_Click(object sender, EventArgs e) { Model.Card_wx.Card_BaseInfo Fros = new Card_BaseInfo(); if (Card_type.Text.Length == 0 || title.Text.Length == 0 || brand_name.Text.Length == 0 || imagetext.Text.Length == 0 || Card_color.Text.Length == 0 || notice.Text.Length == 0 || description.InnerText.Length == 0 || time_day.Text.Length == 0 || Cardnumber.Text.Length == 0) { JscriptMsg("参数不能为空!", "back", "Error"); } else { _BaseInfo.code_type = Senparc.Weixin.MP.Card_CodeType.CODE_TYPE_QRCODE; Fros.logo_url = MyCommFun.getWebSite() + imagetext.Text; _BaseInfo.logo_url = MyCommFun.getWebSite() + imagetext.Text.ToString(); _BaseInfo.brand_name = brand_name.Text; Fros.brand_name = brand_name.Text; _BaseInfo.title = title.Text; Fros.title = title.Text; _BaseInfo.sub_title = sub_title.Text; Fros.sub_title = sub_title.Text; _BaseInfo.color = Card_color.Text; Fros.color = Card_color.Text; _BaseInfo.notice = notice.Text; Fros.notice = notice.Text; _BaseInfo.service_phone = service_phone.Text; Fros.service_phone = service_phone.Text; _BaseInfo.description = description.InnerText; Fros.description = description.InnerText; _BaseInfo.date_info.begin_timestamp = DateTimeHelper.GetWeixinDateTime(DateTime.Now); Fros.begin_timestamp = (DateTimeHelper.GetWeixinDateTime(DateTime.Now)).ToString();; _BaseInfo.date_info.end_timestamp = DateTimeHelper.GetWeixinDateTime(DateTime.Now.AddDays(int.Parse(time_day.Text))); Fros.end_timestamp = time_day.Text.ToString(); _BaseInfo.sku.quantity = int.Parse(Cardnumber.Text); Fros.quantity = int.Parse(Cardnumber.Text);; _BaseInfo.use_limit = int.Parse(user_limit.Text); Fros.use_limit = int.Parse(user_limit.Text); _BaseInfo.get_limit = int.Parse(get_limit.Text); Fros.get_limit = int.Parse(get_limit.Text); _BaseInfo.use_custom_code = code.Checked; Fros.use_custom_code = code.Checked; _BaseInfo.bind_openid = false; Fros.bind_openid = false; _BaseInfo.can_share = share_page.Checked; Fros.can_share = share_page.Checked; _BaseInfo.can_give_friend = share_card.Checked; _BaseInfo.url_name_type = Senparc.Weixin.MP.Card_UrlNameType.URL_NAME_TYPE_RESERVATION; Fros.can_give_friend = share_card.Checked; _BaseInfo.custom_url_name = url_name.Text; Fros.custom_url_name = url_name.Text; _BaseInfo.location_id_list = fghj(); _BaseInfo.custom_url_sub_title = sub_url_name.Text; Fros.custom_url_sub_title = sub_url_name.Text; _BaseInfo.custom_url = custom_url.Text; Fros.custom_url = custom_url.Text; _BaseInfo.promotion_url_name = pro_url_name.Text; Fros.promotion_url_name = pro_url_name.Text; _BaseInfo.promotion_url = pro_url.Text; Fros.promotion_url = pro_url.Text; if (Card_type.Text == "团购券") { Model.wx_userweixin weixin = GetWeiXinCode(); int wid = weixin.id; string accessToken = Token(); var data = new Senparc.Weixin.MP.AdvancedAPIs.Card.Card_GrouponData() { base_info = _BaseInfo, deal_detail = deal_detail.Text.ToString() }; BLL.Card_wx.Card_BaseInfo Add = new BLL.Card_wx.Card_BaseInfo(); Fros.wid = wid; Fros.deal_detail = deal_detail.Text; Fros.Card_type = Card_type.Text; Fros.Paycell = paycell.Checked; Fros.hexiao = hexiao.Checked; var result = CardApi.CreateCard(accessToken, data); Fros.Wx_Card_id = result.card_id; Add.Add(Fros); if (paycell.Checked == true) { CardApi.PayCellSet(accessToken, Fros.Wx_Card_id, true); ///设置微信买单功能 } if (hexiao.Checked == true) { CardApi.SelfConsumecellSet(Token(), Fros.Wx_Card_id, true); ///设置自助核销接口 } Console.Write(result); JscriptMsg("添加卡券成功!", "Card_wx_QR.aspx", "Success"); } else if (Card_type.Text == "代金券") { Model.wx_userweixin weixin = GetWeiXinCode(); int wid = weixin.id; string accessToken = Token(); var data = new Senparc.Weixin.MP.AdvancedAPIs.Card.Card_CashData() { base_info = _BaseInfo, least_cost = int.Parse(least_cost.Text), reduce_cost = int.Parse(reduce_cost.Text) }; BLL.Card_wx.Card_BaseInfo Add = new BLL.Card_wx.Card_BaseInfo(); Fros.wid = wid; Fros.Card_type = Card_type.Text; Fros.least_cost = least_cost.Text; Fros.reduce_cost = reduce_cost.Text; Fros.Paycell = paycell.Checked; Fros.hexiao = hexiao.Checked; var result = CardApi.CreateCard(accessToken, data); Fros.Wx_Card_id = result.card_id; Add.Add(Fros); if (paycell.Checked == true) { CardApi.PayCellSet(accessToken, Fros.Wx_Card_id, true); ///设置微信买单功能 } if (hexiao.Checked == true) { CardApi.SelfConsumecellSet(Token(), Fros.Wx_Card_id, true); ///设置自助核 销接口 } Console.Write(result); JscriptMsg("添加卡券成功!", "Card_wx_QR.aspx", "Success"); } else if (Card_type.Text == "折扣券") { Model.wx_userweixin weixin = GetWeiXinCode(); int wid = weixin.id; string accessToken = Token(); var data = new Senparc.Weixin.MP.AdvancedAPIs.Card.Card_DisCountData() { base_info = _BaseInfo, discount = float.Parse(discount.Text.ToString()) }; BLL.Card_wx.Card_BaseInfo Add = new BLL.Card_wx.Card_BaseInfo(); Fros.wid = wid; Fros.Card_type = Card_type.Text; Fros.discount = discount.Text; Fros.Paycell = paycell.Checked; Fros.hexiao = hexiao.Checked; var result = CardApi.CreateCard(accessToken, data); Fros.Wx_Card_id = result.card_id; Add.Add(Fros); if (paycell.Checked == true) { CardApi.PayCellSet(accessToken, Fros.Wx_Card_id, true); ///设置微信买单功能 } if (hexiao.Checked == true) { CardApi.SelfConsumecellSet(Token(), Fros.Wx_Card_id, true); ///设置自助核销接口 } Console.Write(result); JscriptMsg("添加卡券成功!", "Card_wx_QR.aspx", "Success"); } else if (Card_type.Text == "优惠券") { Model.wx_userweixin weixin = GetWeiXinCode(); int wid = weixin.id; string accessToken = Token(); var data = new Senparc.Weixin.MP.AdvancedAPIs.Card.Card_GeneralCouponData() { base_info = _BaseInfo, default_detail = default_detail.Text }; BLL.Card_wx.Card_BaseInfo Add = new BLL.Card_wx.Card_BaseInfo(); Fros.wid = wid; Fros.Card_type = Card_type.Text; Fros.default_detail = default_detail.Text; Fros.Paycell = paycell.Checked; Fros.hexiao = hexiao.Checked; var result = CardApi.CreateCard(accessToken, data); Fros.Wx_Card_id = result.card_id; Add.Add(Fros); if (paycell.Checked == true) { CardApi.PayCellSet(accessToken, Fros.Wx_Card_id, true); ///设置微信买单功能 } if (hexiao.Checked == true) { CardApi.SelfConsumecellSet(Token(), Fros.Wx_Card_id, true); ///设置自助核销接口 } Console.Write(result); JscriptMsg("添加卡券成功!", "Card_wx_QR.aspx", "Success"); } } }