抖音退款接口:https://developer.toutiao.com/api/apps/ecpay/v1/create_refund 的签名方式请用.net代码写一个方法
时间: 2023-08-29 22:07:09 浏览: 97
以下是使用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`:退款原因描述
该方法返回一个字符串,表示计算得到的签名值。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)