获取支付宝授权用户信息
登录 支付宝开放平台,创建应用
进入应用
在应用信息里设置两处,授权回调只需要到域名即可。
接口加签方式如下图
使用“支付宝密钥生成器”生成,如下图
将公钥复制到 接口加签方式 的公钥字符。
程序:
string auth_code = context.request.querystring["auth_code"];
string statestr = string.empty;
if (string.isnullorempty(auth_code)) //如果为空表示要获取
{
string parkid = context.request.querystring["sjh"];
string deviceid = context.request.querystring["deviceid"];
string paymodel = context.request.querystring["paymodel"];//支付方式:场内(payinpark)、出口(payoutpark)
statestr = string.format("sjh={0}&deviceid={1}&paymodel={2}", parkid, deviceid, paymodel);
//获取auth_code
string redirect_uri = "http://www.zftong.cn/cn.ubingo/alipayauth/getalipayauth.ashx";
redirect_uri = httputility.urlencode(redirect_uri);
string accessurl = "https://openauth.alipay.com/oauth2/publicappauthorize.htm?app_id={0}&scope=auth_base&redirect_uri={1}&state={2}";
string accurl = string.format(accessurl, alipayconfig.app_id, redirect_uri, desencrypt.encrypt(statestr));
context.response.redirect(accurl, true);
context.response.end();
return;
}
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);
//获取user_id和access_token
alipaysystemoauthtokenrequest request = new alipaysystemoauthtokenrequest();
request.granttype = "authorization_code";
request.code = auth_code;
alipaysystemoauthtokenresponse responseaccess_token = client.execute(request);
//获取用户信息 注:在获取auth_code时,如果是auth_base无法获取用户信息,需要auth_user
//alipayuserinfosharerequest requestuserinfo = new alipayuserinfosharerequest();
//alipayuserinfoshareresponse responseuserinfo = client.execute(requestuserinfo, responseaccess_token.accesstoken);
//string username = responseuserinfo.nickname;
上一篇: Winform中设置ZedGraph的字体和间距不随图形的缩放而缩放
下一篇: 动态添加class