Beispiel #1
0
        /// <summary>
        /// WebHook
        /// </summary>
        /// <returns></returns>
        public ActionResultVM WebHook()
        {
            var vm = new ActionResultVM();

            try
            {
                if (Request.Method == "POST")
                {
                    using var ms = new MemoryStream();
                    Request.Body.CopyTo(ms);
                    string postStr = System.Text.Encoding.UTF8.GetString(ms.ToArray());

                    //new WebHookService(postStr);

                    vm.Data = postStr;
                    vm.Set(ARTag.success);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                FilterConfigs.WriteLog(HttpContext, ex);
            }

            return(vm);
        }
Beispiel #2
0
        /// <summary>
        /// 开发者接管
        /// </summary>
        /// <param name="signature"></param>
        /// <param name="timestamp"></param>
        /// <param name="nonce"></param>
        /// <param name="echostr"></param>
        /// <param name="encrypt_type"></param>
        /// <param name="msg_signature"></param>
        public async void WeChat(string signature, string timestamp, string nonce, string echostr, string encrypt_type, string msg_signature)
        {
            string result = string.Empty;

            //微信后台验证地址(使用Get),微信后台的“接口配置信息”的Url
            if (Request.Method.ToLower() == "get")
            {
                var Token = GlobalTo.GetValue("ApiKey:WeChatMP:Token");

                if (Netnr.WeChat.Helpers.Util.CheckSignature(signature, timestamp, nonce, Token))
                {
                    //返回随机字符串则表示验证通过
                    result = echostr;
                }
                else
                {
                    result = "参数错误!";
                }
            }
            //处理请求
            else
            {
                WeChatMessage message  = null;
                var           safeMode = encrypt_type == "aes";

                var Token          = string.Empty;
                var EncodingAESKey = string.Empty;
                var AppID          = string.Empty;

                if (safeMode)
                {
                    Token          = GlobalTo.GetValue("ApiKey:WeChatMP:Token");
                    EncodingAESKey = GlobalTo.GetValue("ApiKey:WeChatMP:EncodingAESKey");
                    AppID          = GlobalTo.GetValue("ApiKey:WeChatMP:AppID");
                }

                using (var ms = new MemoryStream())
                {
                    await Request.Body.CopyToAsync(ms);

                    var myByteArray = ms.ToArray();

                    var    decryptMsg = string.Empty;
                    string postStr    = System.Text.Encoding.UTF8.GetString(myByteArray);

                    #region 解密
                    if (safeMode)
                    {
                        var wxBizMsgCrypt = new WeChat.Helpers.Crypto.WXBizMsgCrypt(Token, EncodingAESKey, AppID);
                        var ret           = wxBizMsgCrypt.DecryptMsg(msg_signature, timestamp, nonce, postStr, ref decryptMsg);
                        //解密失败
                        if (ret != 0)
                        {
                            FilterConfigs.WriteLog(HttpContext, new Exception("微信解密失败"));
                        }
                    }
                    else
                    {
                        decryptMsg = postStr;
                    }
                    #endregion

                    message = WeChatMessage.Parse(decryptMsg);
                }
                var response = new WeChatExecutor().Execute(message);

                #region 加密
                if (safeMode)
                {
                    var wxBizMsgCrypt = new WeChat.Helpers.Crypto.WXBizMsgCrypt(Token, EncodingAESKey, AppID);
                    var ret           = wxBizMsgCrypt.EncryptMsg(response, timestamp, nonce, ref result);
                    if (ret != 0)//加密失败
                    {
                        FilterConfigs.WriteLog(HttpContext, new Exception("微信加密失败"));
                    }
                }
                else
                {
                    result = response;
                }
                #endregion
            }

            //输出
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(result);
            await Response.Body.WriteAsync(buffer, 0, buffer.Length);

            await Response.Body.FlushAsync();
        }
Beispiel #3
0
        public string NEAPI()
        {
            string cmd    = RouteData.Values["id"]?.ToString().ToLower();
            string bucket = Request.Form["bucket"].ToString();
            string result = "fail";

            var nosClient = new NosClient(AccessNOS.EndPoint, AccessNOS.AccessKeyId, AccessNOS.AccessKeySecret, new ClientConfiguration()
            {
                MaxErrorRetry     = 2,
                MaxConnections    = 200,
                ConnectionTimeout = 50000
            });

            switch (cmd)
            {
                #region 列举文件
            case "list":
                var listObjectsRequest = new ListObjectsRequest(bucket)
                {
                    MaxKeys = 1000,
                    Prefix  = Request.Form["keywords"].ToString()
                };
                try
                {
                    ObjectListing objList = nosClient.ListObjects(listObjectsRequest);
                    result = objList.ObjectSummarise.ToJson();
                }
                catch (Exception ex)
                {
                    FilterConfigs.WriteLog(HttpContext, ex);
                    result = "[]";
                }
                break;
                #endregion

                #region 存在文件
            case "exists":
                try
                {
                    string key = Request.Form["key"].ToString();
                    bool   b   = nosClient.DoesObjectExist(bucket, key);
                    result = b ? "1" : "0";
                }
                catch (Exception)
                {
                    result = "error";
                }
                break;
                #endregion

                #region  除文件
            case "del":
                try
                {
                    var keys = Request.Form["key"].ToString().Split(',').ToList();
                    if (keys.Count == 1)
                    {
                        nosClient.DeleteObject(bucket, keys[0]);
                    }
                    else if (keys.Count > 1)
                    {
                        nosClient.DeleteObjects(bucket, keys, false);
                    }
                    result = "success";
                }
                catch (Exception)
                {
                    result = "fail";
                }
                break;
                #endregion
            }

            return(result);
        }