Exemplo n.º 1
0
        //private static RestTemplate getRestTemplate(YopRequest request)
        //{
        //  if (null != request.ConnectTimeout || null != request.ReadTimeout)
        //  {
        //    int connectTimeout = null != request.ConnectTimeout ? request.ConnectTimeout.intValue() : YopConfig.ConnectTimeout;
        //    int readTimeout = null != request.ReadTimeout ? request.ReadTimeout.intValue() : YopConfig.ReadTimeout;
        //    return new YopRestTemplate(connectTimeout, readTimeout);
        //  }
        //  else
        //  {
        //    return restTemplate;
        //  }
        //}


        /// <summary>
        /// 简单校验及请求签名
        /// </summary>
        /// <param name="request"></param>
        public static void signAndEncrypt(YopRequest request)
        {
            Assert.notNull(request.getMethod(), "method must be specified");
            Assert.notNull(request.getSecretKey(), "secretKey must be specified");
            string appKey = request.getParamValue(YopConstants.APP_KEY);

            if (StringUtils.isBlank(appKey))
            {
                appKey = StringUtils.trimToNull(request
                                                .getParamValue(YopConstants.CUSTOMER_NO));
            }
            Assert.notNull(appKey, "appKey 与 customerNo 不能同时为空");
            string signValue = YopSignUtils.sign(toSimpleMap(request.getParams()),
                                                 request.getIgnoreSignParams(), request.getSecretKey(),
                                                 request.getSignAlg());

            request.addParam(YopConstants.SIGN, signValue);
            if (request.IsRest())
            {
                request.removeParam(YopConstants.METHOD);
                request.removeParam(YopConstants.VERSION);
            }

            // 签名之后再加密
            if (request.isEncrypt())
            {
                try
                {
                    encrypt(request);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }