Beispiel #1
0
        //
        // GET: /Test/
        public ActionResult Index()
        {
            MenuInfo menu  = new MenuInfo("开始训练", MenuInfo.ButtonType.view, "http://wx.zzd123.com/wechat/Calendar");
            MenuInfo menu2 = new MenuInfo("免费体验", new MenuInfo[] {
                new MenuInfo("免费行为测评", MenuInfo.ButtonType.view, "http://wx.zzd123.com/Free/FreeScale"),
                new MenuInfo("免费心理服务", MenuInfo.ButtonType.view, "http://wx.zzd123.com/Free/FreeHeartList")
            });
            //  MenuInfo menu2 = new MenuInfo("行为测评", MenuInfo.ButtonType.view, "http://www.sina.com");
            //MenuInfo relatedInfo = new MenuInfo("相关链接", new MenuInfo[] {
            //    new MenuInfo("公司介绍", MenuInfo.ButtonType.click, "Event_Company"),
            //    new MenuInfo("官方网站", MenuInfo.ButtonType.view, "http://www.iqidi.com"),
            //    new MenuInfo("提点建议", MenuInfo.ButtonType.click, "Event_Suggestion"),
            //    new MenuInfo("联系客服", MenuInfo.ButtonType.click, "Event_Contact"),
            //    new MenuInfo("发邮件", MenuInfo.ButtonType.view, "http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=S31yfX15fn8LOjplKCQm")
            //});

            MenuJson menujson = new MenuJson();

            menujson.button.AddRange(new MenuInfo[] { menu, menu2 });

            string token = AccessTokenService.GetAccessToken();

            string postData = JsonConvert.SerializeObject(menujson);

            ViewBag.x = WechatService.wechatApi("CreateMenu", token, postData);


            return(View());
        }
Beispiel #2
0
        public ActionResult GetMaterialList()
        {
            MaterialListPost postobj = new MaterialListPost();

            postobj.count  = 20;
            postobj.type   = "image";
            postobj.offset = 0;
            string token       = AccessTokenService.GetAccessToken();
            string postJsonStr = JsonConvert.SerializeObject(postobj);
            string result      = WechatMaterialServices.GetMaterialList(token, postJsonStr);

            WechatResult wechatResult = JsonConvert.DeserializeObject <WechatResult>(result);

            if (wechatResult.errcode != 0)
            {
                ViewBag.msg     = "获取素材列表失败!返回错误代码如下:";
                ViewBag.content = result;
            }
            else
            {
                MaterialList materialList = JsonConvert.DeserializeObject <MaterialList>(result);
                ViewData["materialList"] = materialList.item;

                ViewBag.msg = "success";
            }


            return(View());
        }
Beispiel #3
0
        public ActionResult GetMenu()
        {
            string token  = AccessTokenService.GetAccessToken();
            string result = WechatMenuServices.GetMenu(token);

            ViewBag.result = result;
            return(View());
        }
Beispiel #4
0
        public void GetAccessToken()
        {
            var iAccessToken = DependencyManager.Resolve <IAccessTokenRepository>();
            var token        = iAccessToken.GetAccessToken(1);

            AccessTokenService accessTokenService = new AccessTokenService();
            string             errorMessage;
            var result = accessTokenService.GetAccessToken(1, out errorMessage);

            Assert.IsTrue(result != null && !result.IsExpired());
        }
Beispiel #5
0
        //public ActionResult demo()
        //{
        //    string str = @"开始时间:2016-1-1" + "\r\n"
        //                                                 + "结束时间:2017-1-1" + "\r\n"
        //                                                + "沙尘天气等级:2" + "\r\n"
        //                                                + "PM10日均浓度最大值:2ug/m3" + "\r\n"
        //                                                 + "影响范围:济南,青岛";

        //    string oldpath = @"/Resource/Image/78041949.png";
        //    string avatarpath=@"/Resource/Image/avatar.png";
        //  //  string newpath = @"/Resource/Image/"+CommonTools.getRandomNumber(10000,99999999)+".png";
        //    string imagepath = ImageTools.composeImage(oldpath, avatarpath, @"/Resource/Image/" + CommonTools.getRandomNumber(10000, 99999999) + ".png");
        //    string textimagepath = ImageTools.composeText(oldpath, "我是贺苏\r\n邀请你来参加第二节", @"/Resource/Image/" + CommonTools.getRandomNumber(10000, 99999999) + ".png");
        //    string texttoimagepath = ImageTools.SaveTextToImage(str);
        //    ViewBag.imagepath = imagepath;
        //    ViewBag.textimagepath = textimagepath;
        //    ViewBag.texttoimagepath = texttoimagepath;
        //    return View();
        //}
        public ActionResult Index()
        {
            string       access_token = AccessTokenService.GetAccessToken();
            WechatConfig wechatconfig = AccessTokenService.GetWechatConfig();
            string       xml          = XmlSerializerHelper.ToXml(wechatconfig);


            ViewBag.Message  = access_token;
            ViewBag.Message2 = xml;

            return(View());
        }
        public override async Task <AuthenticationState> GetAuthenticationStateAsync()
        {
            var tokenResult = await _accessTokenService.GetAccessToken();

            if (tokenResult != null)
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", tokenResult.Value);

                return(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity(ParseClaimsFromJwt(tokenResult.Value), "jwt"))));
            }

            return(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));
        }
