本机微信开发环境搭建
生活随笔
收集整理的這篇文章主要介紹了
本机微信开发环境搭建
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1,打開瀏覽器,這里以IE為例。輸入:http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
2,用手機登錄你的微信,使用微信中的“掃一掃”功能,掃描上面網頁中的二維碼。登錄測試公眾號后臺:
?
3.記住測試號的,appID和appsecret,用微信掃描測試公眾號的二維碼,并關注他
?
4.設置網頁服務—>網頁賬號 的回調地址為本機IP,我的是(192.168.21.49)
5,開始編寫測試代碼
public class HomeController : Controller{private const string appID = "wx158da7aeb0f4ecc9";// private const string appsecret = "9b9ff146f68cd9530c62ccbbb15b397d";// private const string redirect_uri = "http://192.168.21.49/Home/CallBack";//回調地址private const string AccessTokenUrl = "https://open.weixin.qq.com/connect/oauth2/authorize";//授權地址private const string GetInfoUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";//獲取微信信息/// <summary>/// 首頁/// </summary>/// <returns></returns>public ActionResult Index(){string url = string.Format("{0}?appid={1}&redirect_uri={2}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect", AccessTokenUrl, appID, redirect_uri);ViewBag.url = url;return View();}/// <summary>/// 授權回調地址/// </summary>/// <param name="code"></param>/// <returns></returns>public ActionResult CallBack(string code){IDictionary<string, string> dic = new Dictionary<string, string>();dic.Add("appid", appID);dic.Add("secret", appsecret);dic.Add("code", code);dic.Add("grant_type", "authorization_code");var tokenJson = new Top.Api.Util.WebUtils().DoPost(GetInfoUrl, dic);ViewBag.Callback = tokenJson;return View();}}?
Index.cshtml
@{ViewBag.Title = "Index"; } <meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0" /><a href="@ViewBag.url"><h1>去授權</h1></a>CallBack.cshtml
@{ViewBag.Title = "CallBack"; } <meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0" /> <h2>@ViewBag.Callback</h2>6.將代碼部署到本機IIS內
7,將程序地址生成二維碼
8,確保手機Wifi和電腦在同一局域網,掃描生成的地址二維碼測試成功
?
Code:http://files.cnblogs.com/files/longren629/WinXin.rar
轉載于:https://www.cnblogs.com/longren629/p/4666485.html
總結
以上是生活随笔為你收集整理的本机微信开发环境搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实力赢得信任丨西安珠江新城业主喜迎公元物
- 下一篇: swustoj木材加工(0436)