获取支付宝授权用户信息
<p>登录 支付宝开放平台,创建应用</p><p><div align="center"></div></p>
<p>进入应用</p>
<p><div align="center"></div></p>
<p>在应用信息里设置两处,授权回调只需要到域名即可。</p>
<p>接口加签方式如下图</p>
<p><div align="center"></div></p>
<p>利用“支付宝密钥生成器”生成,如下图</p>
<p><div align="center"></div></p>
<p>将公钥复制到 接口加签方式 的公钥字符。</p>
<p> </p>
<p>程序:</p>
<p>String auth_code = context.Request.QueryString["auth_code"];<br /> String stateStr = String.Empty;<br /> if (String.IsNullOrEmpty(auth_code)) //如果为空体现要获取<br /> {<br /> String ParkID = context.Request.QueryString["sjh"];<br /> String DeviceID = context.Request.QueryString["deviceid"];<br /> String PayModel = context.Request.QueryString["paymodel"];//支付方式:场内(PayInPark)、出口(PayOutPark)</p>
<p> stateStr = String.Format("sjh={0}&deviceid={1}&paymodel={2}", ParkID, DeviceID, PayModel);</p>
<p><strong> //获取auth_code</strong><br /> String redirect_uri = "http://www.zftong.cn/Cn.Ubingo/AlipayAuth/GetAlipayAuth.ashx"; <br /> redirect_uri = HttpUtility.UrlEncode(redirect_uri);<br /> String accessUrl = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id={0}&scope=auth_base&redirect_uri={1}&state={2}";<br /> String accUrl = String.Format(accessUrl, AlipayConfig.APP_ID, redirect_uri, DESEncrypt.Encrypt(stateStr)); <br /> context.Response.Redirect(accUrl, true);<br /> context.Response.End();<br /> return;<br /> }</p>
<p><br /> IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AlipayConfig.APP_ID, AlipayConfig.Pri_Key, "json", "1.0", "RSA2", AlipayConfig.Pub_Key, "GBK", false);<br /> <br /> <strong>//获取user_id和access_token</strong><br /> AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();<br /> request.GrantType = "authorization_code";<br /> request.Code = auth_code;<br /> AlipaySystemOauthTokenResponse responseAccess_token = client.Execute(request);<br /> <strong>//获取用户信息 注:在获取auth_code时,如果是auth_base无法获取用户信息,需要auth_user</strong><br /> //AlipayUserInfoShareRequest requestUserinfo = new AlipayUserInfoShareRequest();<br /> //AlipayUserInfoShareResponse responseUserinfo = client.Execute(requestUserinfo, responseAccess_token.AccessToken);<br /> //String UserName = responseUserinfo.NickName;</p><br><br/><br/><br/><br/><br/>来源:<a href="https://www.cnblogs.com/KimhillZhang/p/11551848.html" target="_blank">https://www.cnblogs.com/KimhillZhang/p/11551848.html</a> 获取支付宝授权用户信息 [复制链接]
页:
[1]