Beispiel #7
0
        public ActionResult SendTempletMessage()
        {
            WechatTemplateMessage msgData = new WechatTemplateMessage
            {
                touser      = "******",
                template_id = "S0jkUpR2R7C6PIpnJHRD1GxIad27dln4vEOtD7uRl4A",
                url         = "http://www.baidu.com",
                data        = new
                {
                    first = new
                    {
                        value = "宝贝,你好,训练时间到了",
                        color = "#173177"
                    },
                    keyword1 = new
                    {
                        value = "踢皮球运动",
                        color = "#173177"
                    },
                    keyword2 = new
                    {
                        value = "30分钟",
                        color = "#173177"
                    },
                    remark = new
                    {
                        value = "感谢您的参与。"
                    }
                }
            };

            string access_token = AccessTokenService.GetAccessToken();
            string postdata     = JsonConvert.SerializeObject(msgData);

            string result = WechatMessageServices.SendTempletMessge(access_token, postdata);

            WechatResult wechatResult = JsonConvert.DeserializeObject <WechatResult>(result);

            if (wechatResult.errcode == 0)
            {
                ViewBag.msg    = "模板消息发送成功!操作代码如下:";
                ViewBag.result = result;
            }
            else
            {
                ViewBag.msg    = "模板消息发送失败!错误代码如下:";
                ViewBag.result = result;
            }

            return(View());
        }
Beispiel #8
0
        public ActionResult GetUserInfoByopenid(string openid)
        {
            if (string.IsNullOrEmpty(openid))
            {
                openid = "oChqYt13RL8dBi0zKHo0kao-aSHo";
            }
            string         userAgent    = Request.UserAgent;
            string         access_token = AccessTokenService.GetAccessToken();
            WechatUserInfo userinfo     = new WechatUserInfo();

            userinfo = WechatApi.GetUserInfo(access_token, userAgent, openid);

            return(View(userinfo));
        }
Beispiel #9
0
        public ActionResult UploadMaterial()
        {
            string type = Request.Form["MaterialType"];

            var    file  = Request.Files["MaterialFile"];
            string token = AccessTokenService.GetAccessToken();

            var    media_id = WechatMaterialServices.UploadForeverMedia(token, type, file.FileName, file.InputStream);
            string filename = file.FileName;

            ViewBag.filename = filename;
            ViewBag.type     = type;
            ViewBag.info     = media_id;
            return(View());
        }
Beispiel #10
0
        public ActionResult SendTempletMessage()
        {
            WechatTemplateMessage msgData = new WechatTemplateMessage
            {
                touser      = "******",
                template_id = "KqDQm6LejvmNDrTWIQuRYoflIpi7JKgvUNsQfqf8i70",
                url         = "http://www.baidu.com",
                data        = new
                {
                    welcome = new
                    {
                        value = "宝贝,你好,训练时间到了",
                        color = "#173177"
                    },
                    first = new
                    {
                        value = "踢皮球运动",
                        color = "#173177"
                    },
                    second = new
                    {
                        value = "30分钟",
                        color = "#173177"
                    }
                }
            };

            string access_token = AccessTokenService.GetAccessToken();
            string postdata     = JsonConvert.SerializeObject(msgData);

            string result = WechatMessageServices.SendTempletMessge(access_token, postdata);

            WechatResult wechatResult = JsonConvert.DeserializeObject <WechatResult>(result);

            if (wechatResult.errcode == 0)
            {
                ViewBag.msg    = "模板消息发送成功!操作代码如下:";
                ViewBag.result = result;
            }
            else
            {
                ViewBag.msg    = "模板消息发送失败!错误代码如下:";
                ViewBag.result = result;
            }

            return(View());
        }
