/// <summary> /// 获取卡券领取地址 /// </summary> /// <param name="cardid"></param> /// <returns></returns> public string GetCardReceiveUrl(string cardid, long couponRecordId, WXCardLogInfo.CouponTypeEnum couponType) { string result = ""; if (!string.IsNullOrWhiteSpace(cardid)) { var card = Context.WXCardLogInfo.FirstOrDefault(d => d.CardId == cardid); if (card != null) { string acctoken = GetAccessToken(card.AppId, card.AppSecret); //生成记录 long logid = SyncCouponRecordInfo(cardid, couponRecordId, couponType); int outerid = (int)logid; CreateQRResultJson wxResultJson = CardApi.CreateQR(acctoken, card.CardId, null, null, null, false, null, outerid); if (wxResultJson.errcode == Senparc.Weixin.ReturnCode.请求成功) { result = wxResultJson.url; } else { Log.Info("[Coupon]" + ((int)wxResultJson.errcode).ToString() + ":" + wxResultJson.errmsg); } } } return(result); }
public string GetCardReceiveUrl(string cardid, long couponRecordId, WXCardLogInfo.CouponTypeEnum couponType) { string str = ""; if (!string.IsNullOrWhiteSpace(cardid)) { WXCardLogInfo wXCardLogInfo = context.WXCardLogInfo.FirstOrDefault((WXCardLogInfo d) => d.CardId == cardid); if (wXCardLogInfo != null) { string accessToken = GetAccessToken(wXCardLogInfo.AppId, wXCardLogInfo.AppSecret); int num = (int)SyncCouponRecordInfo(cardid, couponRecordId, couponType); CreateQRResultJson createQRResultJson = CardApi.CreateQR(accessToken, wXCardLogInfo.CardId); if (createQRResultJson.errcode != ReturnCode.请求成功) { int num1 = (int)createQRResultJson.errcode; Log.Info(string.Concat("[Coupon]", num1.ToString(), ":", createQRResultJson.errmsg)); } else { str = createQRResultJson.url; } } } return(str); }
public void CreateQRTest() { var accessToken = AccessTokenContainer.GetToken(_appId); var cardIdList = CardBatchGetTest(); var cardId = cardIdList.FirstOrDefault(); var result = CardApi.CreateQR(accessToken, cardId); Console.Write(result); Assert.IsNotNull(result); }
/// <summary> /// 创建二维码接口(投放二维码) /// </summary> /// <param name="cardId">卡券ID</param> /// <param name="code">卡券Code码,use_custom_code字段为true的卡券必须填写,非自定义code不必填写。</param> /// <param name="openId">指定领取者的openid,只有该用户能领取。bind_openid字段为true的卡券必须填写,非指定openid不必填写。 </param> /// <param name="expireSeconds">指定二维码的有效时间,范围是60 ~ 1800秒。不填默认为永久有效。</param> /// <param name="isUniqueCode">指定下发二维码,生成的二维码随机分配一个code,领取后不可再次扫描。填写true或false。默认false,注意填写该字段时,卡券须通过审核且库存不为0。 </param> /// <param name="outer_id">领取场景值,用于领取渠道的数据统计,默认值为0,字段类型为整型,长度限制为60位数字。用户领取卡券后触发的事件推送中会带上此自定义场景值。 </param> /// <returns></returns> public ActionResult CreateQRCode(string cardId, string code, string openId, string expireSeconds, bool isUniqueCode, string outer_id) { string qrcode_url = string.Empty; if (!VerifyParam("cardId,code,openId,outer_id")) { return(ErrMsg()); } var weChatConfig = GetWechatConfig(); var ret = CardApi.CreateQR(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, cardId, code, openId, null, false, outer_id); if (ret.ticket.Contains("=")) { qrcode_url = ret.ticket.Replace("=", "%3D").Replace("=", "%3D"); } else { qrcode_url = ret.ticket; } if (ret.errcode == Weixin.ReturnCode.请求成功) { return(Json(new { message = "", success = true, ticket = ret.ticket, show_qrcode_url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + qrcode_url }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { message = ret.errmsg, success = false }, JsonRequestBehavior.AllowGet)); } }
protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "toufang") { // int dd = int.Parse(lbtn_Update.CommandArgument.ToString()); int dd = int.Parse(e.Item.ItemIndex.ToString()); string Cardid = ((HiddenField)rptList.Items[dd].FindControl("HiddenField1")).Value; var cardId = Cardid; string accessToken = Token(); var result = CardApi.CreateQR(accessToken, cardId); string ticket = result.ticket; string url_image = GetShowQrCodeUrl(ticket); int ss = int.Parse(e.Item.ItemIndex.ToString()); Image sss = (Image)rptList.Items[ss].FindControl("Image2"); sss.ImageUrl = url_image; } else if (e.CommandName == "deletecard") { DropDownList dr = new DropDownList(); dr = (DropDownList)rptList.Controls[0].FindControl("DropDownList2"); string dd = dr.SelectedValue; int cardid = int.Parse(e.Item.ItemIndex.ToString()); string card_wx_id = ((HiddenField)rptList.Items[cardid].FindControl("HiddenField1")).Value; var result = CardApi.CardDelete(Token(), card_wx_id); if (result.errmsg == "ok") { bll.delete(card_wx_id); } else { string ss = result.errmsg; } string where = "wid=" + wid() + " and Card_type=团购券"; Rqlistb(where); } else if (e.CommandName == "update_q") { int dd = int.Parse(e.Item.ItemIndex.ToString()); string Cardid = ((HiddenField)rptList.Items[dd].FindControl("HiddenField1")).Value; var cardId = Cardid; string Cardtype = ((HiddenField)rptList.Items[dd].FindControl("hd2")).Value; string accessToken = Token(); int ss = int.Parse(e.Item.ItemIndex.ToString()); TextBox sss = (TextBox)rptList.Items[ss].FindControl("quantity"); var result = CardApi.CardDetailGet(accessToken, cardId); if (Cardtype == "团购券") { sss.Text = result.card.groupon.base_info.sku.quantity.ToString(); } else if (Cardtype == "代金券") { sss.Text = result.card.cash.base_info.sku.quantity.ToString(); } else if (Cardtype == "折扣券") { sss.Text = result.card.discount.base_info.sku.quantity.ToString(); } else if (Cardtype == "优惠券") { sss.Text = result.card.general_coupon.base_info.sku.quantity.ToString(); } Model.Card_wx.Card_BaseInfo Base = new Model.Card_wx.Card_BaseInfo(); Base.quantity = int.Parse(sss.Text); Base.Wx_Card_id = cardId; Base.wid = wid(); bll.Upadata_kucun(Base); // var result= CardApi.ModifyStock(Token(), Cardid, int.Parse(sss.Text)); // try // { // if (result.errmsg == "ok") // { // } // } // catch (Exception ex) // { // } } else if (e.CommandName == "exit") { int dd = int.Parse(e.Item.ItemIndex.ToString()); string Cardid = ((HiddenField)rptList.Items[dd].FindControl("HiddenField1")).Value; var cardId = Cardid; string Cardtype = ((HiddenField)rptList.Items[dd].FindControl("hd2")).Value; Response.Redirect("Card_wx_exid.aspx?cardtype=" + Cardtype + "&cardid=" + cardId + "&type=exit"); } }