public ActionResult Index() { WechatConfig config = AccessTokenService.GetWechatConfig(); ViewData["config"] = config; return(View()); }
//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 ActionResult About() //{ // WechatTemplateMessage msgData = new WechatTemplateMessage // { // touser = "******", // template_id = "KqDQm6LejvmNDrTWIQuRYoflIpi7JKgvUNsQfqf8i70", // url = "http://www.baidu.com", // data = new // { // welcome = new // { // value = "训练提醒通知", // color = "#173177" // }, // first = new // { // value = "2015年6月7日", // color = "#173177" // }, // second = new // { // value = "踢皮球", // color = "#173177" // }, // } // }; // string access_token = AccessTokenService.GetAccessToken(); // string operate="SendTemplateMessage"; // string postdata = JsonConvert.SerializeObject(msgData); // string result=WechatService.wechatApi(operate,access_token,postdata); // ViewBag.Message = JsonConvert.SerializeObject(msgData); // ViewBag.result = result; // return View(); //} //public ActionResult SendMessage() //{ // 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 = "只有坚持不懈的努力,才能有进步,加油!", // color = "#173177" // }, // } // }; // string access_token = AccessTokenService.GetAccessToken(); // string postdata = JsonConvert.SerializeObject(msgData); // string result = WechatMessageServices.SendTempletMessge(access_token, postdata); // ViewBag.Message = JsonConvert.SerializeObject(msgData); // ViewBag.result = result; // return View(); //} //public ActionResult Contact() //{ // UserListItem[] u = new UserListItem[2]; // u[0] = new UserListItem { openid = "oChqYt13RL8dBi0zKHo0kao-aSHo", lang = "zh_CN" }; // u[1] = new UserListItem { openid = "oChqYt1b0t1U2_b_U9ag1JQyrebM", lang = "zh_CN" }; // UserList ulist = new UserList // { // user_list = u // }; // string postdata = JsonConvert.SerializeObject(ulist); // string access_token = AccessTokenService.GetAccessToken(); // string operate = "GetUserListInfo"; // string result = WechatService.wechatApi(operate, access_token, postdata); // ViewBag.Message = postdata; // ViewBag.result = result; // return View(); //} //public ActionResult Jstest() //{ // string userAgent=Request.UserAgent; // string access_token = AccessTokenService.GetAccessToken(); // string url=string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi",access_token); // // result = HttpWebResponseUtility.CreateGetHttpResponse(url,null,userAgent,null); // HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(url, null, userAgent, null); // Stream stream = response.GetResponseStream(); // StreamReader sr = new StreamReader(stream); // string result = sr.ReadToEnd(); // WechatJsTicket ticket = JsonConvert.DeserializeObject<WechatJsTicket>(result); // string jsapi_ticket = ticket.ticket; // string url2 = Request.Url.ToString(); // string string1 = "jsapi_ticket=" + jsapi_ticket + // "&noncestr=" + "zhaozheng" + // "×tamp=" + "1414587457" + // "&url=" + url2; // string x = SkyEncrypt.SHA1(string1); // ViewBag.signature = x; // return View(); //} //public ActionResult js() //{ // string userAgent = Request.UserAgent; // string access_token = AccessTokenService.GetAccessToken(); // string url = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", access_token); // // result = HttpWebResponseUtility.CreateGetHttpResponse(url,null,userAgent,null); // HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(url, null, userAgent, null); // Stream stream = response.GetResponseStream(); // StreamReader sr = new StreamReader(stream); // string result = sr.ReadToEnd(); // WechatJsTicket ticket = JsonConvert.DeserializeObject<WechatJsTicket>(result); // string jsapi_ticket = ticket.ticket; // string url2 = Request.Url.ToString(); // string string1 = "jsapi_ticket=" + jsapi_ticket + // "&noncestr=" + "zhaozhengo" + // "×tamp=" + "1414587487" + // "&url=" + url2; // string x = SkyEncrypt.SHA1(string1); // ViewBag.signature = x; // return View(); //} //public ActionResult wechatjs() //{ // string access_token = AccessTokenService.GetAccessToken(); // string userAgent = Request.UserAgent; // string jsapi_ticket = WechatJsServices.GetJsapi_ticket(access_token, userAgent); // string timestamp = TimeHelp.GetTimeStamp(DateTime.Now, 10); // string nonceStr = "zhaozheng"; // string currentUrl = Request.Url.ToString(); // string signature = WechatJsServices.GetSignature(jsapi_ticket, nonceStr, timestamp, currentUrl); // WechatConfig wechatconfig = AccessTokenService.GetWechatConfig(); // ViewBag.timestamp = int.Parse(timestamp); // ViewBag.nonceStr = nonceStr; // ViewBag.appid = wechatconfig.Appid; // ViewBag.signature = signature; // ViewBag.jsapi_ticket = jsapi_ticket; // ViewBag.currentUrl = currentUrl; // return View(); //} public ActionResult GetUserInfo() { WechatConfig wechatconfig = AccessTokenService.GetWechatConfig(); string REDIRECT_URI = System.Web.HttpUtility.UrlEncode("http://wx.zzd123.com/Home/GetUserId"); string SCOPE = "snsapi_userinfo"; string url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wechatconfig.Appid + "&redirect_uri=" + REDIRECT_URI + "&response_type=code&scope=" + SCOPE + "&state=STATE#wechat_redirect"; return(Redirect(url)); }
public ActionResult WechatLogin(string redirectUrl) { // string sourceUrl = Request.UrlReferrer.ToString(); string userAgent = Request.UserAgent; WechatConfig wechatconfig = AccessTokenService.GetWechatConfig(); // string REDIRECT_URI = System.Web.HttpUtility.UrlEncode("http://peiban.zzd123.com/Ucenter/Register"); string REDIRECT_URI = System.Web.HttpUtility.UrlEncode(redirectUrl); string SCOPE = "snsapi_userinfo"; //string STATE = sourceUrl; string STATE = "statecanshu"; string url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wechatconfig.Appid + "&redirect_uri=" + REDIRECT_URI + "&response_type=code&scope=" + SCOPE + "&state=" + STATE + "#wechat_redirect"; return(Redirect(url)); }