|
|
using POSV.Card;
|
|
|
using POSV.HttpApi;
|
|
|
using POSV.Utils;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
|
|
|
namespace POSV.QiMai
|
|
|
{
|
|
|
|
|
|
public class QiMaiUtils
|
|
|
{
|
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
protected static Dictionary<string, string> _errorDesc = new Dictionary<string, string>();
|
|
|
|
|
|
static QiMaiUtils()
|
|
|
{
|
|
|
//------------------------------------------------------
|
|
|
//系统没有定义的错误代码
|
|
|
_errorDesc.Add("9999", "应答的报文解析异常");
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 门店信息
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiEntityResponse<QiMaiShopQueryResponse>> QiMaiShopQuery(QiMaiShopQueryRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiEntityResponse<QiMaiShopQueryResponse>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.shop.query");
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiEntityResponse<QiMaiShopQueryResponse>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiShopQueryResponse>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiShopQueryResponse>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiShopQueryResponse>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信门店信息获取异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiShopQueryResponse>>(false, "微信门店信息获取异常,请检查网络连接", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 企迈小程序待处理订单查询,这个接口只返回外卖订单,堂食订单默认已经接单
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiListResponse<QiMaiOrder>> QiMaiQrderHandle(QiMaiQrderHandleRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiListResponse<QiMaiOrder>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.order.handle");
|
|
|
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiListResponse<QiMaiOrder>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiListResponse<QiMaiOrder>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiListResponse<QiMaiOrder>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiListResponse<QiMaiOrder>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "待处理企迈订单查询异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiListResponse<QiMaiOrder>>(false, "待处理订单询异常,本次操作无效", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 美团历史订单查询
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiPagerResponse<QiMaiOrder>> QiMaiQrderList(QiMaiQrderListRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiPagerResponse<QiMaiOrder>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.order.list");
|
|
|
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("pageNumber", string.Format("{0}", request.PageNumber));
|
|
|
parameters.Add("pageSize", string.Format("{0}", request.PageSize));
|
|
|
parameters.Add("orderDate", request.OrderDate);
|
|
|
parameters.Add("type", string.Format("{0}", request.Type));
|
|
|
|
|
|
var ignoreParameters = new List<string>();
|
|
|
ignoreParameters.Add("pageNumber");
|
|
|
ignoreParameters.Add("pageSize");
|
|
|
ignoreParameters.Add("orderDate");
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignoreParameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiPagerResponse<QiMaiOrder>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiPagerResponse<QiMaiOrder>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiPagerResponse<QiMaiOrder>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiPagerResponse<QiMaiOrder>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信订单查询异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiPagerResponse<QiMaiOrder>>(false, "微信订单询异常,本次操作无效", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 门店状态变更
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiEntityResponse<QiMaiShopStatusResponse>> QiMaiShopStatus(QiMaiShopStatusRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiEntityResponse<QiMaiShopStatusResponse>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.shop.status");
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("status", request.Status);
|
|
|
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiEntityResponse<QiMaiShopStatusResponse>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiShopStatusResponse>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiShopStatusResponse>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiShopStatusResponse>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信门店状态更改异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiShopStatusResponse>>(false, "微信门店状态更改异常,请检查网络连接", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 拒绝退单
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseRefundResponse>> QiMaiOrderRefuseRefund(QiMaiOrderRefuseRefundRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseRefundResponse>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
List<string> ignoreParameters = new List<string>();
|
|
|
parameters.Add("method", "qimai.order.refuserefund");
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("orderId", request.OrderId);
|
|
|
parameters.Add("reason", request.Reason);
|
|
|
ignoreParameters.Add("reason");
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignoreParameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiEntityResponse<QiMaiOrderRefuseRefundResponse>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseRefundResponse>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseRefundResponse>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseRefundResponse>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信拒绝退单异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseRefundResponse>>(false, "微信拒绝退单异常,请检查网络连接", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 订单同意退单(主动)
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>> QiMaiOrderRefund(QiMaiOrderRefundRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.order.refund");
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("orderId", request.OrderId);
|
|
|
parameters.Add("orderNo", request.OrderNo);
|
|
|
parameters.Add("amount", string.Format("{0}", request.Amount));//zhangy 2020-04-02 Edit,不再以这个字段为准,企迈:wallte_amount+amount,接口修改兼容逻辑
|
|
|
List<string> ignoreParameters = new List<string>();
|
|
|
ignoreParameters.Add("amount");
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignoreParameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信同意退单异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(false, "微信同意退单异常,请检查网络连接", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 同意退单
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>> QiMaiOrderAgreeRefund(QiMaiOrderAgreeRefundRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.order.agreerefund");
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("orderId", request.OrderId);
|
|
|
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信同意退单异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderAgreeRefundResponse>>(false, "微信同意退单异常,请检查网络连接", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 订单拒单
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseReceiveResponse>> QiMaiOrderRefuseReceive(QiMaiOrderRefuseReceiveRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseReceiveResponse>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.order.refusereceive");
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("orderId", request.OrderId);
|
|
|
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiEntityResponse<QiMaiOrderRefuseReceiveResponse>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseReceiveResponse>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseReceiveResponse>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseReceiveResponse>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信订单拒单异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderRefuseReceiveResponse>>(false, "微信订单拒单异常,请检查网络连接", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 订单接单
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderReceiveResponse>> QiMaiOrderReceive(QiMaiOrderReceiveRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderReceiveResponse>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.order.receive");
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("orderId", request.OrderId);
|
|
|
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiEntityResponse<QiMaiOrderReceiveResponse>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderReceiveResponse>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderReceiveResponse>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderReceiveResponse>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信订单接单异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrderReceiveResponse>>(false, "微信订单接单异常,请检查网络连接", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 订单信息
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public static Tuple<bool, string, QiMaiEntityResponse<QiMaiOrder>> QiMaiOrderInfo(QiMaiOrderRequest request)
|
|
|
{
|
|
|
Tuple<bool, string, QiMaiEntityResponse<QiMaiOrder>> result = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai);
|
|
|
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
|
|
|
|
|
|
parameters.Add("method", "qimai.order.query");
|
|
|
parameters.Add("storeId", request.StoreId);
|
|
|
parameters.Add("orderId", request.OrderId);
|
|
|
|
|
|
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters));
|
|
|
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
|
|
|
|
|
|
//获取成功
|
|
|
if (Constant.IsSuccessful(response))
|
|
|
{
|
|
|
var data = JsonUtils.Deserialize<QiMaiEntityResponse<QiMaiOrder>>(response);
|
|
|
if (data.Status == 1)
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrder>>(true, data.Message, data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrder>>(false, data.ErrMessage, data);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string errorMessage = PaserErrors(response);
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrder>>(false, errorMessage, null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "微信订单查询异常");
|
|
|
|
|
|
result = new Tuple<bool, string, QiMaiEntityResponse<QiMaiOrder>>(false, "微信订单查询异常,请检查网络连接", null);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
protected static string PaserErrors(string response)
|
|
|
{
|
|
|
string result = string.Empty;
|
|
|
try
|
|
|
{
|
|
|
logger.Error(response);
|
|
|
|
|
|
Errors mainError = JsonUtils.Deserialize<Errors>(response);
|
|
|
if (_errorDesc.ContainsKey(mainError.Code))
|
|
|
{
|
|
|
result = _errorDesc[mainError.Code];
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = mainError.Message;
|
|
|
}
|
|
|
|
|
|
List<SubErrors> subError = mainError.SubErrors;
|
|
|
if (subError != null && subError.Count > 0)
|
|
|
{
|
|
|
SubErrors error = subError[0];
|
|
|
if (_errorDesc.ContainsKey(error.Code))
|
|
|
{
|
|
|
result = _errorDesc[error.Code];
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = error.Message;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error(ex, "非法的错误信息格式");
|
|
|
|
|
|
result = _errorDesc["9999"];
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
}
|