添加C#sdk

This commit is contained in:
tanghc
2019-04-03 18:00:31 +08:00
parent 8fb4a66109
commit 2cff1a7c0b
35 changed files with 13483 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SDKCSharp.Request
{
/// <summary>
/// 元数据,放在属性上面,表示忽略签名
/// </summary>
sealed class IgnoreSign : Attribute
{
}
}

View File

@@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SDKCSharp;
namespace SDKCSharp.Common
{
public class OpenConfig
{
private String successCode = SdkConfig.SUCCESS_CODE;
/// <summary>
/// 返回码成功值
/// </summary>
public String SuccessCode
{
get { return successCode; }
set { successCode = value; }
}
private String defaultVersion = SdkConfig.DEFAULT_VERSION;
/// <summary>
/// 默认版本号
/// </summary>
public String DefaultVersion
{
get { return defaultVersion; }
set { defaultVersion = value; }
}
private String methodName = "method";
/// <summary>
/// 接口属性名
/// </summary>
public String MethodName
{
get { return methodName; }
set { methodName = value; }
}
private String versionName = "version";
/// <summary>
/// 版本号名称
/// </summary>
public String VersionName
{
get { return versionName; }
set { versionName = value; }
}
private String charsetName = "charset";
/// <summary>
/// 编码名称
/// </summary>
/// <value>The name of the charset.</value>
public string CharsetName { get => charsetName; set => charsetName = value; }
private String appKeyName = "app_id";
/// <summary>
/// appKey名称
/// </summary>
public String AppKeyName
{
get { return appKeyName; }
set { appKeyName = value; }
}
private String dataName = "biz_content";
/// <summary>
/// data名称
/// </summary>
public String DataName
{
get { return dataName; }
set { dataName = value; }
}
private String timestampName = "timestamp";
/// <summary>
/// 时间戳名称
/// </summary>
public String TimestampName
{
get { return timestampName; }
set { timestampName = value; }
}
private String timestampPattern = "yyyy-MM-dd HH:mm:ss";
/// <summary>
/// 时间戳格式
/// </summary>
public String TimestampPattern
{
get { return timestampPattern; }
set { timestampPattern = value; }
}
private String signName = "sign";
/// <summary>
/// 签名串名称
/// </summary>
public String SignName
{
get { return signName; }
set { signName = value; }
}
private String formatName = "format";
/// <summary>
/// 格式化名称
/// </summary>
public String FormatName
{
get { return formatName; }
set { formatName = value; }
}
private String formatType = "json";
/// <summary>
/// 格式类型
/// </summary>
public String FormatType
{
get { return formatType; }
set { formatType = value; }
}
private String accessTokenName = "app_auth_token";
/// <summary> accessToken名称
/// </summary>
public String AccessTokenName
{
get { return accessTokenName; }
set { accessTokenName = value; }
}
private String locale = "zh-CN";
/// <summary>
/// 国际化语言
/// </summary>
public String Locale
{
get { return locale; }
set { locale = value; }
}
private String responseCodeName = "code";
/// <summary>
/// 响应code名称
/// </summary>
public String ResponseCodeName
{
get { return responseCodeName; }
set { responseCodeName = value; }
}
private int connectTimeoutSeconds = 10;
/// <summary>
/// 请求超时时间
/// </summary>
public int ConnectTimeoutSeconds
{
get { return connectTimeoutSeconds; }
set { connectTimeoutSeconds = value; }
}
private int readTimeoutSeconds = 10;
/// <summary>
/// http读取超时时间
/// </summary>
public int ReadTimeoutSeconds
{
get { return readTimeoutSeconds; }
set { readTimeoutSeconds = value; }
}
private string signTypeName = "sign_type";
/// <summary>
/// 签名类型名称
/// </summary>
/// <value>The name of the sign type.</value>
public string SignTypeName { get => signTypeName; set => signTypeName = value; }
}
}

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SDKCSharp.Common
{
public class RequestForm
{
private Dictionary<string, string> form;
/// <summary>
/// 请求表单内容
/// </summary>
public Dictionary<string, string> Form
{
get { return form; }
set { form = value; }
}
private List<UploadFile> files;
/// <summary>
/// 上传文件
/// </summary>
public List<UploadFile> Files
{
get { return files; }
set { files = value; }
}
public RequestForm(Dictionary<string, string> form)
{
this.form = form;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SDKCSharp.Common
{
public class SdkConfig
{
public static String SUCCESS_CODE = "10000";
public static String DEFAULT_VERSION = "1.0";
public static String FORMAT_TYPE = "json";
public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static String CHARSET = "UTF-8";
public static String SIGN_TYPE = "RSA2";
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace SDKCSharp.Common
{
public class SopSignature
{
public SopSignature()
{
}
public static String getSignContent(Dictionary<string, string> form)
{
StringBuilder content = new StringBuilder();
List<string> keys = new List<string>(form.Keys);
keys.Sort();
int index = 0;
for (int i = 0; i < keys.Count; i++)
{
string key = keys[i];
string value = form[key];
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
{
content.Append((index == 0 ? "" : "&") + key + "=" + value);
index++;
}
}
return content.ToString();
}
}
}

View File

@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using SDKCSharp.Utility;
namespace SDKCSharp.Common
{
public class UploadFile
{
/// <summary>
/// 添加上传文件
/// </summary>
/// <param name="name">表单名称,不能重复</param>
/// <param name="filePath">文件路径</param>
public UploadFile(string name, string filePath)
: this(name, FileUtil.GetFileName(filePath), FileUtil.ReadFile(filePath))
{
}
/// <summary>
/// 添加上传文件
/// </summary>
/// <param name="name">表单名称,不能重复</param>
/// <param name="fileName">文件名称</param>
/// <param name="fileStream">文件流</param>
public UploadFile(string name, string fileName, FileStream fileStream)
: this(name, fileName, FileUtil.ReadFile(fileStream))
{
}
/// <summary>
/// 添加上传文件
/// </summary>
/// <param name="name">表单名称,不能重复</param>
/// <param name="fileName">文件名称</param>
/// <param name="fileData">文件内容</param>
public UploadFile(string name, string fileName, byte[] fileData)
{
this.name = name;
this.fileName = fileName;
this.fileData = fileData;
this.md5 = MD5Util.Encrypt(fileData);
}
private string name;
public string Name
{
get { return name; }
}
private string fileName;
public string FileName
{
get { return fileName; }
}
private byte[] fileData;
public byte[] FileData
{
get { return fileData; }
}
private string md5;
public string Md5
{
get { return md5; }
}
}
}