Example #1
0
        public string GetRequestUrl(string returnUrl, string notifyUrl, string orderId, decimal totalFee, string productInfo, string openId = null)
        {
            string resultUrl = string.Empty;

            if (CUConfig == null)
            {
                CUConfig = Utility <ChinaUnionConfig> .GetConfig(WorkDirectory);
            }
            if (string.IsNullOrEmpty(CUConfig.merId))
            {
                throw new PluginException("未设置商户编码!");
            }
            if (string.IsNullOrEmpty(CUConfig.signCertpath))
            {
                throw new PluginException("未设置商户私钥证书!");
            }

            Dictionary <string, string> dictParams = new Dictionary <string, string>();

            dictParams.Add("merId", CUConfig.merId);
            dictParams.Add("version", CUConfig.version);
            dictParams.Add("encoding", CUConfig.encoding);
            dictParams.Add("signMethod", CUConfig.signMethod);
            dictParams.Add("txnType", CUConfig.txnType);
            dictParams.Add("txnSubType", CUConfig.txnSubType);
            dictParams.Add("bizType", CUConfig.bizType);
            dictParams.Add("channelType", CUConfig.channelType);
            dictParams.Add("accessType", CUConfig.accessType);
            dictParams.Add("currencyCode", CUConfig.currencyCode);
            dictParams.Add("frontUrl", returnUrl);
            dictParams.Add("backUrl", notifyUrl);
            dictParams.Add("orderId", orderId);
            dictParams.Add("txnTime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            dictParams.Add("txnAmt", ((int)(totalFee * 100)).ToString());
            string signCertpath = WorkDirectory + "\\Cert\\" + CUConfig.signCertpath;

            try
            {
                //string signCertpath = WorkDirectory + "\\Cert\\" + CUConfig.signCertpath;
                bool isSign = SignUtil.Sign(dictParams, System.Text.ASCIIEncoding.GetEncoding(CUConfig.encoding), signCertpath, CUConfig.signCertpwd);
                if (!isSign)
                {
                    throw new PluginException("签名失败!");
                }
            }
            catch (Exception ex)
            {
                throw new PluginException(ex.Message);
            }
            resultUrl = CUConfig.frontTransUrl + "?" + SignUtil.CoverDictionaryToString(dictParams);
            return(resultUrl);
        }
Example #2
0
        public string GetRequestUrl(string returnUrl, string notifyUrl, string orderId, decimal totalFee, string productInfo, string openId = null)
        {
            string empty = string.Empty;

            if (ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig == null)
            {
                ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig = Utility <ChinaUnionConfig> .GetConfig(base.WorkDirectory);
            }
            if (string.IsNullOrEmpty(ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.merId))
            {
                throw new PluginException("未设置商户编码!");
            }
            if (string.IsNullOrEmpty(ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.signCertpath))
            {
                throw new PluginException("未设置商户私钥证书!");
            }
            Dictionary <string, string> strs = new Dictionary <string, string>()
            {
                { "merId", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.merId },
                { "version", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.version },
                { "encoding", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.encoding },
                { "signMethod", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.signMethod },
                { "txnType", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.txnType },
                { "txnSubType", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.txnSubType },
                { "bizType", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.bizType },
                { "channelType", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.channelType },
                { "accessType", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.accessType },
                { "currencyCode", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.currencyCode },
                { "frontUrl", returnUrl },
                { "backUrl", notifyUrl },
                { "orderId", orderId },
                { "txnTime", DateTime.Now.ToString("yyyyMMddHHmmss") }
            };
            int num = (int)(totalFee * new decimal(100));

            strs.Add("txnAmt", num.ToString());
            string str = string.Concat(base.WorkDirectory, "\\Cert\\", ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.signCertpath);

            try
            {
                if (!SignUtil.Sign(strs, Encoding.GetEncoding(ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.encoding), str, ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.signCertpwd))
                {
                    throw new PluginException("签名失败!");
                }
            }
            catch (Exception exception)
            {
                throw new PluginException(exception.Message);
            }
            empty = string.Concat(ChemCloud.Plugin.Payment.UnionPay.UnionPay.CUConfig.frontTransUrl, "?", SignUtil.CoverDictionaryToString(strs));
            return(empty);
        }