Beispiel #11
0
        public ActionResult DeleteWechatMenu()
        {
            string token = AccessTokenService.GetAccessToken();
            string result = WechatMenuService.DeleteMenu(token);
            ViewBag.result = result;
            WechatResult wechatResult = JsonConvert.DeserializeObject<WechatResult>(result);
            if (wechatResult.errcode == 0)
            {
                ViewBag.msg = "删除成功!";
            }
            else
            {
                ViewBag.msg = "删除失败!";

            }
            return View();
        }
Beispiel #12
0
        public ActionResult GetWechatMenu()
        {
            string token = AccessTokenService.GetAccessToken();
            string menuStr = WechatMenuService.GetMenu(token);
            WechatResult wechatResult = JsonConvert.DeserializeObject<WechatResult>(menuStr);
            if (wechatResult.errcode != 0)
            {
                ViewBag.msg = "此公众号目前没有菜单!返回错误代码如下:";
            }
            else
            {
                ViewBag.msg = "成功获取到菜单内容!菜单代码如下:";
            }
            ViewBag.content = menuStr;

            return View();
        }
        public ActionResult CreateForeverQR()
        {
            WechatIDQRInfo IdQR = new WechatIDQRInfo();

            IdQR.action_name = "QR_SCENE";
            action_info action = new action_info();

            IdQR.action_info = action;
            scene scene = new scene();

            scene.scene_str = "stringqr";

            string postData = JsonConvert.SerializeObject(IdQR);
            string token    = AccessTokenService.GetAccessToken();
            string result   = WechatQRServices.CreateForeverQR(token, postData);

            ViewBag.result = result;
            return(View("Result"));
        }
Beispiel #14
0
        public ActionResult CreateMenuold()
        {
            MenuInfo menu  = new MenuInfo("开始训练", MenuInfo.ButtonType.view, "http://wx.zzd123.com/wechat/Calendar");
            MenuInfo menu2 = new MenuInfo("免费体验", new MenuInfo[] {
                new MenuInfo("免费行为测评", MenuInfo.ButtonType.view, "http://wx.zzd123.com/Free/FreeScale"),
                new MenuInfo("免费心理服务", MenuInfo.ButtonType.view, "http://wx.zzd123.com/Free/FreeHeartList")
            });
            MenuJson menujson = new MenuJson();

            menujson.button.AddRange(new MenuInfo[] { menu, menu2 });

            string token = AccessTokenService.GetAccessToken();

            string postData = JsonConvert.SerializeObject(menujson);

            ViewBag.x = WechatService.wechatApi("CreateMenu", token, postData);


            return(View());
        }
Beispiel #15
0
        public ActionResult CreateMenu()
        {
            string postData = Request.Form["content"].Replace("\r\n", "").Replace("\\", "");
            string token    = AccessTokenService.GetAccessToken();

            string       result       = WechatMenuServices.CreateMenu(token, postData);
            WechatResult wechatResult = JsonConvert.DeserializeObject <WechatResult>(result);

            if (wechatResult.errcode == 0)
            {
                ViewBag.msg    = "微信菜单创建成功!菜单代码如下:";
                ViewBag.result = postData;
            }
            else
            {
                ViewBag.msg    = "微信菜单创建失败!错误代码如下:";
                ViewBag.result = result;
            }

            return(View());
        }
Beispiel #16
0
 private static void RefreshAccessToken()
 {
     if (AccessTokenService.RefreshTokenExpired ||
         AccessTokenService.RequestedAccessToken == DateTime.MinValue ||
         string.IsNullOrEmpty(AccessTokenService.AccessToken))
     {
         var success = AccessTokenService.GetAccessToken("SDL_PLUGIN", "E9KWtWahXs4hvE9z");
         if (!success)
         {
             Logger.Error(PluginResources.TermSearchService_Error_in_requesting_access_token);
         }
     }
     else if (AccessTokenService.AccessTokenExpired && !AccessTokenService.AccessTokenExtended)
     {
         var success = AccessTokenService.ExtendAccessToken();
         if (!success)
         {
             Logger.Error(PluginResources.TermSearchService_Error_in_refreshing_access_token);
         }
     }
 }
