|
|
@ -16,50 +16,112 @@ using Newtonsoft.Json.Linq; |
|
|
|
namespace SDKCSharp.Client |
|
|
|
namespace SDKCSharp.Client |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 客户端 |
|
|
|
/// 客户端,申明一个即可 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public class OpenClient |
|
|
|
public class OpenClient |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 默认配置 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
private static OpenConfig DEFAULT_CONFIG = new OpenConfig(); |
|
|
|
private static OpenConfig DEFAULT_CONFIG = new OpenConfig(); |
|
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, string> header = new Dictionary<string, string>(); |
|
|
|
private Dictionary<string, string> header = new Dictionary<string, string>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 接口请求url |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
private string url; |
|
|
|
private string url; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 平台提供的appId |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
private string appId; |
|
|
|
private string appId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 开放平台提供的私钥 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
private string privateKey; |
|
|
|
private string privateKey; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 开放平台提供的公钥 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
private string publicKeyPlatform; |
|
|
|
private string publicKeyPlatform; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 配置项 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
private OpenConfig openConfig; |
|
|
|
private OpenConfig openConfig; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 请求对象 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
private OpenRequest openRequest; |
|
|
|
private OpenRequest openRequest; |
|
|
|
private DataNameBuilder dataNameBuilder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 节点处理 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
private DataNameBuilder dataNameBuilder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 构建请求客户端 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="url">接口url</param> |
|
|
|
|
|
|
|
/// <param name="appId">平台分配的appId</param> |
|
|
|
|
|
|
|
/// <param name="privateKey">平台分配的私钥</param> |
|
|
|
public OpenClient(string url, string appId, string privateKey) |
|
|
|
public OpenClient(string url, string appId, string privateKey) |
|
|
|
: this(url, appId, privateKey,false, DEFAULT_CONFIG) |
|
|
|
: this(url, appId, privateKey,false, DEFAULT_CONFIG) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 构建请求客户端 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="url">接口url</param> |
|
|
|
|
|
|
|
/// <param name="appId">平台分配的appId</param> |
|
|
|
|
|
|
|
/// <param name="privateKey">平台分配的私钥</param> |
|
|
|
|
|
|
|
/// <param name="publicKeyPlatform">平台分配的公钥</param> |
|
|
|
public OpenClient(string url, string appId, string privateKey, string publicKeyPlatform) |
|
|
|
public OpenClient(string url, string appId, string privateKey, string publicKeyPlatform) |
|
|
|
: this(url, appId, privateKey) |
|
|
|
: this(url, appId, privateKey) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.publicKeyPlatform = publicKeyPlatform; |
|
|
|
this.publicKeyPlatform = publicKeyPlatform; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 构建请求客户端 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="url">接口url</param> |
|
|
|
|
|
|
|
/// <param name="appId">平台分配的appId</param> |
|
|
|
|
|
|
|
/// <param name="privateKey">平台分配的私钥</param> |
|
|
|
|
|
|
|
/// <param name="priKeyFromFile">如果设置 <c>true</c> 从文件中加载私钥</param> |
|
|
|
public OpenClient(string url, string appId, string privateKey, bool priKeyFromFile) |
|
|
|
public OpenClient(string url, string appId, string privateKey, bool priKeyFromFile) |
|
|
|
: this(url, appId, privateKey, priKeyFromFile, DEFAULT_CONFIG) |
|
|
|
: this(url, appId, privateKey, priKeyFromFile, DEFAULT_CONFIG) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 构建请求客户端 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="url">接口url</param> |
|
|
|
|
|
|
|
/// <param name="appId">平台分配的appId</param> |
|
|
|
|
|
|
|
/// <param name="privateKey">平台分配的私钥</param> |
|
|
|
|
|
|
|
/// <param name="priKeyFromFile">如果设置 <c>true</c> 从文件中加载私钥</param> |
|
|
|
|
|
|
|
/// <param name="publicKeyPlatform">平台分配的公钥</param> |
|
|
|
public OpenClient(string url, string appId, string privateKey, bool priKeyFromFile, string publicKeyPlatform) |
|
|
|
public OpenClient(string url, string appId, string privateKey, bool priKeyFromFile, string publicKeyPlatform) |
|
|
|
: this(url, appId, privateKey, priKeyFromFile) |
|
|
|
: this(url, appId, privateKey, priKeyFromFile) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.publicKeyPlatform = publicKeyPlatform; |
|
|
|
this.publicKeyPlatform = publicKeyPlatform; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 构建请求客户端 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="url">接口url</param> |
|
|
|
|
|
|
|
/// <param name="appId">平台分配的appId</param> |
|
|
|
|
|
|
|
/// <param name="privateKey">平台分配的私钥</param> |
|
|
|
|
|
|
|
/// <param name="priKeyFromFile">如果设置 <c>true</c> 从文件中加载私钥</param> |
|
|
|
|
|
|
|
/// <param name="openConfig">配置项</param> |
|
|
|
public OpenClient(string url, string appId, string privateKey,bool priKeyFromFile, OpenConfig openConfig) |
|
|
|
public OpenClient(string url, string appId, string privateKey,bool priKeyFromFile, OpenConfig openConfig) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.url = url; |
|
|
|
this.url = url; |
|
|
@ -75,6 +137,15 @@ namespace SDKCSharp.Client |
|
|
|
this.dataNameBuilder = openConfig.DataNameBuilder; |
|
|
|
this.dataNameBuilder = openConfig.DataNameBuilder; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 构建请求客户端 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="url">接口url</param> |
|
|
|
|
|
|
|
/// <param name="appId">平台分配的appId</param> |
|
|
|
|
|
|
|
/// <param name="privateKey">平台分配的私钥</param> |
|
|
|
|
|
|
|
/// <param name="priKeyFromFile">如果设置 <c>true</c> 从文件中加载私钥</param> |
|
|
|
|
|
|
|
/// <param name="publicKeyPlatform">平台分配的公钥</param> |
|
|
|
|
|
|
|
/// <param name="openConfig">配置项</param> |
|
|
|
public OpenClient(string url, string appId, string privateKey, bool priKeyFromFile, string publicKeyPlatform, OpenConfig openConfig) |
|
|
|
public OpenClient(string url, string appId, string privateKey, bool priKeyFromFile, string publicKeyPlatform, OpenConfig openConfig) |
|
|
|
: this(url, appId, privateKey, priKeyFromFile, openConfig) |
|
|
|
: this(url, appId, privateKey, priKeyFromFile, openConfig) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -203,6 +274,14 @@ namespace SDKCSharp.Client |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 构建业务json内容。 |
|
|
|
|
|
|
|
/// 假设返回的结果是:{"alipay_story_get_response":{"msg":"Success","code":"10000","name":"海底小纵队","id":1},"sign":"xxx"} |
|
|
|
|
|
|
|
/// 将解析得到:{"msg":"Success","code":"10000","name":"海底小纵队","id":1} |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <returns>The biz json.</returns> |
|
|
|
|
|
|
|
/// <param name="rootNodeName">根节点名称.</param> |
|
|
|
|
|
|
|
/// <param name="body">返回内容.</param> |
|
|
|
protected virtual string BuildBizJson(string rootNodeName, string body) |
|
|
|
protected virtual string BuildBizJson(string rootNodeName, string body) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int indexOfRootNode = body.IndexOf(rootNodeName); |
|
|
|
int indexOfRootNode = body.IndexOf(rootNodeName); |
|
|
@ -219,6 +298,14 @@ namespace SDKCSharp.Client |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 获取业务结果,如下结果:{"alipay_story_get_response":{"msg":"Success","code":"10000","name":"海底小纵队","id":1},"sign":"xxx"} |
|
|
|
|
|
|
|
/// 将返回:{"msg":"Success","code":"10000","name":"海底小纵队","id":1} |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <returns>The json node data.</returns> |
|
|
|
|
|
|
|
/// <param name="body">Body.</param> |
|
|
|
|
|
|
|
/// <param name="rootNode">Root node.</param> |
|
|
|
|
|
|
|
/// <param name="indexOfRootNode">Index of root node.</param> |
|
|
|
protected virtual string BuildJsonNodeData(string body, string rootNode, int indexOfRootNode) |
|
|
|
protected virtual string BuildJsonNodeData(string body, string rootNode, int indexOfRootNode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int signDataStartIndex = indexOfRootNode + rootNode.Length + 2; |
|
|
|
int signDataStartIndex = indexOfRootNode + rootNode.Length + 2; |
|
|
|