Example #1
0
		public static WxPayData Refund(WxPayData inputObj, PayConfig config, int timeOut = 60)
		{
			string text = "https://api.mch.weixin.qq.com/secapi/pay/refund";
			if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id"))
			{
				WxPayLog.AppendLog(inputObj.GetParam(), "", HttpContext.Current.Request.Url.ToString(), "退款订单API接口中缺少必填参数out_trade_no 或者 transaction_id", LogType.Refund);
			}
			else if (!inputObj.IsSet("out_refund_no"))
			{
				WxPayLog.AppendLog(inputObj.GetParam(), "", HttpContext.Current.Request.Url.ToString(), "退款订单API接口中缺少必填参数out_refund_no", LogType.Refund);
			}
			else if (!inputObj.IsSet("total_fee"))
			{
				WxPayLog.AppendLog(inputObj.GetParam(), "", HttpContext.Current.Request.Url.ToString(), "退款订单API接口中缺少必填参数total_fee", LogType.Refund);
			}
			else if (!inputObj.IsSet("refund_fee"))
			{
				WxPayLog.AppendLog(inputObj.GetParam(), "", HttpContext.Current.Request.Url.ToString(), "退款订单API接口中缺少必填参数refund_fee", LogType.Refund);
			}
			else if (!inputObj.IsSet("op_user_id"))
			{
				WxPayLog.AppendLog(inputObj.GetParam(), "", HttpContext.Current.Request.Url.ToString(), "退款订单API接口中缺少必填参数op_user_id", LogType.Refund);
			}
			inputObj.SetValue("appid", config.AppId);
			inputObj.SetValue("mch_id", config.MchID);
			inputObj.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", ""));
			inputObj.SetValue("sign", inputObj.MakeSign(config.Key));
			string xml = inputObj.ToXml();
			DateTime now = DateTime.Now;
			string xml2 = HttpService.Post(xml, text, true, config, timeOut);
			DateTime now2 = DateTime.Now;
			int timeCost = (int)(now2 - now).TotalMilliseconds;
			WxPayData wxPayData = new WxPayData();
			wxPayData.FromXml(xml2, config.Key);
			WxPayApi.ReportCostTime(text, timeCost, wxPayData, config);
			return wxPayData;
		}
Example #2
0
		public static WxPayData DownloadBill(WxPayData inputObj, PayConfig config, int timeOut = 6)
		{
			string url = "https://api.mch.weixin.qq.com/pay/downloadbill";
			if (!inputObj.IsSet("bill_date"))
			{
				WxPayLog.AppendLog(inputObj.GetParam(), "", HttpContext.Current.Request.Url.ToString(), "对账单接口中,缺少必填参数bill_date", LogType.DownLoadBill);
			}
			inputObj.SetValue("appid", config.AppId);
			inputObj.SetValue("mch_id", config.MchID);
			inputObj.SetValue("nonce_str", WxPayApi.GenerateNonceStr());
			inputObj.SetValue("sign", inputObj.MakeSign(config.Key));
			string xml = inputObj.ToXml();
			string text = HttpService.Post(xml, url, false, config, timeOut);
			WxPayData wxPayData = new WxPayData();
			if (text.Substring(0, 5) == "<xml>")
			{
				wxPayData.FromXml(text, config.Key);
			}
			else
			{
				wxPayData.SetValue("result", text);
			}
			return wxPayData;
		}
Example #3
0
        public static NameValueCollection GetOpenidAndAccessTokenFromCode(string code, Page page, string appId, string appSecret, bool appendLog = false)
        {
            NameValueCollection nameValueCollection = new NameValueCollection();

            nameValueCollection.Add("OpenID", "");
            nameValueCollection.Add("Access_Token", "");
            string value  = "";
            string value2 = "";

            try
            {
                WxPayData wxPayData = new WxPayData();
                wxPayData.SetValue("appid", appId);
                wxPayData.SetValue("secret", appSecret);
                wxPayData.SetValue("code", code);
                wxPayData.SetValue("grant_type", "authorization_code");
                string   text     = "https://api.weixin.qq.com/sns/oauth2/access_token?" + wxPayData.ToUrl();
                string   json     = HttpService.Get(text, "");
                JsonData jsonData = JsonMapper.ToObject(json);
                value2 = (string)jsonData["access_token"];
                value  = (string)jsonData["openid"];
                nameValueCollection.Set("OpenID", value);
                nameValueCollection.Set("Access_Token", value2);
                if (!JsApiPay.paramDict.ContainsKey("appid"))
                {
                    JsApiPay.paramDict.Add("appid", appId);
                }
                if (!JsApiPay.paramDict.ContainsKey("secret"))
                {
                    JsApiPay.paramDict.Add("secret", appSecret);
                }
                if (!JsApiPay.paramDict.ContainsKey("code"))
                {
                    JsApiPay.paramDict.Add("code", code);
                }
                if (!JsApiPay.paramDict.ContainsKey("grant_type"))
                {
                    JsApiPay.paramDict.Add("grant_type", "authorization_code");
                }
                if (!JsApiPay.paramDict.ContainsKey("RequestUrl"))
                {
                    JsApiPay.paramDict.Add("RequestUrl", text);
                }
                if (!JsApiPay.paramDict.ContainsKey("OpenID"))
                {
                    JsApiPay.paramDict.Add("OpenID", value);
                }
                if (!JsApiPay.paramDict.ContainsKey("Access_Token"))
                {
                    JsApiPay.paramDict.Add("Access_Token", value2);
                }
                if (appendLog)
                {
                    WxPayLog.AppendLog(JsApiPay.paramDict, "", page.Request.Url.ToString(), "根据code获取OpenId和AccessToken", LogType.GetTokenOrOpenID);
                }
                return(nameValueCollection);
            }
            catch (Exception ex)
            {
                if (!JsApiPay.paramDict.ContainsKey("appid"))
                {
                    JsApiPay.paramDict.Add("appid", appId);
                }
                if (!JsApiPay.paramDict.ContainsKey("secret"))
                {
                    JsApiPay.paramDict.Add("secret", appSecret);
                }
                if (!JsApiPay.paramDict.ContainsKey("code"))
                {
                    JsApiPay.paramDict.Add("code", code);
                }
                if (!JsApiPay.paramDict.ContainsKey("grant_type"))
                {
                    JsApiPay.paramDict.Add("grant_type", "authorization_code");
                }
                if (!JsApiPay.paramDict.ContainsKey("OpenID"))
                {
                    JsApiPay.paramDict.Add("OpenID", value);
                }
                if (!JsApiPay.paramDict.ContainsKey("Access_Token"))
                {
                    JsApiPay.paramDict.Add("Access_Token", value2);
                }
                WxPayLog.AppendLog(JsApiPay.paramDict, "", page.Request.Url.ToString(), "根据code获取OpenId和AccessToken" + ex.Message, LogType.GetTokenOrOpenID);
                throw new WxPayException(ex.ToString());
            }
        }