public IWebClient TokenandWebClientSetupRemoteCall(out string token) { WebClientWrapper wclient = new WebClientWrapper(new MockWebClient()); var apiCall = new TokenApi(Settings.Default.BaseUrl, 1, Settings.Default.ApiDeveloperId, Settings.Default.ApiKey, wclient); token = apiCall.GetToken("*****@*****.**", "P@ssword123"); return wclient; }
public Mock<IWebClient> TokenandWebClientSetup(out string token) { string tokenResult = "Sample_Token"; Mock<IWebClient> mockWebClient = new Mock<IWebClient>(); mockWebClient.Setup(x => x.UploadString(new Uri(BaseUri, @"v2/account/token"), "POST", "{\"email\":\"[email protected]\",\"password\":\"Password@123\",\"hospitalId\":1,\"userTypeId\":1}")) .Returns("{\"$id\": \"1\",\"data\": [{\"$id\": \"2\",\"access_token\": \"" + tokenResult + "\"} ] }"); mockWebClient.Setup(x => x.Headers).Returns(new WebHeaderCollection()); var apiCall = new TokenApi(Settings.Default.BaseUrl, 1, Settings.Default.ApiDeveloperId, Settings.Default.ApiKey, mockWebClient.Object); //token = apiCall.GetToken("*****@*****.**", "P@ssword123"); token = apiCall.GetToken("*****@*****.**", "Password@123"); Assert.AreEqual(token, tokenResult); return mockWebClient; }
public string GetToken() { string token = TokenApi.GetToken("wxe7322013e6e964b8", "9e4e5617c1b543e3164befd1952716b0"); return((new JavaScriptSerializer()).Deserialize <Token>(token).access_token); }
public override AbstractResponse OnEvent_ClickRequest(ClickEventRequest clickEventRequest) { string userOpenId = clickEventRequest.FromUserName; WeiXinHelper.UpdateRencentOpenID(userOpenId); try { Hidistro.Entities.VShop.MenuInfo menu = VShopHelper.GetMenu(Convert.ToInt32(clickEventRequest.EventKey)); if (menu == null) { return(null); } if (menu.BindType == BindType.StoreCard) { try { SiteSettings siteSettings = SettingsManager.GetMasterSettings(false); string access_token = TokenApi.GetToken(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret); access_token = JsonConvert.DeserializeObject <Token>(access_token).access_token; MemberInfo member = MemberProcessor.GetOpenIdMember(userOpenId, "wx"); if (member == null) { this.CreatMember(userOpenId, 0, access_token); member = MemberProcessor.GetOpenIdMember(userOpenId, "wx"); } string userHead = member.UserHead; string storeLogo = siteSettings.DistributorLogoPic; string webStart = Globals.GetWebUrlStart(); string imageUrl = "/Storage/master/DistributorCards/MemberCard" + member.UserId + ".jpg"; string mediaid = string.Empty; int ReferralId = 0; string storeName = siteSettings.SiteName; string NotSuccessMsg = string.Empty; DistributorsInfo distributorInfo = DistributorsBrower.GetDistributorInfo(member.UserId); if (distributorInfo != null) { ReferralId = member.UserId; if (siteSettings.IsShowDistributorSelfStoreName) { storeName = distributorInfo.StoreName; storeLogo = distributorInfo.Logo; } imageUrl = "/Storage/master/DistributorCards/StoreCard" + ReferralId + ".jpg"; } else if (!siteSettings.IsShowSiteStoreCard) { string str = "您还不是分销商,不能为您生成推广图片,立即<a href='" + webStart + "/Vshop/DistributorCenter.aspx'>申请分销商</a>"; if (!string.IsNullOrEmpty(siteSettings.ToRegistDistributorTips)) { str = Regex.Replace(siteSettings.ToRegistDistributorTips, "{{申请分销商}}", "<a href='" + webStart + "/Vshop/DistributorCenter.aspx'>申请分销商</a>"); } return(new TextResponse { CreateTime = DateTime.Now, ToUserName = userOpenId, FromUserName = clickEventRequest.ToUserName, Content = str }); } string postData = string.Empty; string creatingStoreCardTips = siteSettings.CreatingStoreCardTips; if (!string.IsNullOrEmpty(creatingStoreCardTips)) { postData = "{\"touser\":\"" + userOpenId + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"" + Globals.String2Json(creatingStoreCardTips) + "\"}}"; NewsApi.KFSend(access_token, postData); } string filePath = HttpContext.Current.Request.MapPath(imageUrl); Task.Factory.StartNew(delegate { try { File.Exists(filePath); string str = File.ReadAllText(HttpRuntime.AppDomainAppPath + "/Storage/Utility/StoreCardSet.js"); string qRImageUrlByTicket = webStart + "/Follow.aspx?ReferralId=" + ReferralId.ToString(); ScanInfos info = ScanHelp.GetScanInfosByUserId(ReferralId, 0, "WX"); if (info == null) { ScanHelp.CreatNewScan(ReferralId, "WX", 0); info = ScanHelp.GetScanInfosByUserId(ReferralId, 0, "WX"); } if ((info != null) && !string.IsNullOrEmpty(info.CodeUrl)) { qRImageUrlByTicket = BarCodeApi.GetQRImageUrlByTicket(info.CodeUrl); } else { string token = TokenApi.GetToken_Message(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret); if (TokenApi.CheckIsRightToken(token)) { string str4 = BarCodeApi.CreateTicket(token, info.Sceneid, "QR_LIMIT_SCENE", "2592000"); if (!string.IsNullOrEmpty(str4)) { qRImageUrlByTicket = BarCodeApi.GetQRImageUrlByTicket(str4); info.CodeUrl = str4; info.CreateTime = DateTime.Now; info.LastActiveTime = DateTime.Now; ScanHelp.updateScanInfosCodeUrl(info); } } } StoreCardCreater creater = new StoreCardCreater(str, userHead, storeLogo, qRImageUrlByTicket, member.UserName, storeName, ReferralId, member.UserId); if (creater.ReadJson() && creater.CreadCard(out NotSuccessMsg)) { if (ReferralId > 0) { DistributorsBrower.UpdateStoreCard(ReferralId, NotSuccessMsg); } string msg = NewsApi.GetMedia_IDByPath(access_token, webStart + imageUrl); mediaid = NewsApi.GetJsonValue(msg, "media_id"); } else { Globals.Debuglog(NotSuccessMsg, "_DebugCreateStoreCardlog.txt"); } postData = "{\"touser\":\"" + userOpenId + "\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"" + mediaid + "\"}}"; NewsApi.KFSend(access_token, postData); } catch (Exception exception) { postData = "{\"touser\":\"" + userOpenId + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"生成图片失败," + Globals.String2Json(exception.ToString()) + "\"}}"; NewsApi.KFSend(access_token, postData); } }); return(null); } catch (Exception exception) { return(new TextResponse { CreateTime = DateTime.Now, ToUserName = userOpenId, FromUserName = clickEventRequest.ToUserName, Content = "问题:" + exception.ToString() }); } } Hidistro.Entities.VShop.ReplyInfo reply = ReplyHelper.GetReply(menu.ReplyId); if (reply == null) { return(null); } if (reply.MessageType != Hidistro.Entities.VShop.MessageType.Image) { AbstractResponse keyResponse = this.GetKeyResponse(reply.Keys, clickEventRequest); if (keyResponse != null) { return(keyResponse); } } AbstractResponse response = this.GetResponse(reply, clickEventRequest.FromUserName); if (response == null) { this.GotoManyCustomerService(clickEventRequest); } response.ToUserName = clickEventRequest.FromUserName; response.FromUserName = clickEventRequest.ToUserName; return(response); } catch (Exception exception2) { return(new TextResponse { CreateTime = DateTime.Now, ToUserName = clickEventRequest.FromUserName, FromUserName = clickEventRequest.ToUserName, Content = "问题:" + exception2.ToString() }); } }
protected void Page_Load(object sender, System.EventArgs e) { if (!base.IsPostBack) { if (this.type == "getarticleinfo") { base.Response.ContentType = "application/json"; string s = "{\"type\":\"0\",\"tips\":\"操作失败\"}"; int num = Globals.RequestFormNum("articleid"); if (num > 0) { ArticleInfo articleInfo = ArticleHelper.GetArticleInfo(num); if (articleInfo != null) { System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); switch (articleInfo.ArticleType) { case ArticleType.News: s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)articleInfo.ArticleType, ",\"title\":\"", this.String2Json(articleInfo.Title), "\",\"date\":\"", this.String2Json(articleInfo.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(articleInfo.ImageUrl), "\",\"memo\":\"", this.String2Json(articleInfo.Memo), "\"}" }); goto IL_30E; case ArticleType.List: { System.Collections.Generic.IList <ArticleItemsInfo> itemsInfo = articleInfo.ItemsInfo; foreach (ArticleItemsInfo current in itemsInfo) { stringBuilder.Append(string.Concat(new string[] { "{\"title\":\"", this.String2Json(current.Title), "\",\"imgurl\":\"", this.String2Json(current.ImageUrl), "\"}," })); } s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)articleInfo.ArticleType, ",\"title\":\"", this.String2Json(articleInfo.Title), "\",\"date\":\"", this.String2Json(articleInfo.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(articleInfo.ImageUrl), "\",\"items\":[", stringBuilder.ToString().Trim(new char[] { ',' }), "]}" }); goto IL_30E; } } s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)articleInfo.ArticleType, ",\"title\":\"", this.String2Json(articleInfo.Title), "\",\"date\":\"", this.String2Json(articleInfo.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(articleInfo.ImageUrl), "\",\"memo\":\"", this.String2Json(articleInfo.Content), "\"}" }); } } IL_30E: base.Response.Write(s); base.Response.End(); return; } if (this.type == "postdata") { base.Response.ContentType = "application/json"; string s2 = "{\"type\":\"1\",\"tips\":\"操作成功\"}"; this.sendID = Globals.RequestFormNum("sendid"); int num2 = Globals.RequestFormNum("sendtype"); int num3 = Globals.RequestFormNum("msgtype"); int articleid = Globals.RequestFormNum("articleid"); string title = Globals.RequestFormStr("title"); string content = Globals.RequestFormStr("content"); int isoldarticle = Globals.RequestFormNum("isoldarticle"); string text = this.SavePostData(num3, articleid, title, content, isoldarticle, this.sendID, true); if (string.IsNullOrEmpty(text)) { MessageType messageType = (MessageType)num3; string text2 = string.Empty; SiteSettings masterSettings = SettingsManager.GetMasterSettings(false); string text3 = TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret); text3 = JsonConvert.DeserializeObject <Token>(text3).access_token; switch (messageType) { case MessageType.News: case MessageType.List: { bool flag = true; ArticleInfo articleInfo2 = ArticleHelper.GetArticleInfo(articleid); if (articleInfo2.MediaId.Length < 1) { string text4 = NewsApi.GetMedia_IDByPath(text3, articleInfo2.ImageUrl); text4 = NewsApi.GetJsonValue(text4, "media_id"); if (!string.IsNullOrEmpty(text4)) { ArticleHelper.UpdateMedia_Id(0, articleInfo2.ArticleId, text4); } else { flag = false; s2 = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(NewsApi.GetJsonValue(text4, "errcode")) + "111111\"}"; } } if (messageType == MessageType.List) { foreach (ArticleItemsInfo current2 in articleInfo2.ItemsInfo) { if (current2.MediaId == null || current2.MediaId.Length < 1) { string media_IDByPath = NewsApi.GetMedia_IDByPath(text3, current2.ImageUrl); string jsonValue = NewsApi.GetJsonValue(media_IDByPath, "media_id"); if (jsonValue.Length == 0) { this.errcode = NewsApi.GetJsonValue(media_IDByPath, "errcode"); flag = false; s2 = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(this.errcode) + "\"}"; break; } ArticleHelper.UpdateMedia_Id(1, current2.Id, jsonValue); } } } if (!flag) { goto IL_91D; } string articlesJsonStr = this.GetArticlesJsonStr(articleInfo2); string msg = NewsApi.UploadNews(text3, articlesJsonStr); this.sendID = Globals.ToNum(this.SavePostData(num3, articleid, title, content, isoldarticle, this.sendID, false)); string jsonValue2 = NewsApi.GetJsonValue(msg, "media_id"); if (jsonValue2.Length <= 0) { this.errcode = NewsApi.GetJsonValue(msg, "errcode"); s2 = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(this.errcode) + "!\"}"; goto IL_91D; } if (num2 != 1) { System.Data.DataTable rencentOpenID = WeiXinHelper.GetRencentOpenID(100); int count = rencentOpenID.Rows.Count; int num4 = 0; string returnjsondata = string.Empty; for (int i = 0; i < rencentOpenID.Rows.Count; i++) { string msg2 = NewsApi.KFSend(text3, this.GetKFSendImageJson(rencentOpenID.Rows[i][0].ToString(), articleInfo2)); this.errcode = NewsApi.GetJsonValue(msg2, "errcode"); if (this.errcode == "0") { num4++; } else { returnjsondata = NewsApi.GetErrorCodeMsg(this.errcode); } } int sendstate = (num4 > 0) ? 1 : 2; WeiXinHelper.UpdateMsgId(this.sendID, "", sendstate, num4, count, returnjsondata); goto IL_91D; } text2 = NewsApi.SendAll(text3, NewsApi.CreateImageNewsJson(jsonValue2)); if (string.IsNullOrWhiteSpace(text2)) { s2 = "{\"type\":\"2\",\"tips\":\"type参数错误\"}"; goto IL_91D; } string jsonValue3 = NewsApi.GetJsonValue(text2, "msg_id"); if (!string.IsNullOrEmpty(jsonValue3)) { WeiXinHelper.UpdateMsgId(this.sendID, jsonValue3, 0, 0, 0, ""); goto IL_91D; } this.errcode = NewsApi.GetJsonValue(text2, "errcode"); string errorCodeMsg = NewsApi.GetErrorCodeMsg(this.errcode); WeiXinHelper.UpdateMsgId(this.sendID, jsonValue3, 2, 0, 0, errorCodeMsg); s2 = "{\"type\":\"2\",\"tips\":\"" + errorCodeMsg + "!!\"}"; goto IL_91D; } } this.sendID = Globals.ToNum(this.SavePostData(num3, articleid, title, content, isoldarticle, this.sendID, false)); if (num2 == 1) { text2 = NewsApi.SendAll(text3, this.CreateTxtNewsJson(content)); if (!string.IsNullOrWhiteSpace(text2)) { string jsonValue4 = NewsApi.GetJsonValue(text2, "msg_id"); if (jsonValue4.Length == 0) { this.errcode = NewsApi.GetJsonValue(text2, "errcode"); string errorCodeMsg2 = NewsApi.GetErrorCodeMsg(this.errcode); WeiXinHelper.UpdateMsgId(this.sendID, jsonValue4, 2, 0, 0, errorCodeMsg2); s2 = "{\"type\":\"2\",\"tips\":\"" + errorCodeMsg2 + "\"}"; } else { WeiXinHelper.UpdateMsgId(this.sendID, jsonValue4, 0, 0, 0, ""); } } else { s2 = "{\"type\":\"2\",\"tips\":\"type参数错误\"}"; } } else { System.Data.DataTable rencentOpenID2 = WeiXinHelper.GetRencentOpenID(100); int count2 = rencentOpenID2.Rows.Count; int num5 = 0; string returnjsondata2 = string.Empty; for (int j = 0; j < rencentOpenID2.Rows.Count; j++) { string msg3 = NewsApi.KFSend(text3, NewsApi.CreateKFTxtNewsJson(rencentOpenID2.Rows[j][0].ToString(), this.String2Json(this.FormatSendContent(content)))); this.errcode = NewsApi.GetJsonValue(msg3, "errcode"); if (this.errcode == "0") { num5++; } else { returnjsondata2 = NewsApi.GetErrorCodeMsg(this.errcode); } } int sendstate2 = (num5 > 0) ? 1 : 2; WeiXinHelper.UpdateMsgId(this.sendID, "", sendstate2, num5, count2, returnjsondata2); if (num5 == 0) { s2 = "{\"type\":\"0\",\"tips\":\"发送失败\"}"; } } } else { s2 = "{\"type\":\"0\",\"tips\":\"" + text + "\"}"; } IL_91D: base.Response.Write(s2); base.Response.End(); return; } if (this.sendID > 0) { this.hdfSendID.Value = this.sendID.ToString(); SendAllInfo sendAllInfo = WeiXinHelper.GetSendAllInfo(this.sendID); if (sendAllInfo != null) { MessageType messageType2 = sendAllInfo.MessageType; this.hdfMessageType.Value = ((int)sendAllInfo.MessageType).ToString(); int articleID = sendAllInfo.ArticleID; this.hdfArticleID.Value = articleID.ToString(); this.txtTitle.Text = sendAllInfo.Title; switch (messageType2) { case MessageType.Text: this.fkContent.Text = sendAllInfo.Content; break; case MessageType.News: if (articleID <= 0) { this.hdfIsOldArticle.Value = "1"; NewsReplyInfo newsReplyInfo = ReplyHelper.GetReply(this.sendID) as NewsReplyInfo; if (newsReplyInfo != null && newsReplyInfo.NewsMsg != null && newsReplyInfo.NewsMsg.Count != 0) { this.htmlInfo = string.Concat(new string[] { "<div class=\"mate-inner\"><h3 id=\"singelTitle\">", newsReplyInfo.NewsMsg[0].Title, "</h3><span>", newsReplyInfo.LastEditDate.ToString("M月d日"), "</span><div class=\"mate-img\"><img id=\"img1\" src=\"", newsReplyInfo.NewsMsg[0].PicUrl, "\" class=\"img-responsive\"></div><div class=\"mate-info\" id=\"Lbmsgdesc\">", newsReplyInfo.NewsMsg[0].Description, "</div><div class=\"red-all clearfix\"><strong class=\"fl\">查看全文</strong><em class=\"fr\">></em></div></div>" }); } } break; case MessageType.List: if (articleID <= 0) { this.hdfIsOldArticle.Value = "1"; NewsReplyInfo newsReplyInfo2 = ReplyHelper.GetReply(this.sendID) as NewsReplyInfo; if (newsReplyInfo2 != null) { System.Text.StringBuilder stringBuilder2 = new System.Text.StringBuilder(); if (newsReplyInfo2.NewsMsg != null && newsReplyInfo2.NewsMsg.Count > 0) { int num6 = 0; foreach (NewsMsgInfo current3 in newsReplyInfo2.NewsMsg) { num6++; if (num6 == 1) { stringBuilder2.Append(string.Concat(new string[] { "<div class=\"mate-inner top\"> <div class=\"mate-img\" > <img id=\"img1\" src=\"", current3.PicUrl, "\" class=\"img-responsive\"> <div class=\"title\" id=\"title1\">", current3.Title, "</div> </div> </div>" })); } else { stringBuilder2.Append(string.Concat(new string[] { " <div class=\"mate-inner\"> <div class=\"child-mate\"> <div class=\"child-mate-title clearfix\"> <div class=\"title\">", current3.Title, "</div> <div class=\"img\"> <img src=\"", current3.PicUrl, "\" class=\"img-responsive\"> </div> </div> </div> </div>" })); } } this.htmlInfo = stringBuilder2.ToString(); } } } break; } } else { base.Response.Redirect("sendalllist.aspx"); base.Response.End(); } } else if (this.LocalArticleID > 0) { ArticleInfo articleInfo3 = ArticleHelper.GetArticleInfo(this.LocalArticleID); if (articleInfo3 != null) { this.hdfArticleID.Value = this.LocalArticleID.ToString(); this.hdfMessageType.Value = ((int)articleInfo3.ArticleType).ToString(); } } if (string.IsNullOrEmpty(this.htmlInfo)) { this.htmlInfo = "<div class=\"exit-shop-info\">内容区</div>"; } this.litInfo.Text = this.htmlInfo; } }
public string GetToken() { string token = TokenApi.GetToken("wxe7322013e6e964b8", "9e4e5617c1b543e3164befd1952716b0"); return(JsonConvert.DeserializeObject <Token>(token).access_token); }
protected void Page_Load(object sender, EventArgs e) { string str2; if (base.IsPostBack) { return; } if (!(this.type == "getarticleinfo")) { if (!(this.type == "postdata")) { if (this.sendID > 0) { this.hdfSendID.Value = this.sendID.ToString(); SendAllInfo sendAllInfo = WeiXinHelper.GetSendAllInfo(this.sendID); if (sendAllInfo != null) { MessageType messageType = sendAllInfo.MessageType; this.hdfMessageType.Value = ((int)sendAllInfo.MessageType).ToString(); int articleID = sendAllInfo.ArticleID; this.hdfArticleID.Value = articleID.ToString(); this.txtTitle.Text = sendAllInfo.Title; switch (messageType) { case MessageType.Text: this.fkContent.Text = sendAllInfo.Content; break; case MessageType.News: if (articleID <= 0) { this.hdfIsOldArticle.Value = "1"; NewsReplyInfo reply = ReplyHelper.GetReply(this.sendID) as NewsReplyInfo; if (((reply != null) && (reply.NewsMsg != null)) && (reply.NewsMsg.Count != 0)) { this.htmlInfo = "<div class=\"mate-inner\"><h3 id=\"singelTitle\">" + reply.NewsMsg[0].Title + "</h3><span>" + reply.LastEditDate.ToString("M月d日") + "</span><div class=\"mate-img\"><img id=\"img1\" src=\"" + reply.NewsMsg[0].PicUrl + "\" class=\"img-responsive\"></div><div class=\"mate-info\" id=\"Lbmsgdesc\">" + reply.NewsMsg[0].Description + "</div><div class=\"red-all clearfix\"><strong class=\"fl\">查看全文</strong><em class=\"fr\">></em></div></div>"; } } break; case MessageType.List: if (articleID <= 0) { this.hdfIsOldArticle.Value = "1"; NewsReplyInfo info6 = ReplyHelper.GetReply(this.sendID) as NewsReplyInfo; if (info6 != null) { StringBuilder builder2 = new StringBuilder(); if ((info6.NewsMsg != null) && (info6.NewsMsg.Count > 0)) { int num15 = 0; foreach (NewsMsgInfo info7 in info6.NewsMsg) { num15++; if (num15 == 1) { builder2.Append("<div class=\"mate-inner top\"> <div class=\"mate-img\" > <img id=\"img1\" src=\"" + info7.PicUrl + "\" class=\"img-responsive\"> <div class=\"title\" id=\"title1\">" + info7.Title + "</div> </div> </div>"); } else { builder2.Append(" <div class=\"mate-inner\"> <div class=\"child-mate\"> <div class=\"child-mate-title clearfix\"> <div class=\"title\">" + info7.Title + "</div> <div class=\"img\"> <img src=\"" + info7.PicUrl + "\" class=\"img-responsive\"> </div> </div> </div> </div>"); } } this.htmlInfo = builder2.ToString(); } } } break; } } else { base.Response.Redirect("sendalllist.aspx"); base.Response.End(); } } else if (this.LocalArticleID > 0) { ArticleInfo articleInfo = ArticleHelper.GetArticleInfo(this.LocalArticleID); if (articleInfo != null) { this.hdfArticleID.Value = this.LocalArticleID.ToString(); this.hdfMessageType.Value = ((int)articleInfo.ArticleType).ToString(); } } if (string.IsNullOrEmpty(this.htmlInfo)) { this.htmlInfo = "<div class=\"exit-shop-info\">内容区</div>"; } this.litInfo.Text = this.htmlInfo; return; } base.Response.ContentType = "application/json"; str2 = "{\"type\":\"1\",\"tips\":\"操作成功\"}"; this.sendID = Globals.RequestFormNum("sendid"); int num2 = Globals.RequestFormNum("sendtype"); int msgType = Globals.RequestFormNum("msgtype"); int num4 = Globals.RequestFormNum("articleid"); string title = Globals.RequestFormStr("title"); string content = Globals.RequestFormStr("content"); int isoldarticle = Globals.RequestFormNum("isoldarticle"); string str5 = this.SavePostData(msgType, num4, title, content, isoldarticle, this.sendID, true); if (!string.IsNullOrEmpty(str5)) { str2 = "{\"type\":\"0\",\"tips\":\"" + str5 + "\"}"; } else { MessageType type = (MessageType)msgType; string msg = string.Empty; SiteSettings masterSettings = SettingsManager.GetMasterSettings(false); string str7 = JsonConvert.DeserializeObject <Token>(TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret)).access_token; switch (type) { case MessageType.News: case MessageType.List: { bool flag = true; ArticleInfo info3 = ArticleHelper.GetArticleInfo(num4); if (info3.MediaId.Length < 1) { string jsonValue = NewsApi.GetJsonValue(NewsApi.GetMedia_IDByPath(str7, info3.ImageUrl), "media_id"); if (string.IsNullOrEmpty(jsonValue)) { flag = false; str2 = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(NewsApi.GetJsonValue(jsonValue, "errcode")) + "111111\"}"; } else { ArticleHelper.UpdateMedia_Id(0, info3.ArticleId, jsonValue); } } if (type == MessageType.List) { foreach (ArticleItemsInfo info4 in info3.ItemsInfo) { if ((info4.MediaId == null) || (info4.MediaId.Length < 1)) { string str9 = NewsApi.GetMedia_IDByPath(str7, info4.ImageUrl); string mediaid = NewsApi.GetJsonValue(str9, "media_id"); if (mediaid.Length == 0) { this.errcode = NewsApi.GetJsonValue(str9, "errcode"); str9 = ""; flag = false; str2 = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(this.errcode) + "\"}"; break; } ArticleHelper.UpdateMedia_Id(1, info4.Id, mediaid); } } } if (flag) { string articlesJsonStr = this.GetArticlesJsonStr(info3); string str12 = NewsApi.UploadNews(str7, articlesJsonStr); this.sendID = Globals.ToNum(this.SavePostData(msgType, num4, title, content, isoldarticle, this.sendID, false)); string str13 = NewsApi.GetJsonValue(str12, "media_id"); if (str13.Length > 0) { if (num2 == 1) { msg = NewsApi.SendAll(str7, NewsApi.CreateImageNewsJson(str13)); if (!string.IsNullOrWhiteSpace(msg)) { string str14 = NewsApi.GetJsonValue(msg, "msg_id"); if (!string.IsNullOrEmpty(str14)) { WeiXinHelper.UpdateMsgId(this.sendID, str14, 0, 0, 0, ""); } else { this.errcode = NewsApi.GetJsonValue(msg, "errcode"); string errorCodeMsg = NewsApi.GetErrorCodeMsg(this.errcode); WeiXinHelper.UpdateMsgId(this.sendID, str14, 2, 0, 0, errorCodeMsg); str2 = "{\"type\":\"2\",\"tips\":\"" + errorCodeMsg + "!!\"}"; } } else { str2 = "{\"type\":\"2\",\"tips\":\"type参数错误\"}"; } } else { DataTable rencentOpenID = WeiXinHelper.GetRencentOpenID(100); int count = rencentOpenID.Rows.Count; int sendcount = 0; string returnjsondata = string.Empty; for (int i = 0; i < rencentOpenID.Rows.Count; i++) { string str17 = NewsApi.KFSend(str7, this.GetKFSendImageJson(rencentOpenID.Rows[i][0].ToString(), info3)); this.errcode = NewsApi.GetJsonValue(str17, "errcode"); if (this.errcode == "0") { sendcount++; } else { returnjsondata = NewsApi.GetErrorCodeMsg(this.errcode); } } int sendstate = (sendcount > 0) ? 1 : 2; WeiXinHelper.UpdateMsgId(this.sendID, "", sendstate, sendcount, count, returnjsondata); } } else { this.errcode = NewsApi.GetJsonValue(str12, "errcode"); str2 = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(this.errcode) + "!\"}"; } } goto Label_091D; } } this.sendID = Globals.ToNum(this.SavePostData(msgType, num4, title, content, isoldarticle, this.sendID, false)); if (num2 == 1) { msg = NewsApi.SendAll(str7, this.CreateTxtNewsJson(content)); if (!string.IsNullOrWhiteSpace(msg)) { string msgid = NewsApi.GetJsonValue(msg, "msg_id"); if (msgid.Length == 0) { this.errcode = NewsApi.GetJsonValue(msg, "errcode"); string str19 = NewsApi.GetErrorCodeMsg(this.errcode); WeiXinHelper.UpdateMsgId(this.sendID, msgid, 2, 0, 0, str19); str2 = "{\"type\":\"2\",\"tips\":\"" + str19 + "\"}"; } else { WeiXinHelper.UpdateMsgId(this.sendID, msgid, 0, 0, 0, ""); } } else { str2 = "{\"type\":\"2\",\"tips\":\"type参数错误\"}"; } } else { DataTable table2 = WeiXinHelper.GetRencentOpenID(100); int totalcount = table2.Rows.Count; int num11 = 0; string str20 = string.Empty; for (int j = 0; j < table2.Rows.Count; j++) { string str21 = NewsApi.KFSend(str7, NewsApi.CreateKFTxtNewsJson(table2.Rows[j][0].ToString(), this.String2Json(this.FormatSendContent(content)))); this.errcode = NewsApi.GetJsonValue(str21, "errcode"); if (this.errcode == "0") { num11++; } else { str20 = NewsApi.GetErrorCodeMsg(this.errcode); } } int num13 = (num11 > 0) ? 1 : 2; WeiXinHelper.UpdateMsgId(this.sendID, "", num13, num11, totalcount, str20); if (num11 == 0) { str2 = "{\"type\":\"0\",\"tips\":\"发送失败\"}"; } } } goto Label_091D; } base.Response.ContentType = "application/json"; string s = "{\"type\":\"0\",\"tips\":\"操作失败\"}"; int articleid = Globals.RequestFormNum("articleid"); if (articleid > 0) { ArticleInfo info = ArticleHelper.GetArticleInfo(articleid); if (info != null) { StringBuilder builder = new StringBuilder(); switch (info.ArticleType) { case ArticleType.News: s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)info.ArticleType, ",\"title\":\"", this.String2Json(info.Title), "\",\"date\":\"", this.String2Json(info.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(info.ImageUrl), "\",\"memo\":\"", this.String2Json(info.Memo), "\"}" }); goto Label_030E; case ArticleType.List: foreach (ArticleItemsInfo info2 in info.ItemsInfo) { builder.Append("{\"title\":\"" + this.String2Json(info2.Title) + "\",\"imgurl\":\"" + this.String2Json(info2.ImageUrl) + "\"},"); } s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)info.ArticleType, ",\"title\":\"", this.String2Json(info.Title), "\",\"date\":\"", this.String2Json(info.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(info.ImageUrl), "\",\"items\":[", builder.ToString().Trim(new char[] { ',' }), "]}" }); goto Label_030E; } s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)info.ArticleType, ",\"title\":\"", this.String2Json(info.Title), "\",\"date\":\"", this.String2Json(info.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(info.ImageUrl), "\",\"memo\":\"", this.String2Json(info.Content), "\"}" }); } } Label_030E: base.Response.Write(s); base.Response.End(); return; Label_091D: base.Response.Write(str2); base.Response.End(); }
private void btnSubmit_Click(object sender, System.EventArgs e) { System.Collections.Generic.IList <MenuInfo> initMenus = VShopHelper.GetInitMenus(ClientType.VShop); Ecdev.Weixin.MP.Domain.Menu.Menu menu = new Ecdev.Weixin.MP.Domain.Menu.Menu(); foreach (MenuInfo current in initMenus) { if (current.Chilren == null || current.Chilren.Count == 0) { menu.menu.button.Add(this.BuildMenu(current)); } else { SubMenu subMenu = new SubMenu { name = current.Name }; foreach (MenuInfo current2 in current.Chilren) { subMenu.sub_button.Add(this.BuildMenu(current2)); } menu.menu.button.Add(subMenu); } } string json = JsonConvert.SerializeObject(menu.menu); SiteSettings masterSettings = SettingsManager.GetMasterSettings(false); if (string.IsNullOrEmpty(masterSettings.WeixinAppId) || string.IsNullOrEmpty(masterSettings.WeixinAppSecret)) { base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='VServerConfig.aspx'</script>"); return; } string text = TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret); try { text = (JsonConvert.DeserializeObject(text, typeof(Token)) as Token).access_token; string text2 = MenuApi.CreateMenus(text, json); if (text2.Contains("ok")) { this.ShowMsg("成功的把自定义菜单保存到了微信", true); } else { this.ShowMsg("操作失败!服务号配置信息错误或没有微信自定义菜单权限,请检查配置信息以及菜单的长度。", false); } } catch (System.Exception ex) { base.Response.Write(string.Concat(new string[] { ex.Message, "---", text, "---", masterSettings.WeixinAppId, "---", masterSettings.WeixinAppSecret })); base.Response.End(); } }