62,046
社区成员
发帖
与我相关
我的任务
分享
string Alipay_APPID = "20160xxxxxxxxxxxx";
string Alipay_RSAPrivate = "MIICXQxxxxxx";
string Alipay_TokenT = "";
string Alipay_ReToken = "";
string Alipay_Code = "0a844a1f6a544acf838a910b25aaYX45";
string Alipay_ReTokenT = "";
string Alipay_Token = "";
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string start_time = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
string time_end = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
byte[] privateKey = Convert.FromBase64String(Alipay_RSAPrivate);
RSACryptoServiceProvider rSACryptoServiceProvider = Cean.Common.RSA_Str.RSASignData(privateKey);
XmlDocument xmlDocument = new XmlDocument();
string para = "app_id=" + Alipay_APPID;
para += "&charset=GBK";
para += "&code=" + Alipay_Code;
para += "&format=xml&grant_type=authorization_code";
para += "&method=alipay.system.oauth.token&sign_type=RSA";
para = para + "×tamp=" + timestamp;
para += "&version=1.0";
string sign_temp = Convert.ToBase64String(rSACryptoServiceProvider.SignData(Encoding.Default.GetBytes(para), "SHA1"));
string urlHtml = Utils.GetUrlHtml("https://openapi.alipay.com/gateway.do", "GBK", para + "&sign=" + HttpUtility.UrlEncode(sign_temp, Encoding.GetEncoding("GBK")));
xmlDocument.LoadXml(urlHtml);
if (xmlDocument.SelectNodes("/alipay_system_oauth_token_response").Count > 0)
{
//*************这边可以读取到access_token及用户userId等信息
Alipay_Token = xmlDocument.SelectNodes("/alipay_system_oauth_token_response")[0]["refresh_token"].Innerpara.ToString();
}
para = "app_id=" + Alipay_APPID;
para += "&auth_token=" + Alipay_Token;
para += "&charset=GBK&end_time=" + time_end;
para += "&format=xml&method=alipay.user.trade.search&order_from=TAOBAO";
para += "&page_no=1&page_size=30&sign_type=RSA";
para += "&start_time=" + start_time;
para += "×tamp=" + timestamp;
para += "&version=1.0";
str4 = Convert.ToBase64String(rSACryptoServiceProvider.SignData(Encoding.Default.GetBytes(para), "SHA1"));
urlHtml =Utils.GetUrlHtml("https://openapi.alipay.com/gateway.do", "GBK", para + "&sign=" + HttpUtility.UrlEncode(str4, Encoding.GetEncoding("GBK")));
//****************执行上一句时就会提示“无效的令牌访问”,不知是哪里出了问题。**************
<?xml version=\"1.0\" encoding=\"GBK\" ?><error_response><code>20001</code><msg>Insufficient Token Permissions</msg><sub_code>aop.invalid-auth-token</sub_code><sub_msg>无效的访问令牌</sub_msg><sign>Ra1OgQUjsIdl8t7v9r1jITDxLb71wEZYLm69vCMRwZGn3jRLV4SAE01zxwmBcuo0/yq5LomUkxw5dnWuRur2MX4H/gzjGPvzSrqgMBR46XcNtvAVMvgGVxmMNn0/NCdgLmvaf4cgo7jteNymKfEbPXU6zbReVaS6AbUQrB7KcME=</sign></error_response>"
string app_id = "201603040xxxxxxx";
string merchant_private_key = Server.MapPath("/t/rsa_private_key.pem");
string alipay_public_key = Server.MapPath("/t/rsa_public_key.pem");
IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app_id, merchant_private_key, "json", "GBK", alipay_public_key);
AlipayUserTradeSearchRequest request = new AlipayUserTradeSearchRequest();
request.StartTime = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
request.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
request.OrderType = "TRADE";
request.OrderStatus = "TRADE_FINISHED";
request.OrderFrom = "TAOBAO";
request.PageNo = "1";
request.PageSize = "100";
AlipayUserTradeSearchResponse response = client.Execute(request);
string app_id = "201603040xxxxxxx";
string Alipay_Code = "71f2866496c84cf3ba1c9bab0555UB45";
string merchant_private_key = Server.MapPath("/t/rsa_private_key.pem");
string alipay_public_key = Server.MapPath("/t/rsa_public_key.pem");//RSA
IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app_id, merchant_private_key, "json", "1.0", "RSA");
#region 获取access_token
AlipaySystemOauthTokenRequest request_oauth = new AlipaySystemOauthTokenRequest();
request_oauth.GrantType = "authorization_code";
request_oauth.Code = Alipay_Code;
AlipaySystemOauthTokenResponse response_oauth = client.Execute(request_oauth);
#endregion
AlipayUserTradeSearchRequest request = new AlipayUserTradeSearchRequest();
request.StartTime = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
request.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
request.OrderType = "TRADE";
request.OrderStatus = "TRADE_FINISHED";
request.PageNo = "1";
request.PageSize = "100";
AlipayUserTradeSearchResponse response = client.Execute(request, response_oauth.AccessToken);
顶上去,有没人在啊,帮忙看下为什么会返回:“无效的访问令牌”
谢谢各位了。