public static readonly string NOTIFY_URL_HB_Store   = "/PaySuccess.aspx"; // ConfigurationManager.AppSettings["WXPayNotify_URL_CardStore"].ToString();

        public static string Get_RequestHtml(string openid, string Bill_No, decimal Charge_Amt, string Body, string PayType, string APPID)
        {
            if (Body == "")
            {
                Body = "测试充值";
            }
            if (PayType == "")
            {
                PayType = "card_store";
            }
            HttpContext Context = System.Web.HttpContext.Current;

            if (openid.Length == 0)
            {
                return("");
            }

            //支付完成后的回调处理页面,*替换成notify_url.asp所在路径
            string TENPAY_NOTIFY = NOTIFY_URL_Card_Store;

            if (PayType == "card_user")
            {
                //用户购买支付
                TENPAY_NOTIFY = NOTIFY_URL_Card_User;
            }
            else if (PayType == "hb_store")
            {
                //店铺红包充值
                TENPAY_NOTIFY = NOTIFY_URL_HB_Store;
            }

            //设置package订单参数
            SortedDictionary <string, string> dic = new SortedDictionary <string, string>();

            string total_fee    = (Charge_Amt * 100).ToString("f0");
            string wx_timeStamp = "";
            string wx_nonceStr  = Interface_WxPay.getNoncestr();

            dic.Add("appid", APPID);
            dic.Add("mch_id", PARTNER);     //财付通帐号商家
            dic.Add("device_info", "1000"); //可为空
            dic.Add("nonce_str", wx_nonceStr);
            dic.Add("trade_type", "JSAPI");
            dic.Add("attach", "att1");
            dic.Add("openid", openid);
            dic.Add("out_trade_no", Bill_No);                             //商家订单号
            dic.Add("total_fee", total_fee);                              //商品金额,以分为单位(money * 100).ToString()
            dic.Add("notify_url", TENPAY_NOTIFY.ToLower());               //接收财付通通知的URL
            dic.Add("body", Body);                                        //商品描述
            dic.Add("spbill_create_ip", Context.Request.UserHostAddress); //用户的公网ip,不是商户服务器IP

            string get_sign = BuildRequest(dic, PARTNER_KEY);



            string url       = "https://api.mch.weixin.qq.com/pay/unifiedorder";
            string _req_data = "<xml>";

            _req_data += "<appid>" + APPID + "</appid>";
            _req_data += "<attach><![CDATA[att1]]></attach>";
            _req_data += "<body><![CDATA[" + Body + "]]></body> ";
            _req_data += "<device_info><![CDATA[1000]]></device_info> ";
            _req_data += "<mch_id><![CDATA[" + PARTNER + "]]></mch_id> ";
            _req_data += "<openid><![CDATA[" + openid + "]]></openid> ";
            _req_data += "<nonce_str><![CDATA[" + wx_nonceStr + "]]></nonce_str> ";
            _req_data += "<notify_url><![CDATA[" + TENPAY_NOTIFY.ToLower() + "]]></notify_url> ";
            _req_data += "<out_trade_no><![CDATA[" + Bill_No + "]]></out_trade_no> ";
            //_req_data += "<spbill_create_ip><![CDATA[" + Context.Request.UserHostAddress + "]]></spbill_create_ip> ";
            _req_data += "<spbill_create_ip><![CDATA[59.45.67.233]]></spbill_create_ip> ";
            _req_data += "<total_fee><![CDATA[" + total_fee + "]]></total_fee> ";
            _req_data += "<trade_type><![CDATA[JSAPI]]></trade_type> ";
            //_req_data += "<sign><![CDATA[" + get_sign + "]]></sign> ";
            _req_data += "</xml>";

            //通知支付接口,拿到prepay_id
            ReturnValue retValue = StreamReaderUtils.StreamReader(url, Encoding.UTF8.GetBytes(_req_data), System.Text.Encoding.UTF8, true);

            //设置支付参数
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.LoadXml(retValue.Message);

            XmlNode Event = xmldoc.SelectSingleNode("/xml/prepay_id");

            string return_json = "";

            if (Event != null)
            {
                string _prepay_id = Event.InnerText;

                SortedDictionary <string, string> pay_dic = new SortedDictionary <string, string>();

                wx_timeStamp = Interface_WxPay.getTimestamp();
                wx_nonceStr  = Interface_WxPay.getNoncestr();

                string _package = "prepay_id=" + _prepay_id;

                pay_dic.Add("appId", APPID);
                pay_dic.Add("timeStamp", wx_timeStamp);
                pay_dic.Add("nonceStr", wx_nonceStr);
                pay_dic.Add("package", _package);
                pay_dic.Add("signType", "MD5");

                string get_PaySign = BuildRequest(pay_dic, PARTNER_KEY);

                return_json = JsonUtils.SerializeToJson(new
                {
                    appId     = APPID,
                    timeStamp = wx_timeStamp,
                    nonceStr  = wx_nonceStr,
                    package   = _package,
                    paySign   = get_PaySign,
                    signType  = "MD5"
                });
            }
            else
            {
                return(retValue.Message);
            }

            return(return_json);
        }
