1、首先必须获得Token
CRMComm crm = new CRMComm();
string error = "";
string accToken = crm.GetAccessToken(out error);
2、向指定用户发送信息
Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(accToken, openid, text);
3、DTcms.API.Weixin.Common下的MessageFunction.cs中
/// <summary>
/// 推送纯文字
/// </summary>
public IResponseMessageBase GetResponseMessageTxt(RequestMessageEventBase requestMessage, int ruleId)
{}
可以写用户关注时,向用户发送的文字信息
4、 /// <summary>
/// 获得微信用户信息
/// </summary>
/// <param name="openid"></param>
/// <returns></returns>
public Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson WX_User(string accToken, string openid)
{
Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson user = Senparc.Weixin.MP.AdvancedAPIs.UserApi.Info(accToken, openid);
return user;
}
5、网站授权登录
code在授权页面直接用DTRequest.GetQueryString("code")获得
Senparc.Weixin.MP.AdvancedAPIs.OAuth.OAuthAccessTokenResult accto = Senparc.Weixin.MP.AdvancedAPIs.OAuthApi.GetAccessToken(appid, appsecret, code);
获得单个微信用户信息Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson user = Senparc.Weixin.MP.AdvancedAPIs.UserApi.Info(crm.GetAccessToken(out error), accto.openid);
6、授权登录后带参数。
https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=http%3a%2f%2fwww.baidu.com.com%2fadmin/wxadminlogin.aspx%3fopenid=" + openid + "&response_type=code&scope=snsapi_userinfo&state=redirectUrl#wechat_redirect
其中%3fopenid=" + openid + " 为附带的参数,若直接在地址栏中用?,是不能被识别的,用url编码为%3f。