|
@@ -0,0 +1,93 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Concurrent;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Net;
|
|
|
+using System.Text;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using JsonRpcLite.Network;
|
|
|
+using JsonRpcLite.Services;
|
|
|
+using JsonRpcLite.Utilities;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using WingInterfaceLibrary.DTO.ServerInfo;
|
|
|
+using WingInterfaceLibrary.DTO.User;
|
|
|
+using WingInterfaceLibrary.Enum;
|
|
|
+using WingInterfaceLibrary.Interface;
|
|
|
+using WingInterfaceLibrary.Request.Authentication;
|
|
|
+using WingInterfaceLibrary.Result.Device;
|
|
|
+using WingServerCommon.Config;
|
|
|
+using WingServerCommon.Config.Parameters;
|
|
|
+using WingServerCommon.Interfaces.Cache;
|
|
|
+using WingServerCommon.Log;
|
|
|
+using WingServerCommon.Service;
|
|
|
+
|
|
|
+namespace WingCloudServer.Plugin
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 支付Plugin接口
|
|
|
+ /// </summary>
|
|
|
+ public interface IPaymentPlugin : IJsonRpcHttpServerEnginePlugin
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 支付Plugin
|
|
|
+ /// </summary>
|
|
|
+ public class PaymentPlugin : JsonRpcService, IPaymentPlugin
|
|
|
+ {
|
|
|
+ private IPaymentService _paymentService;
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化
|
|
|
+ /// </summary>
|
|
|
+ public override void Load(JsonRpcClientPool jsonRpcClientPool)
|
|
|
+ {
|
|
|
+ base.Load(jsonRpcClientPool);
|
|
|
+ _paymentService = GetProxy<IPaymentService>();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 前处理
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="context">上下文/param>
|
|
|
+ /// <param name="requestData">请求参数</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public PluginProcessResult PreProcess(IJsonRpcHttpContext context, byte[] requestData)
|
|
|
+ {
|
|
|
+ var dataLength = (int)context.GetRequestContentLength();
|
|
|
+ var requests = JsonRpcCodec.DecodeRequestsAsync(requestData, new System.Threading.CancellationToken(), dataLength).Result;
|
|
|
+ var apiName = $"{context.GetRequestPath().Trim('/')}/{requests[0].Method.Trim('/')}";
|
|
|
+ if(apiName == "IPaymentService/PayNotify")
|
|
|
+ {
|
|
|
+ var contentStr = GetInputStreamValue(requestData);
|
|
|
+ _paymentService.PayCallbackAsync(contentStr);
|
|
|
+ }
|
|
|
+ return new PluginProcessResult(requestData, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 后处理
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="context">上下文/param>
|
|
|
+ /// <param name="responseData">响应参数</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public PluginProcessResult PostProcess(IJsonRpcHttpContext context, byte[] responseData)
|
|
|
+ {
|
|
|
+ return new PluginProcessResult(responseData, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get InputStreamValue
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private string GetInputStreamValue(byte[] data)
|
|
|
+ {
|
|
|
+ using(StreamReader sr = new StreamReader(new MemoryStream(data)))
|
|
|
+ {
|
|
|
+ return sr.ReadToEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|