/// <summary> /// 获取网页授权链接 /// </summary> /// <param name="redirectUrl">授权后重定向的回调链接地址,请使用urlencode对链接进行处理</param> /// <param name="state">重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节</param> /// <param name="appid"></param> /// <param name="scope"> /// 应用授权作用域 /// snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid), /// snsapi_userinfo(弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息) /// </param> /// <returns></returns> private static string GetAuthorizeUrl(string redirectUrl, string state, string appid, OAuthScopes scope = OAuthScopes.snsapi_userinfo) { return($"https://open.weixin.qq.com/connect/oauth2/authorize?appid={appid}&redirect_uri={UrlEncoder.Default.Encode(redirectUrl)}&response_type=code&scope={scope}&state={state}#wechat_redirect"); }
public string GetScanCodeAuthorizeUrl(string redirectUrl, string state, OAuthScopes scope = OAuthScopes.snsapi_userinfo) { return(string.Format( "https://open.weixin.qq.com/connect/qrconnect?appid={0}&redirect_uri={1}&response_type={2}&scope={3}&state={4}#wechat_redirect", AppConfig.AppId, redirectUrl.UrlEncode(), "code", scope, state)); }