using BasePaySdk.Request;
using System;
using System.Collections.Generic;
namespace BasePaySdk
{
public class BasePayClient
{
///
/// 发送报文请求
///
///
/// 功能编码
/// 请求报文
/// 商户配置key
///
/// 返回报文
///
public static Dictionary postRequest(string funcCode, Dictionary requestParams, string merchantKey = "default") {
MerConfig config = BasePay.fetchConfig(merchantKey);
return NetUtils.requestBasePay(requestParams, funcCode, NetUtils.POST, config);
}
///
/// 上传文件请求
///
///
/// 功能编码
/// 请求报文
/// 上传文件路径
/// 商户配置key
///
/// 返回报文
///
public static Dictionary postRequestFile(string funcCode, Dictionary requestParams, string filePath, string merchantKey = "default")
{
MerConfig config = BasePay.fetchConfig(merchantKey);
return NetUtils.requestBasePayForFileUpload(requestParams, filePath, "file", funcCode, NetUtils.POST, config);
}
///
/// 发送报文请求
///
///
/// 请求类
/// 商户配置key
/// 是否文件类
/// 返回报文
///
public static Dictionary postRequest(BaseRequest request,string filePath,string merchantKey = "default")
{
MerConfig config = BasePay.fetchConfig(merchantKey);
//1.把requset转为map,适应requestParams
Dictionary requestParams = CoreUtils.ObjToMap(request);
//2.把reqest.extendInfos 里的键值,覆盖已有的
if (request.getExtendInfos() != null && request.getExtendInfos().Count > 0)
{
foreach (KeyValuePair item in request.getExtendInfos())
{
if (requestParams.ContainsKey(item.Key) ){
requestParams.Remove(item.Key);
}
requestParams.Add(item.Key, item.Value);
}
}
if (!string.IsNullOrEmpty(filePath))
{
return postRequestFile(request.getFunctionCode(), requestParams, filePath);
}
else
{
return NetUtils.requestBasePay(requestParams, request.getFunctionCode(), NetUtils.POST, config);
}
}
}
}