Esempio n. 1
0
        /**
         * 生成扫描支付模式一URL
         * @param productId 商品ID
         * @return 模式一URL
         */
        public string GetPrePayUrl(string productId)
        {
            WebApiConfig.log.Info(this.GetType().ToString(), "Native pay mode 1 url is producing...");

            WxPayData data = new WxPayData();

            data.SetValue("appid", WxPayConfig.APPID);                 //公众帐号id
            data.SetValue("mch_id", WxPayConfig.MCHID);                //商户号
            data.SetValue("time_stamp", WxPayApi.GenerateTimeStamp()); //时间戳
            data.SetValue("nonce_str", WxPayApi.GenerateNonceStr());   //随机字符串
            data.SetValue("product_id", productId);                    //商品ID
            data.SetValue("sign", data.MakeSign());                    //签名
            string str = ToUrlParams(data.GetValues());                //转换为URL串
            string url = "weixin://wxpay/bizpayurl?" + str;

            WebApiConfig.log.Info(this.GetType().ToString(), "Get native pay mode 1 url : " + url);
            return(url);
        }
Esempio n. 2
0
        /**
         *
         * 查询订单
         * @param WxPayData inputObj 提交给查询订单API的参数
         * @param int timeOut 超时时间
         * @throws Exception
         * @return 成功时返回订单查询结果,其他抛异常
         */
        public static WxPayData OrderQuery(WxPayData inputObj, int timeOut = 6)
        {
            string url = "https://api.mch.weixin.qq.com/pay/orderquery";

            //检测必填参数
            if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id"))
            {
                throw new Exception("订单查询接口中,out_trade_no、transaction_id至少填一个!");
            }

            inputObj.SetValue("appid", WxPayConfig.APPID);               //公众账号ID
            inputObj.SetValue("mch_id", WxPayConfig.MCHID);              //商户号
            inputObj.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); //随机字符串
            inputObj.SetValue("sign", inputObj.MakeSign());              //签名

            string xml = inputObj.ToXml();

            var start = DateTime.Now;

            WebApiConfig.log.Debug("WxPayApi", "OrderQuery request : " + xml);
            string response = HttpService.Post(xml, url, false, timeOut);//调用HTTP通信接口提交数据

            WebApiConfig.log.Debug("WxPayApi", "OrderQuery response : " + response);

            var end      = DateTime.Now;
            int timeCost = (int)((end - start).TotalMilliseconds);//获得接口耗时

            //将xml格式的数据转化为对象以返回
            WxPayData result = new WxPayData();

            result.FromXml(response);

            ReportCostTime(url, timeCost, result);//测速上报

            return(result);
        }