Ejemplo n.º 1
0
 public static string unifiedorder(string appid, string mch_id, string openid, string key, string body, string notify_url,
                            string out_trade_no, int total_fee)
 {
     //string appId = this.accessToken.AppId;
     //string parameterValue = this.partnerId;
     var spbill_create_ip = "127.0.0.1";
     string noncestr = TenpayUtil.getNoncestr();
     string parameterValue2 = "JSAPI";
     RequestHandler requestHandler = new RequestHandler(Encoding.UTF8);
     requestHandler.setKey(key);
     requestHandler.setParameter("appid", appid);
     requestHandler.setParameter("body", body);
     requestHandler.setParameter("mch_id", mch_id);
     requestHandler.setParameter("nonce_str", noncestr);
     requestHandler.setParameter("notify_url", notify_url);
     requestHandler.setParameter("openid", openid);
     requestHandler.setParameter("out_trade_no", out_trade_no);
     requestHandler.setParameter("spbill_create_ip", spbill_create_ip);
     requestHandler.setParameter("total_fee", total_fee.ToString());
     requestHandler.setParameter("trade_type", parameterValue2);
     string text = requestHandler.createMd5Sign();
     string data = requestHandler.parseXML();
     string address = "https://api.mch.weixin.qq.com/pay/unifiedorder";
     string xml = new WebClient
     {
         Encoding = Encoding.UTF8
     }.UploadString(address, "post", data);
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.LoadXml(xml);
     XmlElement[] source = xmlDocument.FirstChild.ChildNodes.Cast<XmlElement>().ToArray<XmlElement>();
     string innerText = source.Single((XmlElement o) => o.Name == "return_code").InnerText;
     if (!(innerText != "SUCCESS"))
     {
         return source.Single((XmlElement o) => o.Name == "prepay_id").InnerText;
     }
     string text2 = (
         from o in source
         where o.Name == "err_code"
         select o.InnerText).SingleOrDefault<string>();
     string text3 = (
         from o in source
         where o.Name == "err_code_des"
         select o.InnerText).SingleOrDefault<string>();
     if (text2 != null && text3 != null)
     {
         throw Error.WeiXinError(text2, text3);
     }
     string msg = (
         from o in source
         where o.Name == "return_msg"
         select o.InnerText).SingleOrDefault<string>() ?? "ERROR";
     throw Error.WeiXinError(innerText, msg);
 }