Beispiel #17
0
 public ActionResult GetAccessToken()
 {
     return(Content(AccessTokenService.GetAccessToken()));
 }
        public ActionResult GetForeverMaterialList(int?page, string type = "image", int offset = 0, int count = 20)
        {
            string token = AccessTokenService.GetAccessToken();
            ForeverMaterialCount materialCount = WechatMaterialService.GetForeverMaterialCount(token);

            ViewBag.voice_count = materialCount.voice_count;
            ViewBag.video_count = materialCount.video_count;
            ViewBag.image_count = materialCount.image_count;
            ViewBag.news_count  = materialCount.news_count;

            MaterialListPost materialListPost = new MaterialListPost();

            materialListPost.type   = type;
            materialListPost.offset = offset;
            materialListPost.count  = count;
            string postdata = JsonConvert.SerializeObject(materialListPost);
            string result   = WechatMaterialService.GetMaterialList(token, postdata);

            page = page ?? 1;

            if (type == "news")
            {
                ForeverNewsMaterial foreverNewsMaterial = JsonConvert.DeserializeObject <ForeverNewsMaterial>(result);
                ViewData["NewsMaterialItems"] = foreverNewsMaterial.item;
                ViewBag.total_count           = foreverNewsMaterial.total_count;
                ViewBag.item_count            = foreverNewsMaterial.item_count;
                int  totalPage = ((foreverNewsMaterial.total_count + count - 1) / count);
                bool prepage   = false;
                bool nextpage  = false;
                if (page > 1)
                {
                    prepage = true;
                }
                if (totalPage > page)
                {
                    nextpage = true;
                }

                ViewBag.nextoffset = page * count;
                ViewBag.preoffset  = (page - 2) * count;
                ViewBag.count      = count;
                ViewBag.type       = type;
                ViewBag.page       = page;
                ViewBag.totalPage  = totalPage;
                ViewBag.prepage    = prepage;
                ViewBag.nextpage   = nextpage;
            }
            else
            {
                ForeverMaterial foreverMaterial = JsonConvert.DeserializeObject <ForeverMaterial>(result);
                ViewBag.total_count = foreverMaterial.total_count;
                ViewBag.item_count  = foreverMaterial.item_count;
                int  totalPage = ((foreverMaterial.total_count + count - 1) / count);
                bool prepage   = false;
                bool nextpage  = false;
                if (type == "image")
                {
                    nextpage = true;
                }
                if (page > 1)
                {
                    prepage = true;
                }
                if (totalPage > page)
                {
                    nextpage = true;
                }
                ViewBag.prepage           = prepage;
                ViewBag.nextpage          = nextpage;
                ViewBag.nextoffset        = page * count;
                ViewBag.preoffset         = (page - 2) * count;
                ViewBag.count             = count;
                ViewBag.type              = type;
                ViewBag.page              = page;
                ViewBag.totalPage         = totalPage;
                ViewData["MaterialItems"] = foreverMaterial.item;
            }


            return(View());
        }
        public ActionResult Daka(RenwuDaka daka)
        {
            Ren   ren   = unitOfWork.rensRepository.GetByID(daka.RenwuZhixingzhe);
            Renwu renwu = unitOfWork.renwusRepository.GetByID(daka.RenwuName);

            if (ModelState.IsValid)
            {
                unitOfWork.renwuDakasRepository.Insert(daka);
                unitOfWork.Save();

                WechatTemplateMessage msgData = new WechatTemplateMessage
                {
                    touser      = ren.RenOpenid,
                    template_id = "YfnxngfPAXv5hgSkDGKS-3bd5aScpZgwlRr1Jn85fWc",
                    url         = "http://peiban.zzd123.com/Wap/ArticleContent?id=" + daka.Id,
                    data        = new
                    {
                        first = new
                        {
                            value = "你好,完成作业通知。",
                            color = "#173177"
                        },
                        keyword1 = new
                        {
                            value = ren.RenNickName,
                            color = "#173177"
                        },
                        keyword2 = new
                        {
                            value = renwu.Title,
                            color = "#173177"
                        },
                        keyword3 = new
                        {
                            value = DateTime.Now.ToString("yyyy-MM-dd hh:mm"),
                            color = "#173177"
                        },
                        remark = new
                        {
                            value = "每一次陪伴都是人生的美好。"
                        }
                    }
                };

                string access_token = AccessTokenService.GetAccessToken();
                string postdata     = JsonConvert.SerializeObject(msgData);

                string result = WechatMessageServices.SendTempletMessge(access_token, postdata);

                WechatResult wechatResult = JsonConvert.DeserializeObject <WechatResult>(result);
                if (wechatResult.errcode == 0)
                {
                    ViewBag.msg    = "模板消息发送成功!操作代码如下:";
                    ViewBag.result = result;
                }
                else
                {
                    ViewBag.msg    = "模板消息发送失败!错误代码如下:";
                    ViewBag.result = result;
                }
                return(RedirectToAction("DakaList", "UHome"));
            }
            return(View(daka));
        }
Beispiel #20
0
        public void TestGetAccessToken()
        {
            AccessToken accessToken = accessTokenService.GetAccessToken();

            Console.WriteLine(accessToken);
        }