本机微信开发环境搭建
生活随笔
收集整理的這篇文章主要介紹了
本机微信开发环境搭建
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1,打開(kāi)瀏覽器,這里以IE為例。輸入:http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
2,用手機(jī)登錄你的微信,使用微信中的“掃一掃”功能,掃描上面網(wǎng)頁(yè)中的二維碼。登錄測(cè)試公眾號(hào)后臺(tái):
?
3.記住測(cè)試號(hào)的,appID和appsecret,用微信掃描測(cè)試公眾號(hào)的二維碼,并關(guān)注他
?
4.設(shè)置網(wǎng)頁(yè)服務(wù)—>網(wǎng)頁(yè)賬號(hào) 的回調(diào)地址為本機(jī)IP,我的是(192.168.21.49)
5,開(kāi)始編寫(xiě)測(cè)試代碼
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";//回調(diào)地址private const string AccessTokenUrl = "https://open.weixin.qq.com/connect/oauth2/authorize";//授權(quán)地址private const string GetInfoUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";//獲取微信信息/// <summary>/// 首頁(yè)/// </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>/// 授權(quán)回調(diào)地址/// </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>去授權(quán)</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.將代碼部署到本機(jī)IIS內(nèi)
7,將程序地址生成二維碼
8,確保手機(jī)Wifi和電腦在同一局域網(wǎng),掃描生成的地址二維碼測(cè)試成功
?
Code:http://files.cnblogs.com/files/longren629/WinXin.rar
轉(zhuǎn)載于:https://www.cnblogs.com/longren629/p/4666485.html
總結(jié)
以上是生活随笔為你收集整理的本机微信开发环境搭建的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 实力赢得信任丨西安珠江新城业主喜迎公元物
- 下一篇: swustoj木材加工(0436)