예제 #1
0
        /// <summary>
        /// 服务商支付
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public PrePayResult serPrePay(AppOrderEntity entity)
        {
            string appid   = ConfigurationManager.AppSettings["appid"];
            string mch_id  = ConfigurationManager.AppSettings["mch_id"];
            string signKey = ConfigurationManager.AppSettings["signKey"];

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "entity:" + entity.ToJSON()
            });
            Loggers.Debug(new DebugLogInfo()
            {
                Message = "appid:" + appid + "mch_id:"
                          + mch_id + "sub_appid:" + this.channel.appid + "sub_mch_id:" + this.channel.mch_id
            });
            this.prePayParameters = new Dictionary <string, string>();
            this.prePayParameters.Add("appid", appid);
            this.prePayParameters.Add("mch_id", mch_id);
            this.prePayParameters.Add("sub_appid", this.channel.appid);   //子商户公众账号ID
            this.prePayParameters.Add("sub_mch_id", this.channel.mch_id); //子商户号
            this.prePayParameters.Add("nonce_str", Guid.NewGuid().ToString("N"));
            this.prePayParameters.Add("body", entity.AppOrderDesc);
            this.prePayParameters.Add("out_trade_no", entity.OrderID.ToString());//在支付中心生成的订单号****
            this.prePayParameters.Add("total_fee", entity.AppOrderAmount.Value.ToString());
            this.prePayParameters.Add("spbill_create_ip", entity.ClientIP);
            this.prePayParameters.Add("notify_url", entity.NotifyUrl);
            this.prePayParameters.Add("trade_type", this.channel.trade_type);
            this.prePayParameters.Add("sub_openid", entity.OpenId);

            KeyValuePair <string, string>[] sortParameters = this.prePayParameters.OrderBy(item => item.Key).ToArray();
            List <string> paramater = new List <string>();

            foreach (KeyValuePair <string, string> item in sortParameters)
            {
                paramater.Add(string.Format("<{0}>{1}</{0}>", item.Key, item.Value));
            }
            paramater.Add(string.Format("<sign>{0}</sign>", this.getSign(this.prePayParameters, signKey)));

            //下面向微信支付发起了支付
            this.prePayResponse = WeiXinPayHelper.getResponse(entity.PayUrl, this.prePayRequest = string.Format("<xml>{0}</xml>", string.Join("", paramater.ToArray())));
            return(new XmlSerializer(typeof(PrePayResult)).Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(this.prePayResponse.Replace("xml>", "PrePayResult>")))) as PrePayResult);
        }
예제 #2
0
        /// <summary>
        /// 普通商户支付
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public PrePayResult prePay(AppOrderEntity entity)
        {
            this.prePayParameters = new Dictionary <string, string>();
            this.prePayParameters.Add("appid", this.channel.appid);
            this.prePayParameters.Add("mch_id", this.channel.mch_id);
            //this.prePayParameters.Add("device_info", "");
            this.prePayParameters.Add("nonce_str", Guid.NewGuid().ToString("N"));
            this.prePayParameters.Add("body", entity.AppOrderDesc);
            //this.prePayParameters.Add("attach", "");
            this.prePayParameters.Add("out_trade_no", entity.OrderID.ToString());//在支付中心生成的订单号****
            this.prePayParameters.Add("total_fee", entity.AppOrderAmount.Value.ToString());
            this.prePayParameters.Add("spbill_create_ip", entity.ClientIP);
            //this.prePayParameters.Add("spbill_create_ip","192.168.1.120");  //操作者ip测试 add by Henry
            //this.prePayParameters.Add("time_start", "");
            //this.prePayParameters.Add("time_expire", "");
            //this.prePayParameters.Add("goods_tag", "");
            this.prePayParameters.Add("notify_url", entity.NotifyUrl);
            this.prePayParameters.Add("trade_type", this.channel.trade_type);
            if (!string.IsNullOrEmpty(entity.OpenId))//trade_type=JSAPI,此参数必传,app是不需要填写,而如果值为空时,就不要做为键值对放到sign里***
            {
                this.prePayParameters.Add("openid", entity.OpenId);
            }
            //this.prePayParameters.Add("openid", "on9oCuAzFW9nbK8yC62LwaHnYWf0"); //openId测试 add by Henry
            //this.prePayParameters.Add("product_id", "");

            KeyValuePair <string, string>[] sortParameters = this.prePayParameters.OrderBy(item => item.Key).ToArray();
            List <string> paramater = new List <string>();

            foreach (KeyValuePair <string, string> item in sortParameters)
            {
                paramater.Add(string.Format("<{0}>{1}</{0}>", item.Key, item.Value));
            }
            paramater.Add(string.Format("<sign>{0}</sign>", this.getSign(this.prePayParameters, this.channel.signKey)));

            //下面向微信支付发起了支付
            this.prePayResponse = WeiXinPayHelper.getResponse(entity.PayUrl, this.prePayRequest = string.Format("<xml>{0}</xml>", string.Join("", paramater.ToArray())));
            return(new XmlSerializer(typeof(PrePayResult)).Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(this.prePayResponse.Replace("xml>", "PrePayResult>")))) as PrePayResult);
        }