public RESTfulModel GetJSAPIConfig(string authorizerAppID, string url) { try { AuthorizationInfoModel authorizationInfoModel = accessTokenDAL.Get(authorizerAppID); string jsapiTicket = authorizationInfoModel.JSAPITicket; string timestamp = UtilsHelper.GetTimestamp(); string nonceStr = UtilsHelper.GetNonceStr(); string format = "jsapi_ticket={0}&noncestr={1}×tamp={2}&url={3}"; string stringToHash = string.Format(format, jsapiTicket, nonceStr, timestamp, url); string signature = UtilsHelper.SHA1(stringToHash); return(new RESTfulModel() { Code = (int)CodeEnum.成功, Msg = string.Format(codeMsgDAL.GetByCode((int)CodeEnum.成功), "成功"), Data = new JSAPIConfigModel() { Timestamp = timestamp, NonceStr = nonceStr, Signature = signature } }); } catch (Exception ex) { LogHelper.Error(ex); return(new RESTfulModel() { Code = (int)CodeEnum.系统异常, Msg = codeMsgDAL.GetByCode((int)CodeEnum.系统异常) }); } }
// 卡面 public MemberCardModel GetModel(string authorizerAppID) { try { AuthorizationInfoModel authorizationInfoModel = accessTokenDAL.Get(authorizerAppID); string authorizerAccessToken = authorizationInfoModel.AuthorizerAccessToken; LogHelper.Info("8.6.4 查看卡券详情 authorizerAccessToken", authorizerAccessToken); // 可以删除 //string url = "https://api.weixin.qq.com/card/user/getcardlist?access_token=" + authorizerAccessToken; //LogHelper.Info("2 获取用户已领取卡券接口 url", url); //CardListGetReq req = new CardListGetReq() //{ // OpenID = openID, // CardID = cardID //}; //string requestBody = JsonConvert.SerializeObject(req); //LogHelper.Info("2 获取用户已领取卡券接口 requestBody", requestBody); //string responseBody = HttpHelper.Post(url, requestBody); //LogHelper.Info("2 获取用户已领取卡券接口 responseBody", responseBody); //CardListGetResp resp = JsonConvert.DeserializeObject<CardListGetResp>(responseBody); CardInfoModel cardInfoModel = cardInfoDAL.GetModel(authorizerAppID); if (cardInfoModel == null) { // 未创建会员卡 } // 会员卡信息,建议先保存微信服务器,然后保存本地服务器,修改同理,这里可以从本地服务器查询 string url = "https://api.weixin.qq.com/card/get?access_token=" + authorizerAccessToken; LogHelper.Info("8.6.4 查看卡券详情 url", url); CardGetReq req = new CardGetReq() { CardID = cardInfoModel.CardID }; string requestBody = JsonConvert.SerializeObject(req); LogHelper.Info("8.6.4 查看卡券详情 requestBody", requestBody); string responseBody = HttpHelper.Post(url, requestBody); LogHelper.Info("8.6.4 查看卡券详情 responseBody", responseBody); CardGetResp resp = JsonConvert.DeserializeObject <CardGetResp>(responseBody); var memberCard = resp.Card.MemberCard; return(new MemberCardModel() { CardID = cardInfoModel.CardID, BackgroundPicUrl = memberCard.BackgroundPicUrl, LogoUrl = memberCard.BaseInfo.LogoUrl, BrandName = memberCard.BaseInfo.BrandName, Title = memberCard.BaseInfo.Title }); } catch (Exception ex) { LogHelper.Error(ex); return(null); } }
static void Main(string[] args) { //string cardID = "pp8Cv1bypNXD5z-KwoatVEaYJa0w"; //string apiTicket = "9KwiourQPRN3vx3Nn1c_iXKXdRjqsvnKe_KV_HB6ZofIGZwZJ6XmXxkgI4xvjssApkcK8mxUN8jSd4EMcism-Q"; //string timestamp = UtilsHelper.GetTimestamp(); //string nonceStr = UtilsHelper.GetNonceStr(); //string signature = UtilsHelper.GenarateSignature(apiTicket, timestamp, cardID, nonceStr); //Console.WriteLine(signature); AuthorizationInfoModel authorizationInfoModel = accessTokenDAL.Get("wxab6d7123cc1125f5"); Console.ReadLine(); }
public string UploadIMG(string authorizerAppID, HttpFileCollectionBase files) { try { if (files != null) { HttpPostedFileBase file = files[0]; float mbSize = (float)file.ContentLength / 1048576; if (mbSize <= 1) { AuthorizationInfoModel authorizationInfoModel = accessTokenDAL.Get(authorizerAppID); string url = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=" + authorizationInfoModel.AuthorizerAccessToken; LogHelper.Info("上传图片 url", url); //UploadIMGReq req = new UploadIMGReq() //{ // Buffer = file.InputStream //}; //string requestBody = JsonConvert.SerializeObject(req); //LogHelper.Info("上传图片 requestBody", requestBody); string responseBody = HttpHelper.Post(url, file.FileName, file.InputStream); LogHelper.Info("上传图片 responseBody", responseBody); UploadIMGResp resp = JsonConvert.DeserializeObject <UploadIMGResp>(responseBody); if (resp.ErrCode == 0) { return(JsonConvert.SerializeObject(new RESTfulModel() { Code = (int)CodeEnum.成功, Msg = string.Format(codeMsgDAL.GetByCode((int)CodeEnum.成功), "上传成功"), Data = resp.Url })); } else { string msg = "errcode: " + resp.ErrCode + ", errmsg: " + resp.ErrMsg; return(JsonConvert.SerializeObject(new RESTfulModel() { Code = (int)CodeEnum.失败, Msg = string.Format(codeMsgDAL.GetByCode((int)CodeEnum.失败), msg) })); } } return(JsonConvert.SerializeObject(new RESTfulModel() { Code = (int)CodeEnum.文件大小超限, Msg = codeMsgDAL.GetByCode((int)CodeEnum.文件大小超限) })); } return(JsonConvert.SerializeObject(new RESTfulModel() { Code = (int)CodeEnum.文件集合为空, Msg = codeMsgDAL.GetByCode((int)CodeEnum.文件集合为空) })); } catch (Exception ex) { LogHelper.Error(ex); return(JsonConvert.SerializeObject(new RESTfulModel() { Code = (int)CodeEnum.系统异常, Msg = codeMsgDAL.GetByCode((int)CodeEnum.系统异常) })); } }
// 与腾讯服务器交换信息 private string GetCount(string authorizerAppID, string type) { try { string url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=" + accessTokenDAL.Get(authorizerAppID); string responseBody = HttpHelper.Get(url); LogHelper.Info("获取素材总数 responseBody", responseBody); //int count = 0; //switch (type) //{ // case "voice_count": count = resp.VoiceCount; break; // case "video_count": count = resp.VideoCount; break; // case "image_count": count = resp.ImageCount; break; // case "news_count": count = resp.NewsCount; break; //} return(responseBody); } catch (Exception ex) { LogHelper.Error(ex); return(null); } }
public PagedList <EntityShopInfoModel> GetPageList(string authorizerAppID, int pageIndex, int pageSize) { try { AuthorizationInfoModel authorizationInfoModel = accessTokenDAL.Get(authorizerAppID); string url = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=" + authorizationInfoModel.AuthorizerAccessToken; LogHelper.Info("3.5查询门店列表 url", url); EntityShopListGetReq req = new EntityShopListGetReq() { Begin = pageIndex, Limit = pageSize, }; string requestBody = JsonConvert.SerializeObject(req); LogHelper.Info("3.5查询门店列表 requestBody", requestBody); //string responseBody = HttpHelper.Post(url, requestBody); //LogHelper.Info("3.5查询门店列表 responseBody", responseBody); string responseBody = "{\"errcode\":0,\"errmsg\":\"ok\",\"business_list\":[{\"base_info\":{\"sid\":\"\",\"business_name\":\"朝外MEN写字楼\",\"branch_name\":\"\",\"address\":\"朝外大街26号\",\"telephone\":\"15210470906\",\"categories\":[\"公司企业,企业/工厂\"],\"city\":\"北京市\",\"province\":\"\",\"offset_type\":1,\"longitude\":116.442108154,\"latitude\":39.9230194092,\"photo_list\":[{\"photo_url\":\"http://mmbiz.qpic.cn/mmbiz_png/jTItpJe45JLNBQjKKiapJicznbYVMicDXGzs4EaNVgiao57JSlLgYxrh1OplMF8tr8DJ7RmlAeJmv1h22EePgSl1OQ/0?wx_fmt=png\"}],\"introduction\":\"\",\"recommend\":\"\",\"special\":\"\",\"open_time\":\"10:00-21:00\",\"avg_price\":100,\"poi_id\":\"468757507\",\"available_state\":3,\"district\":\"朝阳区\",\"update_status\":0,\"qualification_list\":[]}}],\"total_count\":1}"; EntityShopListGetResp resp = JsonConvert.DeserializeObject <EntityShopListGetResp>(responseBody); // 直接处理,api 需要返回错误码 List <EntityShop> entityShopList = resp.BusinessList; List <EntityShopInfoModel> modelList = new List <EntityShopInfoModel>(); if (entityShopList != null && entityShopList.Any()) { List <EntityShopInfo> entityShopInfoList = entityShopList.Select(o => o.BaseInfo).ToList(); foreach (var entityShopInfo in entityShopInfoList) { modelList.Add(new EntityShopInfoModel() { SID = entityShopInfo.SID, BusinessName = entityShopInfo.BusinessName, BranchName = entityShopInfo.BranchName, Address = entityShopInfo.Address, Telephone = entityShopInfo.Telephone, Categories = entityShopInfo.Categories, City = entityShopInfo.City, Province = entityShopInfo.Province, OffsetType = entityShopInfo.OffsetType, Longitude = entityShopInfo.Longitude, Latitude = entityShopInfo.Latitude, PhotoList = entityShopInfo.PhotoList.Select(o => o.PhotoUrl).ToList(), Introduction = entityShopInfo.Introduction, Recomend = entityShopInfo.Recomend, Special = entityShopInfo.Special, OpenTime = entityShopInfo.OpenTime, AvgPrice = entityShopInfo.AvgPrice, PoiID = entityShopInfo.PoiID, AvailableState = entityShopInfo.AvailableState, District = entityShopInfo.District, UpdateStatus = entityShopInfo.UpdateStatus }); } } return(new PagedList <EntityShopInfoModel>(modelList, pageIndex, pageSize, resp.TotalCount)); } catch (Exception ex) { LogHelper.Error(ex); return(null); } }
/// <summary> /// 1.仅部分类目可创建会员卡,非开放类目将返回错误码,类目明细见会员卡公告https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1461052555&version=1&lang=zh_CN&platform=2 /// 2.创建会员卡时,需设置会员卡激活后呈现的信息类目,目前支持积分、余额、等级、优惠券、里程、印花、成就、折扣等类型,微信6.2以上版本显示会员信息类目的上限为3个,即创建时类目字段supply_bonus 、supply_balance、 custom_field1、custom_field2 、custom_field3最多选择三项填写。 /// 3.创建卡券时,开发者填入的时间戳须注意时间戳溢出时间,设置的时间戳须早于2038年1月19日,若要设置更久的有效期,可以选择永久有效类型的有效期。 /// </summary> public string Create(string authorizerAppID, MemberCardModel model) { try { Card card = new Card() { CardType = "MEMBER_CARD", MemberCard = new MemberCard() { BackgroundPicUrl = model.BackgroundPicUrl, BaseInfo = new MemberCardBaseInfo() { LogoUrl = model.LogoUrl, BrandName = model.BrandName, CodeType = "CODE_TYPE_QRCODE", Title = model.Title, Color = "Color010", Notice = model.Notice, ServicePhone = model.ServicePhone, Description = model.Description, DateInfo = new DataInfo() { Type = "DATE_TYPE_PERMANENT" }, Sku = new Sku() { Quantity = 100000000 }, GetLimit = 1, CanGiveFriend = false, CanShare = false, UseCustomCode = false, UseAllLocations = true, CenterTitle = "会员买单", //CenterSubTitle = "买单立享" + model.Discount + "折,更有积分相送", CenterUrl = "http://" + authorizerAppID + "." + ConfigHelper.DomainWeChat + "/order/create" // custom_url_name // custom_url // custom_url_sub_title // promotion_url_name // promotion_url // promotion_url_sub_title // need_push_on_view }, AdvancedInfo = new MemberCardAdvancedInfo() { BusinessService = new List <string>() { "BIZ_SERVICE_FREE_WIFI", "BIZ_SERVICE_WITH_PET", "BIZ_SERVICE_FREE_PARK", "BIZ_SERVICE_DELIVER" } }, // 会员卡特权说明 Prerogative = model.Prerogative, // 激活相关 AutoActivate = false, WXActivate = false, // 激活页面 ActivateUrl = "http://" + authorizerAppID + "." + ConfigHelper.DomainWeChat + "/membercard/activate", // 是否支持储值 SupplyBalance = false, //CustomField1 = new CustomField() //{ // // 不行就用 Name , 积分变动触发 is_notify_bonus // // 其他两个触发 is_notify_custom_field2 is_notify_custom_field3 // NameType = "FIELD_NAME_TYPE_STAMP", // Url = string.Format(ConfigHelper.DomainWeChat, authorizerAppID) + "bonus" //}, CustomField2 = new CustomField() { NameType = "FIELD_NAME_TYPE_COUPON", Url = string.Format(ConfigHelper.DomainWeChat, authorizerAppID) + "coupon" }, CustomField3 = new CustomField() { NameType = "FIELD_NAME_TYPE_LEVEL", Url = string.Format(ConfigHelper.DomainWeChat, authorizerAppID) + "level" }, // 积分相关 SupplyBonus = true, BonusRule = new BonusRule() { // 满 CostMoneyUnit = model.CostMoneyUnit, // 送 IncreaseBonus = model.IncreaseBonus, // 单次获得上限 MaxIncreaseBonus = model.MaxIncreaseBonus, // 初始积分 InitIncreaseBonus = model.InitIncreaseBonus, // 用积分 CostBonusUnit = model.CostBonusUnit, // 抵现金 ReduceMoney = model.ReduceMoney, // 抵扣条件,满xx元(这里以分为单位)可用 LeastMoneyToUseBonus = model.LeastMoneyToUseBonus, // 抵扣条件,单笔最多使用xx积分。 MaxReduceBonus = model.MaxReduceBonus }, Discount = model.Discount } }; AuthorizationInfoModel authorizationInfoModel = accessTokenDAL.Get(authorizerAppID); string url = "https://api.weixin.qq.com/card/create?access_token=" + authorizationInfoModel.AuthorizerAccessToken; LogHelper.Info("创建会员卡 url", url); string requestBody = JsonConvert.SerializeObject(card); LogHelper.Info("创建会员卡 requestBody", requestBody); string responseBody = HttpHelper.Post(url, requestBody); LogHelper.Info("创建会员卡 responseBody", responseBody); CardCreateResp resp = JsonConvert.DeserializeObject <CardCreateResp>(responseBody); if (resp.ErrCode == 0) { // 存储 authorizerAppID 和 cardID 之间的对应关系 cardInfoDAL.Insert(authorizerAppID, resp.CardID, DateTime.Now); return(JsonConvert.SerializeObject(new RESTfulModel() { Code = (int)CodeEnum.成功, Msg = string.Format(codeMsgDAL.GetByCode((int)CodeEnum.成功), "创建成功") })); } else { string msg = "errcode: " + resp.ErrCode + ", errmsg: " + resp.ErrMsg; return(JsonConvert.SerializeObject(new RESTfulModel() { Code = (int)CodeEnum.失败, Msg = string.Format(codeMsgDAL.GetByCode((int)CodeEnum.失败), msg) })); } } catch (Exception ex) { LogHelper.Error(ex); return(JsonConvert.SerializeObject(new RESTfulModel() { Code = (int)CodeEnum.系统异常, Msg = codeMsgDAL.GetByCode((int)CodeEnum.系统异常) })); } }