Beispiel #2
0
        /// <summary>
        /// 企业付款给个人
        /// </summary>
        /// <returns></returns>
        public static string EnterprisePay(string Bill_No, string toOpenid, decimal Charge_Amt, string userName, string title)
        {
            //公众账号appid mch_appid 是 wx8888888888888888 String 微信分配的公众账号ID(企业号corpid即为此appId)
            //商户号 mchid 是 1900000109 String(32) 微信支付分配的商户号
            //设备号 device_info 否 013467007045764 String(32) 微信支付分配的终端设备号
            //随机字符串 nonce_str 是 5K8264ILTKCH16CQ2502SI8ZNMTM67VS String(32) 随机字符串,不长于32位
            //签名 sign 是 C380BEC2BFD727A4B6845133519F3AD6 String(32) 签名,详见签名算法
            //商户订单号 partner_trade_no 是 10000098201411111234567890 String 商户订单号,需保持唯一性
            //用户openid openid 是 oxTWIuGaIt6gTKsQRLau2M0yL16E String 商户appid下,某用户的openid
            //校验用户姓名选项 check_name 是 OPTION_CHECK String NO_CHECK:不校验真实姓名
            //FORCE_CHECK:强校验真实姓名(未实名认证的用户会校验失败,无法转账)
            //OPTION_CHECK:针对已实名认证的用户才校验真实姓名(未实名认证用户不校验,可以转账成功)
            //收款用户姓名 re_user_name 可选 马花花 String 收款用户真实姓名。
            // 如果check_name设置为FORCE_CHECK或OPTION_CHECK,则必填用户真实姓名
            //金额 amount 是 10099 int 企业付款金额,单位为分
            //企业付款描述信息 desc 是 理赔 String 企业付款操作说明信息。必填。
            //Ip地址 spbill_create_ip 是 192.168.0.1 String(32) 调用接口的机器Ip地址

            /*
             * <xml>
             * <mch_appid>wxe062425f740c30d8</mch_appid>
             * <mchid>10000098</mchid>
             * <nonce_str>3PG2J4ILTKCH16CQ2502SI8ZNMTM67VS</nonce_str>
             * <partner_trade_no>100000982014120919616</partner_trade_no>
             * <openid>ohO4Gt7wVPxIT1A9GjFaMYMiZY1s</openid>
             * <check_name>OPTION_CHECK</check_name>
             * <re_user_name>张三</re_user_name>
             * <amount>100</amount>
             * <desc>节日快乐!</desc>
             * <spbill_create_ip>10.2.3.10</spbill_create_ip>
             * <sign>C97BDBACF37622775366F38B629F45E3</sign>
             * </xml>
             */

            Bill_No = PARTNER + WXPay.V3Demo.Interface_WxPay.getTimestamp() + Bill_No;  //订单号组成 商户号 + 随机时间串 + 记录ID

            //设置package订单参数
            SortedDictionary <string, string> dic = new SortedDictionary <string, string>();

            string total_fee   = (Charge_Amt * 100).ToString("f0");
            string wx_nonceStr = Guid.NewGuid().ToString().Replace("-", "");    //Interface_WxPay.getNoncestr();

            dic.Add("mch_appid", APPID);
            dic.Add("mchid", PARTNER);//财付通帐号商家
            //dic.Add("device_info", "013467007045711");//可为空
            dic.Add("nonce_str", wx_nonceStr);
            dic.Add("partner_trade_no", Bill_No);
            dic.Add("openid", toOpenid);
            dic.Add("check_name", "NO_CHECK");
            dic.Add("amount", total_fee);
            dic.Add("desc", title);                         //商品描述
            dic.Add("spbill_create_ip", "211.149.234.224"); //用户的公网ip,不是商户服务器IP
            //生成签名

            string get_sign = Interface_WxPay.BuildRequest(dic, PARTNER_KEY);


            Vincent._Log.SaveMessage("第一步 get_sign:" + get_sign);

            string _req_data = "<xml>";

            _req_data += "<mch_appid>" + APPID + "</mch_appid>";
            _req_data += "<mchid>" + PARTNER + "</mchid>";
            _req_data += "<nonce_str>" + wx_nonceStr + "</nonce_str>";
            _req_data += "<partner_trade_no>" + Bill_No + "</partner_trade_no>";
            _req_data += "<openid>" + toOpenid + "</openid>";
            _req_data += "<check_name>NO_CHECK</check_name>";
            _req_data += "<amount>" + total_fee + "</amount>";
            _req_data += "<desc>" + title + "</desc>";
            _req_data += "<spbill_create_ip>211.149.234.224</spbill_create_ip>";
            _req_data += "<sign>" + get_sign + "</sign>";
            _req_data += "</xml>";

            Vincent._Log.SaveMessage("企业付款生成的xml:" + _req_data.Trim());

            var result = HttpPost(URL, _req_data.Trim(), true, 300);

            //var result = HttpPost(URL, _req_data, Encoding.UTF8);
            Vincent._Log.SaveMessage("返回结果:" + result);

            return(result);

            //ReturnValue retValue = StreamReaderUtils.StreamReader(URL, Encoding.UTF8.GetBytes(_req_data), System.Text.Encoding.UTF8, true);
            //Vincent._Log.SaveMessage("返回结果:" + retValue.ErrorCode);
            //return retValue.ErrorCode;
        }