Ejemplo n.º 2
0
        public Dictionary<string, object> QueryOrder(string partnerId, string partnerKey, string outTradeNO)
        {
            var str = string.Format("out_trade_no={0}&partner={1}&key={2}", outTradeNO, partnerId, partnerKey);
            var sign = MD5Encoding(str).ToUpper();
            var package = string.Format("out_trade_no={0}&partner={1}&sign={2}", outTradeNO, partnerId, sign);
            var timeStamp = DateTimeToUnixTimestamp(DateTime.Now).ToString();

            var paySignReqHandler = new RequestHandler(Utility.DefaultEncoding);
            paySignReqHandler.setParameter("appid", this.accessToken.AppId);
            paySignReqHandler.setParameter("appkey", this.appKey);
            paySignReqHandler.setParameter("package", package);
            paySignReqHandler.setParameter("timestamp", timeStamp);
            var app_signature = paySignReqHandler.createSHA1Sign();

            var values = new Dictionary<string, string>();
            values.Add("appid", this.accessToken.AppId);
            values.Add("package", package);
            values.Add("timestamp", timeStamp);
            values.Add("app_signature", app_signature);
            values.Add("sign_method", "sha1");

            var url = "https://api.weixin.qq.com/pay/orderquery?access_token=" + accessToken;
            //var serial = new System.Web.Script.Serialization.JavaScriptSerializer();

            str = Utility.Serialize(values);
            var client = new WebClient();
            client.Encoding = Utility.DefaultEncoding;
            var result = client.UploadString(url, "post", str);
            var dic = Utility.Deserialize<Dictionary<string, object>>(result);
            var code = (int)dic["errcode"];
            var msg = (string)dic["errmsg"];
            if (code != 0)
                throw Error.WeiXinError(code, msg);

            return dic;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 发货,告知微信后台该订单处于发货状态。
        /// </summary>
        /// <param name="openid">购买用户的 OpenId,已经放在最终支付结果通知的 PostData 里了。</param>
        /// <param name="transid">交易单号</param>
        /// <param name="outTradeNO">第三方订单号</param>
        public void Deliver(string openid, string transid, string outTradeNO)
        {
            var paySignReqHandler = new RequestHandler(Utility.DefaultEncoding);

            var timeStamp = DateTimeToUnixTimestamp(DateTime.Now);
            paySignReqHandler.setParameter("appid", this.accessToken.AppId);
            paySignReqHandler.setParameter("appkey", this.appKey);
            paySignReqHandler.setParameter("openid", openid);
            paySignReqHandler.setParameter("transid", transid);
            paySignReqHandler.setParameter("out_trade_no", outTradeNO);
            paySignReqHandler.setParameter("deliver_timestamp", timeStamp.ToString());
            paySignReqHandler.setParameter("deliver_status", "1");
            paySignReqHandler.setParameter("deliver_msg", "ok");
            var paySign = paySignReqHandler.createSHA1Sign();

            var url = "https://api.weixin.qq.com/pay/delivernotify?access_token=" + accessToken;
            var values = new Dictionary<string, string>();
            values.Add("appid", this.accessToken.AppId);
            values.Add("openid", openid);
            values.Add("transid", transid);
            values.Add("out_trade_no", outTradeNO);
            values.Add("deliver_timestamp", timeStamp.ToString());
            values.Add("deliver_status", "1");
            values.Add("deliver_msg", "ok");
            values.Add("app_signature", paySign);
            values.Add("sign_method", "sha1");

            var str = Utility.Serialize(values);

            var client = new WebClient();
            client.Encoding = Utility.DefaultEncoding;
            var result = client.UploadString(url, "post", str);
            var dic = Utility.Deserialize<Dictionary<string, object>>(result);
            var code = (int)dic["errcode"];
            var msg = (string)dic["errmsg"];
            if (code != 0)
                throw Error.WeiXinError(code, msg);

        }
Ejemplo n.º 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string sp_billno = Request["order_no"];
        //当前时间 yyyyMMdd
        string date = DateTime.Now.ToString("yyyyMMdd");

        if (null == sp_billno)
        {
            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
        }
        else
        {
            sp_billno = Request["order_no"].ToString();
        }

        sp_billno = TenpayUtil.partner + sp_billno;

        
        RequestHandler outParams = new RequestHandler(Context);
        
        outParams.init();
        string productid = sp_billno;
        string timeStamp = TenpayUtil.getTimestamp();
        string nonceStr = TenpayUtil.getNoncestr();

        RequestHandler Params = new RequestHandler(Context);
        Params.setParameter("appid", TenpayUtil.appid);
        Params.setParameter("appkey", TenpayUtil.appkey);
        Params.setParameter("noncestr", nonceStr);
        Params.setParameter("timestamp", timeStamp);
        Params.setParameter("productid", productid);
        string sign = Params.createSHA1Sign();
        Params.setParameter("sign",sign);


        parm = "weixin://wxpay/bizpayurl?sign=" + sign + "&appid=" + TenpayUtil.appid + "&productid=" + productid + "&timeStamp=" + timeStamp + "&nonceStr=" + nonceStr;
        parm = QRfromGoogle(parm);
      
    }
