微信相关开发问题收集
1 微信公众号服务器设置token验证失败问题
开发-基本配置-服务器配置 首先设置这些参数,然后写好在服务器地址这里填写的页面如:
https://test.my.com/wx/weixin.aspx
using System;
using System.IO;
using Senparc.Weixin.MP;
using Senparc.Weixin.MP.CommonAPIs;
using Senparc.Weixin.MP.Entities.Request;
namespace Mobile.wx
{
public partial class Weixin : System.Web.UI.Page
{
private readonly string Token = "wxtest2001webmaster110";//与微信公众账号后台的Token设置保持一致,区分大小写。
private readonly string AppId = "wx2e906ed8dfa86ff1";
private readonly string AppSecret = "9e020de7b2fcab2f56ec81ec0489adce";
//private readonly string EncodingAESKey = "K7zNU4Kx6uKn5lUFBwL1CpJcKOAYMXbzGdhUvufiU";
protected void Page_Load(object sender, EventArgs e)
{
string signature = Request["signature"];
string timestamp = Request["timestamp"];
string nonce = Request["nonce"];
string echostr = Request["echostr"];
if (Request.HttpMethod == "GET")
{
//get method - 仅在微信后台填写URL验证时触发
if (CheckSignature.Check(signature, timestamp, nonce, Token))
{
//WriteContent(echostr); //返回随机字符串则表示验证通过
CustomMenu();
}
else
{
//WriteContent("failed:" + signature + "," + CheckSignature.GetSignature(timestamp, nonce, Token) + "。" +
// "如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。");
CustomMenu();
}
Response.End();
}
else
{
//post method - 当有用户想公众账号发送消息时触发
if (!CheckSignature.Check(signature, timestamp, nonce, Token))
{
WriteContent("参数错误!");
return;
}
}
}
private void WriteContent(string str)
{
Response.Output.Write(str);
}
public void CustomMenu()
{
string accessToken = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetToken(AppId, AppSecret).access_token;
Senparc.Weixin.MP.Entities.Menu.ButtonGroup menu = new Senparc.Weixin.MP.Entities.Menu.ButtonGroup();
Senparc.Weixin.MP.Entities.Menu.SingleViewButton btn =
new Senparc.Weixin.MP.Entities.Menu.SingleViewButton();
btn.name = "test";
btn.url = "http://test.my.com/index.html";
menu.button.Add(btn);
省略
CommonApi.CreateMenu(accessToken, menu);
}
}
}
这个页面做好后可以在浏览器打开,如果appsecret 错误会提示,如果没有错误就在公众号设置页面提交,
如果提示 token验证失败,就仔细检查appid,appsecret,token是否对,如果都对还提示该错误,请检查下公众号设置-功能设置里是否把这个地址的域名填写在下面几个域名设置里;
2 公众号内登录问题
如果在公众号内用 https://open.weixin.qq.com/connect/oauth2/authorize?appid=你的公众号appid&redirect_uri=https://wx.fygdrs.com/h5/wxlogin.aspx&response_type=code&scope=snsapi_base&state=1#wechat_redirect 这个登录地址,且当前公众号appid,与登录地址里的appid是同一个的话,会静默登录,即不提示授权,如果不一致的话会登录失败,无任何提示
如何登录用这样的地址 https://open.weixin.qq.com/connect/oauth2/authorize?appid=你的公众号appid&redirect_uri=https://wx.fygdrs.com/h5/wxlogin.aspx&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect
则没有问题,当前公众号appid,与登录地址里的appid是同一个的话,会静默登录,不同的会跳出授权页面。
这两个地址不同的地方在 一个是 scope=snsapi_userinfo,一个是 scope=snsapi_base
3 微信开发者工具调试公众号程序提示"未绑定网页开发者"
在公众平台→开发→开发者工具→web开发者工具,将你的微信号添加到开发者测试号列表中。被添加的微信用户在手
--- end ---