コード例 #1
0
        //获取package带参数的签名包
        public string getRequestURL()
        {
            this.createSign();
            StringBuilder sb    = new StringBuilder();
            ArrayList     akeys = new ArrayList(parameters.Keys);

            akeys.Sort();

            foreach (string k in akeys)
            {
                string v = (string)parameters[k];
                if (null != v && System.String.Compare("key", k, System.StringComparison.Ordinal) != 0)
                {
                    sb.Append(k + "=" + ZweixinpayUtil.UrlEncode(v, getCharset()) + "&");
                }
            }

            //去掉最后一个&
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }


            return(sb.ToString());
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderid"></param>
        /// <param name="orderAmt"></param>
        /// <param name="attach"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string GetCodeUrl(string orderid, decimal orderAmt, string attach, HttpContext context)
        {
            RequestHandler Params = new RequestHandler(context);

            Params.setKey(ZweixinpayUtil.key);

            IPAddress[] list = Dns.GetHostAddresses(Dns.GetHostName());
            Params.setParameter("mch_id", ZweixinpayUtil.partner);
            Params.setParameter("nonce_str", ZweixinpayUtil.getNoncestr());
            Params.setParameter("body", "商城储值");
            Params.setParameter("out_trade_no", orderid);
            Params.setParameter("total_fee", (orderAmt * 100).ToString("f0"));
            Params.setParameter("spbill_create_ip", "127.0.0.1");
            Params.setParameter("notify_url", NotifyURL);
            Params.setParameter("trade_type", "trade.weixin.native");

            string sign = Params.CreateSign();

            Params.setParameter("sign", sign);

            string xml = Params.parseXML();

            LogWrite("Request=>" + xml);

            try
            {
                Hashtable xmlMap;

                string url = "https://api.zwxpay.com/pay/unifiedorder";

                string retXml = ZweixinpayUtil.GetString(url
                                                         , xml
                                                         , "POST"
                                                         , Encoding.UTF8
                                                         , 5 * 1000);

                LogWrite("retXml=>" + retXml);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(retXml);

                XmlNode root = xmlDoc.SelectSingleNode("xml");
                if (root != null)
                {
                    xmlMap = new Hashtable();
                    XmlNodeList xnl = root.ChildNodes;

                    foreach (XmlNode xnf in xnl)
                    {
                        xmlMap.Add(xnf.Name, xnf.InnerText);
                    }

                    if (xmlMap["return_code"] != null &&
                        xmlMap["result_code"] != null &&
                        xmlMap["code_url"] != null)
                    {
                        if (xmlMap["return_code"].ToString() == "SUCCESS" &&
                            xmlMap["result_code"].ToString() == "SUCCESS")
                        {
                            return(xmlMap["code_url"].ToString());
                        }
                    }
                }
            }
            catch (TimeoutException timeoutEx)
            {
                return(GetCodeUrl(orderid, orderAmt, attach, context));
            }
            catch (Exception exception)
            {
                ExceptionHandler.HandleException(exception);
            }
            return(string.Empty);
        }