|
本帖最后由 BIP851961 于 2023-11-16 11:46 编辑
{"code":"10000","message":"com.yonyoucloud.open**.**mon.exception.OpenAuthSystemException: 签名不正确"}
参考:【新提醒】C#接口调用示例(供参考)_用友YonBIP开发者社区 (yonyou.com)
其中修改参考代码
1. 地址,依照tenantid获取修改
2. 时间戳毫秒
private static readonly string URL_GETACCESSTOKEN = "XXXX c3.yonyoucloud.com/iuap-api-auth/open-auth/selfAppAuth/base/v1/getAccessToken?";
//获取自建应用TOKEN
public static string GetSelfToken(string appKey,string appSecret)
{
string token = string.Empty;
string timestamp = string.Empty;
string signature=GetSignature(appKey, appSecret,ref timestamp);
string url = URL_GETACCESSTOKEN + $"appKey={appKey}×tamp={timestamp}&signature={signature}";
string response=HttpGet(url) ;
var rsp = Clay.Parse(response);
if (rsp["code"] == "00000")
{
token = rsp["data"]["access_token"];
}
return token;
}
/// <summary>
/// 签名
/// </summary>
/// <param name="appKey"></param>
/// <returns></returns>
private static string GetSignature(string appKey,string appSecret,ref string timestamp)
{
timestamp = GetTimestamp();
string parameterMap = $"appkey{appKey}timestamp{timestamp}";
string signature = System.Web.HttpUtility.UrlEncode(
HmacSHA256(parameterMap, appSecret),
Encoding.UTF8);
return signature;
}
private static string GetTimestamp()
{
var ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0);
string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
return timestamp;
}
private static string HmacSHA256(string secret, string signKey)
{
string signRet = string.Empty;
using (HMACSHA256 mac = new HMACSHA256(Encoding.UTF8.GetBytes(signKey)))
{
byte[] hash =**.**puteHash(Encoding.UTF8.GetBytes(secret));
signRet = Convert.ToBase64String(hash);
}
return signRet;
}
|
|