Exemple #1
0
        const string DKey        = "2c91808d70b2e6610170b2e6619c0000";              // 开发者key

        /// <summary>
        /// 调用品茗OpenAPI接口。
        /// </summary>
        /// <param name="serverAlias">接口别名。</param>
        /// <param name="sItype">接口编号。</param>
        /// <param name="objectData">业务数据。</param>
        /// <returns></returns>
        public static JObject CallOpenApi(string serverAlias, string sItype, object objectData)
        {
            string sTime = DateTime.Now.ToString("yyyyMMddHHmmss");
            // 转换为JSON
            string sData = JsonConvert.SerializeObject(objectData);

            // UTF-8编码
            sData = HttpUtilityEx.UrlEncode4Java(sData, Encoding.UTF8);
            // 使用AES加密(AES加密是对照品茗给的Demo修改的)
            string sEncryptData = EncryptUtils.EncryptPm(sData, Private_key);
            // MD5签名
            string sSign = EncryptUtils.Md5Encrypt(sItype + sTime + Cono + sEncryptData + Private_key);

            Hashtable pars = new Hashtable
            {
                { "itype", sItype },
                { "cono", Cono },
                { "time", sTime },
                { "data", sEncryptData },
                { "sign", sSign },
                { "etype", "1" },
                { "dtype", DType.ToString() },
                { "dkey", DKey }
            };

            return(WebServiceCaller.QueryPostWebService(ServiceUrl, serverAlias, pars, HttpUtilityEx.UrlEncode4Java));
        }
Exemple #2
0
        /// <summary>
        /// 调用接口。
        /// </summary>
        /// <param name="api">接口信息。</param>
        /// <param name="input">输入参数。</param>
        /// <returns></returns>
        public static JObject CallOpenApi(HjApi api, object input)
        {
            string timestamp = GetTimeStamp();
            string sData     = input.Serialize2JSON();
            // UTF-8编码
            //sData = HttpUtility.UrlEncode(sData, Encoding.UTF8);
            string nonce = Get6RandomNumber();
            string sign  = $"appId={ AppId }&data={ sData }&format={ api.Format }&method={ api.Method }&nonce={ nonce }&timestamp={ timestamp }&version={ api.Version }&appsecret={ Appsecret }".ToLower();

            sign = EncryptUtils.SHA256Encrypt(sign);

            Hashtable pars = new Hashtable
            {
                { "appId", AppId },
                { "data", sData },
                { "format", api.Format },
                { "method", api.Method },
                { "nonce", nonce },
                { "sign", sign },
                { "timestamp", timestamp },
                { "version", api.Version },
            };

            WebApiCaller <JObject> caller = new WebApiCaller <JObject>
            {
                Method      = RequestMethod.POST,
                ContentType = RequestContentType.URLENCODEED,
                Callback    = JObject.Parse
            };

            var result = caller.Call($"{ Host1 }/{ api.Endpoint }", null, pars);

            LogUtils4Debug.Logger.Debug(new { Api = api, Params = input, Result = result }.Serialize2JSON());

            return(result);
        }