/// <summary>
        /// 微信接口
        /// </summary>
        /// <param name="url"></param>
        /// <param name="postData"></param>
        /// <param name="requestmethod"></param>
        /// <returns></returns>
        public static string PalmWXAPI(string url, Dictionary <string, string> postData, string requestmethod)
        {
            string str           = "";
            string host_wx       = System.Configuration.ConfigurationManager.AppSettings["Call_WXApiHost"];                           //WX的API接口链接
            string api_code      = System.Configuration.ConfigurationManager.AppSettings["Call_WXApiCode"];                           //调用FAQ接口所需的Code
            string api_key       = System.Configuration.ConfigurationManager.AppSettings["Call_WXApiKey"];                            //调用FAQ接口所需的Key
            string wxappid       = System.Configuration.ConfigurationManager.AppSettings["PalmmsgBIAppID"];                           //调用FAQ接口所需的Key
            string api_timestamp = GetTimeStamp();                                                                                    //调用FAQ接口所需的时间戳
            string api_sign      = TextEncrypt.MD5Encrypt32(api_code + api_key + api_timestamp, System.Text.Encoding.UTF8).ToLower(); //调用FAQ接口所需的签名

            url = host_wx + url;
            try
            {
                postData.Add("api_code", api_code);
                postData.Add("api_timestamp", api_timestamp);
                postData.Add("api_sign", api_sign);
                //如果外面没有传wxappid进来,则使用web.config的配置中的wxappid
                if (!postData.ContainsKey("wxappid"))
                {
                    postData.Add("wxappid", wxappid);
                }
                str = HttpRequests.HttpRequestString(url, postData, requestmethod);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(str);
        }
Beispiel #2
0
        /// <summary>
        /// 检查API接口授权
        /// </summary>
        void CheckApiAuth(ref ApiResult apiresult)
        {
            string r_ApiCode   = !string.IsNullOrEmpty(Request["api_code"]) ? Request["api_code"].Trim() : "";
            string r_TimeStamp = !string.IsNullOrEmpty(Request["api_timestamp"]) ? Request["api_timestamp"].Trim() : ""; //时间戳
            string r_Sign      = !string.IsNullOrEmpty(Request["api_sign"]) ? Request["api_sign"].Trim() : "";           //API签名

            if (string.IsNullOrEmpty(r_ApiCode))
            {
                apiresult.errcode = -1;
                apiresult.errmsg  = "无ApiCode";
                return;
            }
            if (r_ApiCode.ToLower() != ApiCode.ToLower())
            {
                apiresult.errcode = -1;
                apiresult.errmsg  = "ApiCode未授权";
                return;
            }
            //判断时间戳是否在容差范围之内
            try
            {
                double timestamp = 0d;
                bool   success   = true;
                success = double.TryParse(r_TimeStamp, out timestamp);
                if (!success)
                {
                    apiresult.errcode = -1;
                    apiresult.errmsg  = "Api时间戳错误";
                    return;
                }
                DateTime now      = DateTime.Now;
                DateTime newnow   = TimestampToDatetime(timestamp);
                double   timediff = (now - newnow).TotalSeconds;
                if (timediff > ApiTimeTolerance || ApiTimeTolerance < (-ApiTimeTolerance))
                {
                    apiresult.errcode = -1;
                    apiresult.errmsg  = "Api时间戳超出范围";
                    return;
                }
            }
            catch (Exception ex)
            {
                apiresult.errcode = -1;
                apiresult.errmsg  = "Api时间戳错误";
                LogWriter.WriteLog(ex);
                return;
            }
            if (string.IsNullOrEmpty(r_Sign))
            {
                apiresult.errcode = -1;
                apiresult.errmsg  = "无Api签名";
                return;
            }
            if (r_Sign.ToLower() != TextEncrypt.MD5Encrypt32(ApiCode + ApiKey + r_TimeStamp, System.Text.Encoding.UTF8).ToLower())
            {
                apiresult.errcode = -1;
                apiresult.errmsg  = "Api签名错误";
                return;
            }
        }
        /// <summary>
        /// API调用方法
        /// </summary>
        /// <param name="url">调用地址</param>
        /// <param name="postData">参数</param>
        /// <param name="requestmethod">请求方式:POST或者GET</param>
        /// <returns>返回请求结果</returns>
        public static string PalmCoreIIS3676API(string url, Dictionary <string, string> postData, string requestmethod)
        {
            string str           = "";
            string iis_host      = System.Configuration.ConfigurationManager.AppSettings["CoreApiHostIIS3676"];                       //核心程序IIS的API接口链接
            string api_code      = System.Configuration.ConfigurationManager.AppSettings["Call_CoreApiCode"];                         //调用接口所需的Code
            string api_key       = System.Configuration.ConfigurationManager.AppSettings["Call_CoreApiKey"];                          //调用接口所需的Key
            string api_timestamp = GetTimeStamp();                                                                                    //调用接口所需的时间戳
            string api_sign      = TextEncrypt.MD5Encrypt32(api_code + api_key + api_timestamp, System.Text.Encoding.UTF8).ToLower(); //调用接口所需的签名

            url = iis_host + url;
            try
            {
                postData.Add("api_code", api_code);
                postData.Add("api_timestamp", api_timestamp);
                postData.Add("api_sign", api_sign);
                str = HttpRequests.HttpRequestString(url, postData, requestmethod);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(str);
        }