Ejemplo n.º 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string sp_billno = Request["order_no"];
        //当前时间 yyyyMMdd
        string date = DateTime.Now.ToString("yyyyMMdd");

        if (null == sp_billno)
        {
            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
        }
        else
        {
            sp_billno = Request["order_no"].ToString();
        }

        sp_billno = TenpayUtil.partner + sp_billno;



        //创建支付应答对象
        RequestHandler packageReqHandler = new RequestHandler(Context);
        //初始化
        packageReqHandler.init();


        //设置package订单参数
        packageReqHandler.setParameter("partner", TenpayUtil.partner);		  //商户号
        packageReqHandler.setParameter("fee_type", "1");                    //币种,1人民币
        packageReqHandler.setParameter("input_charset", "GBK");
        packageReqHandler.setParameter("out_trade_no", sp_billno);		//商家订单号
        packageReqHandler.setParameter("total_fee", "1");			        //商品金额,以分为单位(money * 100).ToString()
        packageReqHandler.setParameter("notify_url", TenpayUtil.tenpay_notify);		    //接收财付通通知的URL
        packageReqHandler.setParameter("body", "JSAPIdemo");	                    //商品描述
        packageReqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress);   //用户的公网ip,不是商户服务器IP

        //获取package包
        packageValue = packageReqHandler.getRequestURL();

        //调起微信支付签名
        timeStamp = TenpayUtil.getTimestamp();
        nonceStr = TenpayUtil.getNoncestr();

        //设置支付参数
        RequestHandler paySignReqHandler = new RequestHandler(Context);
        paySignReqHandler.setParameter("appid", appId);
        paySignReqHandler.setParameter("appkey", TenpayUtil.appkey);
        paySignReqHandler.setParameter("noncestr", nonceStr);
        paySignReqHandler.setParameter("timestamp", timeStamp);
        paySignReqHandler.setParameter("package", packageValue);
        paySign = paySignReqHandler.createSHA1Sign();



        //获取debug信息,建议把请求和debug信息写入日志,方便定位问题
        //string pakcageDebuginfo = packageReqHandler.getDebugInfo();
        //Response.Write("<br/>pakcageDebuginfo:" + pakcageDebuginfo + "<br/>");
        //string paySignDebuginfo = paySignReqHandler.getDebugInfo();
        //Response.Write("<br/>paySignDebuginfo:" + paySignDebuginfo + "<br/>");
      

    }
Ejemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string sp_billno = Request["order_no"];
        //当前时间 yyyyMMdd
        string date = DateTime.Now.ToString("yyyyMMdd");
        //订单号,此处用时间和随机数生成,商户根据自己调整,保证唯一
        string out_trade_no = "" + DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);

        if (null == sp_billno)
        {
            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
        }
        else
        {
            sp_billno = Request["order_no"].ToString();
        }

        sp_billno = TenpayUtil.partner + sp_billno;



        //创建RequestHandler实例
        RequestHandler packageReqHandler = new RequestHandler(Context);
        //初始化
        packageReqHandler.init();
        packageReqHandler.setKey(TenpayUtil.key);

        //设置package订单参数
        packageReqHandler.setParameter("partner", TenpayUtil.partner);		  //商户号
        packageReqHandler.setParameter("bank_type", "WX");		                      //银行类型
        packageReqHandler.setParameter("fee_type", "1");                    //币种,1人民币
        packageReqHandler.setParameter("input_charset", "GBK");
        packageReqHandler.setParameter("out_trade_no", sp_billno);		//商家订单号
        packageReqHandler.setParameter("total_fee", "1");			        //商品金额,以分为单位(money * 100).ToString()
        packageReqHandler.setParameter("notify_url", TenpayUtil.tenpay_notify);		    //接收财付通通知的URL
        packageReqHandler.setParameter("body", "nativecall");	                    //商品描述
        packageReqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress);   //用户的公网ip,不是商户服务器IP

        //获取package包
        string  packageValue = packageReqHandler.getRequestURL();

        //调起微信支付签名
        string timeStamp = TenpayUtil.getTimestamp();
        string  nonceStr = TenpayUtil.getNoncestr();

        //设置支付参数
        RequestHandler payHandler = new RequestHandler(Context);
        payHandler.setParameter("appid", TenpayUtil.appid);
        payHandler.setParameter("noncestr", nonceStr);
        payHandler.setParameter("timestamp", timeStamp);
        payHandler.setParameter("package", packageValue);
        payHandler.setParameter("RetCode","0");
        payHandler.setParameter("RetErrMsg","成功");
        string paySign = payHandler.createSHA1Sign();
        payHandler.setParameter("app_signature", paySign);
        payHandler.setParameter("sign_method","SHA1");


        Response.ContentType = "text/xml";
        Response.Clear();
        Response.Write(payHandler.parseXML());

    }