抖音退款接口:https://developer.toutiao.com/api/apps/ecpay/v1/create_refund 的签名方式请用.net代码写一个方法
时间: 2023-08-29 14:07:09 浏览: 234
仿牛客博客项目源码(有部分功能没有实现) https://gitee.com/xudahu/community
以下是使用C#语言编写的抖音退款接口签名方法:
```csharp
using System;
using System.Security.Cryptography;
using System.Text;
public static string GenerateSignature(string appid, string secret, long timestamp, string refundId, string orderId, int refundAmount, int refundReasonId, string refundReasonInfo)
{
// 将参数按照字典序排序
var sortedParams = new SortedDictionary<string, string>
{
{ "app_id", appid },
{ "refund_id", refundId },
{ "order_id", orderId },
{ "refund_amount", refundAmount.ToString() },
{ "refund_reason_id", refundReasonId.ToString() },
{ "refund_reason_info", refundReasonInfo },
{ "timestamp", timestamp.ToString() }
};
// 拼接参数字符串
var paramString = new StringBuilder();
foreach (var item in sortedParams)
{
paramString.Append(item.Key).Append("=").Append(item.Value).Append("&");
}
paramString.Append("app_secret=").Append(secret);
// 计算签名
var sha256 = SHA256.Create();
var hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(paramString.ToString()));
var signature = Convert.ToBase64String(hashBytes);
return signature;
}
```
该方法接受以下参数:
- `appid`:开发者应用唯一标识符
- `secret`:开发者应用密钥
- `timestamp`:当前时间戳,单位为秒
- `refundId`:退款单号
- `orderId`:原订单号
- `refundAmount`:退款金额,单位为分
- `refundReasonId`:退款原因编号
- `refundReasonInfo`:退款原因描述
该方法返回一个字符串,表示计算得到的签名值。
阅读全文