1.做的准备工作:看公众平台文档 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
2.在微信公众号请求用户网页授权之前,开发者需要先到公众平台官网中的“开发 - 接口权限 - 网页服务 - 网页帐号 - 网页授权获取用户基本信息”的配置选项中,修改授权回调域名。请注意,这里填写的是域名例如:www.qq.com,你必须配置成www.123.com
如果你的地址是https://www.123.com/abc.aspx
那么请把https://www.123.com/abc.aspx这个转换成使用urlEncode对链接进行处理,工具地址http://tool.chinaz.com/tools/urlencode.aspx
生成这个地址 https%3a%2f%2fwww.123.com%2fabc.aspx
你肯定有一个公众号的appid=QWERTY23456
那么你把地址改成这个
这个就是你的链接地址,它给你一个code,你通过网页获取,就是你的https://www.123.com/abc.aspx获取。
4.做sap.NET中C#的开发,abc.aspx代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using System.Net;
public partial class index002 : System.Web.UI.Page
{
public string xxx;
protected void Page_Load(object sender, EventArgs e)
{
string code = Request["code"].ToString();
Response.Write("CODE: ");
Response.Write(code);
Response.Write("<br/>");
string html = string.Empty;
string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=QWERTY23456&secret=你的密码&code=" + code + "&grant_type=authorization_code";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "GET";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream ioStream = response.GetResponseStream();
StreamReader sr = new StreamReader(ioStream, Encoding.UTF8);
html = sr.ReadToEnd();
sr.Close();
ioStream.Close();
response.Close();
string key = "\"openid\":\"";
int startIndex = html.IndexOf(key);
if (startIndex != -1)
{
int endIndex = html.IndexOf("\",", startIndex);
string openid = html.Substring(startIndex + key.Length, endIndex - startIndex - key.Length);
Response.Write("OPENID: ");
Response.Write(openid);
}
else
{
Response.Write("获取openid未成功!");
}
}
}
5.ok