コード例 #1
0
        private bool CheckSignature(string vid, string qid, string sign)
        {
            Dictionary <string, string> paraMap = new Dictionary <string, string>();

            if (string.IsNullOrWhiteSpace(vid))
            {
                throw new MyException("签名参数不正确");
            }
            paraMap.Add("vid", vid);

            if (string.IsNullOrWhiteSpace(qid))
            {
                throw new MyException("签名参数不正确");
            }
            paraMap.Add("qid", qid);

            if (string.IsNullOrWhiteSpace(sign))
            {
                throw new MyException("签名参数不正确");
            }
            paraMap.Add("sign", sign);

            if (SignatureServices.Signature(paraMap) == paraMap["sign"])
            {
                return(true);
            }
            return(false);
        }
コード例 #2
0
        private string GetSignature(string vid, string qid)
        {
            Dictionary <string, string> paraMap = new Dictionary <string, string>();

            paraMap.Add("vid", vid);
            paraMap.Add("qid", qid);
            paraMap.Add("key", SystemDefaultConfig.Secretkey);
            return(SignatureServices.Signature(paraMap));
        }
コード例 #3
0
        public ActionResult Index()
        {
            try
            {
                string data = Request.Params["data"];
                TxtLogServices.WriteTxtLogEx("WebApi", "data:{0}", data);
                RequestData model           = JsonHelper.GetJson <RequestData>(data);
                bool        signatureResult = SignatureServices.CheckSignature(model);
                if (!signatureResult)
                {
                    throw new InterfaceException("签名验证失败");
                }

                ReturnResult result = new ReturnResult();
                result.return_code = "SUCCESS";
                switch (model.business_code)
                {
                //扫码枪支付
                case "SMQPAY": {
                    break;
                }

                default: throw new InterfaceException("未知接口类型");
                }
                return(Content(""));
            }
            catch (InterfaceException ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WebApi", "接口调用失败", ex, LogFrom.WeiXin);
                string result = JsonHelper.GetJsonString(new ReturnResult()
                {
                    return_code = "FAIL",
                    return_msg  = ex.Message
                });
                return(Content(result));
            }
            catch (Exception ex) {
                ExceptionsServices.AddExceptionToDbAndTxt("WebApi", "接口调用失败", ex, LogFrom.WeiXin);
                string result = JsonHelper.GetJsonString(new ReturnResult()
                {
                    return_code = "FAIL",
                    return_msg  = "未知异常"
                });
                return(Content(result));
            }
        }
コード例 #4
0
        public Dictionary <string, string> CheckRequest(string id)
        {
            Dictionary <string, string> requestParams = new Dictionary <string, string>();
            var separator = new[] { '^' };//^参数分隔符
            var ids       = id.Split(separator, StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in ids)
            {
                var parame = item.Split(new[] { '=' });
                if (parame.Length < 2)
                {
                    throw new MyException("参数出现错误,请联系管理员");
                }

                requestParams.Add(parame[0], parame[1]);
            }
            if (!requestParams.ContainsKey("cid"))
            {
                throw new MyException("获取单位信息失败");
            }
            if (!requestParams.ContainsKey("sign"))
            {
                throw new MyException("获取签名失败");
            }

            BaseCompany company = CompanyServices.QueryCompanyByRecordId(requestParams["cid"]);

            if (company == null)
            {
                throw new MyException("单位信息不存在");
            }
            requestParams.Add("key", company.Secretkey);
            Response.Cookies.Add(new HttpCookie("SmartSystem_H5_CompanyID", company.CPID));
            if (requestParams.ContainsKey("mp") && !string.IsNullOrWhiteSpace(requestParams["mp"]))
            {
                Response.Cookies.Add(new HttpCookie("SmartSystem_H5_MobilePhone", requestParams["mp"]));
            }
            if (SignatureServices.Signature(requestParams) != requestParams["sign"])
            {
                throw new MyException("签名验证失败");
            }
            return(requestParams);
        }