protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //获取收货地址js函数入口参数 openid = jsApiPay.openid; HttpContext.Current.Response.Cookies.Add(new HttpCookie("openid", openid) { HttpOnly = true }); using (var db = new DBConnection()) { //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "您的id为" + HttpContext.Current.Request.Cookies["userid"].Value + ",微信标识为:" + openid + "</span>"); DataTable dt = db.GetEmptyDataTable("tb_b_user"); DataTableTracker dtt = new DataTableTracker(dt); DataRow dr = dt.NewRow(); dr["UserID"] = HttpContext.Current.Request.Cookies["userid"].Value; dr["OpenID"] = openid; dt.Rows.Add(dr); db.UpdateTable(dt, dtt); } //new Handler().SendWeText(HttpContext.Current.Request.Cookies["openid"].Value, "欢迎登陆"); } catch (Exception ex) { //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex + "</span>"); } } }
protected void Page_Load(object sender, EventArgs e) { LogHelper.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //获取收货地址js函数入口参数 wxEditAddrParam = jsApiPay.GetEditAddressParameters(); ViewState["openid"] = jsApiPay.openid; } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>"); Button1.Visible = false; Button2.Visible = false; Label1.Visible = false; Label2.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //jsApiPay.openid = openid; //JSAPI支付预处理 try { int orderID = RequestHelper.GetQueryString <int>("OrderID"); OrderInfo order = OrderBLL.ReadOrder(orderID, Cookies.User.GetUserID(true)); jsApiPay.out_trade_no = order.OrderNumber; jsApiPay.body = "订单号:" + order.OrderNumber; jsApiPay.total_fee = (int)(order.ProductMoney * 100); //(order.ProductMoney - order.FavorableMoney + order.ShippingMoney + order.OtherMoney - order.Balance - order.CouponMoney).ToString(); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 Response.Write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"2\" align=\"center\">订单详情</td></tr><tr><td width=\"40%\" align=\"right\">订单号:</td><td width=\"60%\" align=\"left\">" + order.OrderNumber + "</td></tr><tr><td align=\"right\">总金额:</td><td align=\"left\">" + order.ProductMoney + "元</td></tr><tr><td colspan=\"2\" align=\"center\"><div onclick=\"callpay()\" style=\"width:210px; height:50px; text-align:center; line-height:50px; border-radius: 15px;background-color:#00CD00; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px; cursor:pointer;\" >立即支付</div></td></tr></table>"); } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); //submit.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { this.out_trade_no.Value = Request.QueryString["out_trade_no"] == null ? "" : Request.QueryString["out_trade_no"]; //本地订单号 Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //获取收货地址js函数入口参数 //wxEditAddrParam = jsApiPay.GetEditAddressParameters(); ViewState["openid"] = jsApiPay.openid; } catch (Exception ex) { //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>"); Button1.Visible = false; Label1.Visible = false; } if (ViewState["openid"] != null && ViewState["openid"].ToString() != "") { //根据订单号获取订单金额 int total_fee = (int)(GetMoeny(this.out_trade_no.Value) * 100); //total_fee=1; this.pay_url = "http://www.yiqixkj.com/PayInterface/WXPpay/JsApiPayPage.aspx?openid=" + ViewState["openid"].ToString() + "&out_trade_no=" + this.out_trade_no.Value + "&total_fee=" + total_fee; } } }
public IActionResult GetOpenID(string redirectUrl, string code = null, string employeeid = null) { var jsApiPay = new JsApiPay(); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token var url = jsApiPay.GetOpenidAndAccessToken($@"{_setting.DomainName}/getopenid/{employeeid}?redirectUrl=" + redirectUrl, code); if (string.IsNullOrEmpty(url)) { if (employeeid == "employee") { return(Redirect($"/login?openID={jsApiPay.openid}")); } return(Redirect($"/wxpay?openid={jsApiPay.openid}&employeeid={employeeid}")); } else { return(Redirect(url)); } } catch (Exception exc) { return(NotFound()); } }
/// <summary> /// 进行微信授权验证,获取Openid /// </summary> /// <param name="UrlCode">URL参数</param> /// <param name="UrlHost">URL服务地址</param> /// <param name="UrlPath">URL路径</param> /// <returns></returns> public static string GetOpenidAndAccessToken(string UrlCode, string Url) { string str = ""; JsApiPay jsApiPay = new JsApiPay(); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(UrlCode, Url); if (string.IsNullOrEmpty(UrlCode)) { //如果UrlCode为空,则获取重定向URL str = jsApiPay.url1; } else { //如果UrlCode不为空,则解析Code,获取Openid //用户统一下单接口 str = jsApiPay.openid; str += "," + jsApiPay.access_token; } } catch (Exception ex) { } return(str); }
/// <summary> /// 返回当前微信客户端的OpenId,每个客户端在每个公众号里的OpenId是唯一的 /// </summary> /// <returns></returns> public static string GetOpenId() { JsApiPay jsApiPay = new JsApiPay(System.Web.HttpContext.Current); jsApiPay.GetOpenidAndAccessToken(); Log.Debug("GetOpenId", "openid : " + jsApiPay.openid); return(jsApiPay.openid); }
protected void Page_Load(object sender, EventArgs e) { string text = base.Request.QueryString.Get("orderId"); if (!string.IsNullOrEmpty(text)) { InpourRequestInfo inpourBlance = MemberProcessor.GetInpourBlance(text); if (inpourBlance != null) { SiteSettings masterSettings = SettingsManager.GetMasterSettings(); PackageInfo packageInfo = new PackageInfo(); packageInfo.Body = inpourBlance.InpourId; packageInfo.NotifyUrl = Globals.GetProtocal(HttpContext.Current) + "://" + $"{base.Request.Url.Host}/pay/WeiXinInpourNotify"; packageInfo.OutTradeNo = inpourBlance.InpourId; packageInfo.TotalFee = (int)(inpourBlance.InpourBlance * 100m); if (packageInfo.TotalFee < decimal.One) { packageInfo.TotalFee = decimal.One; } string text2 = ""; if (string.IsNullOrEmpty(text2)) { PayConfig payConfig = new PayConfig(); payConfig.AppId = masterSettings.WeixinAppId; payConfig.Key = masterSettings.WeixinPartnerKey; payConfig.MchID = masterSettings.WeixinPartnerID; payConfig.AppSecret = masterSettings.WeixinAppSecret; JsApiPay jsApiPay = new JsApiPay(); NameValueCollection openidAndAccessToken = JsApiPay.GetOpenidAndAccessToken(this.Page, payConfig.AppId, payConfig.AppSecret, false); if (openidAndAccessToken.HasKeys()) { text2 = openidAndAccessToken["openId"]; } } if (!string.IsNullOrEmpty(masterSettings.Main_AppId) && !string.IsNullOrEmpty(masterSettings.Main_Mch_ID)) { packageInfo.sub_openid = text2; } else { packageInfo.OpenId = text2; } packageInfo.sub_mch_id = masterSettings.WeixinPartnerID; PayClient payClient = null; payClient = ((string.IsNullOrEmpty(masterSettings.Main_AppId) || string.IsNullOrEmpty(masterSettings.Main_Mch_ID)) ? new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, masterSettings.WeixinPaySignKey, "", "", "") : new PayClient(masterSettings.Main_AppId, masterSettings.WeixinAppSecret, masterSettings.Main_Mch_ID, masterSettings.WeixinPartnerKey, masterSettings.WeixinPaySignKey, masterSettings.WeixinPartnerID, masterSettings.WeixinAppId, "")); PayRequestInfo req = payClient.BuildPayRequest(packageInfo); this.pay_json = this.ConvertPayJson(req); } } }
} //H5调起JS API参数 protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { try { JsApiPay jsApiPay = new JsApiPay(this); //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //获取收货地址js函数入口参数 //wxEditAddrParam = jsApiPay.GetEditAddressParameters(); ViewState["openid"] = jsApiPay.openid; string openid = jsApiPay.openid; string total_fee = "0.01";// //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"); Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit..."); submit.Visible = false; return; } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 //JsApiPay jsApiPay = new JsApiPay(this); jsApiPay.openid = openid; jsApiPay.total_fee = int.Parse(total_fee); //JSAPI支付预处理 WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); submit.Visible = false; } } }
/// <summary> /// 从微信服务器获取OpenId /// </summary> /// <returns></returns> private string GetOpenId() { string openId = ""; JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); openId = jsApiPay.openid; } catch (Exception ex) { Log.Error(this.GetType().ToString(), "从微信获取OpenId,页面传参出错,请返回重试"); } return(openId); }
public ActionResult Open1() { string url = ""; try { string host = StringHelper.GetHost(); string path = Request.Path; string queryString = Request.Url.Query; string code = UrlParameterHelper.GetQueryString("code"); string query = ""; string state = ""; if (!string.IsNullOrEmpty(code)) { query = UrlParameterHelper.GetDecodingParams("state"); } else { state = UrlParameterHelper.UrlEncode(queryString); } JsApiPay jsApiPay = new JsApiPay(host, path, queryString); jsApiPay.GetOpenidAndAccessToken(state, out url, code); if (string.IsNullOrEmpty(url)) { string openid = jsApiPay.OpenId; if (!string.IsNullOrEmpty(openid) && !string.IsNullOrEmpty(query)) { IDictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("openid", openid); url = StringHelper.SpliceUrl(string.Concat("/user/order/paynow/index1", query), dict); } } } catch { url = "/error/notfound".GetChannelRouteUrl(RouteChannelId); } return(Redirect(url)); }
// GET: /WeChat/WeChatPay/ProductPage public ActionResult ProductPage(string total_fee = "1") { var wxEditAddrParam = ""; var openid = ""; JsApiPay jsApiPay = new JsApiPay(HttpContext); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //获取收货地址js函数入口参数 wxEditAddrParam = jsApiPay.GetEditAddressParameters(); openid = jsApiPay.openid; } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>" + ex.Message + "<hr/>" + ex.InnerException + "<hr/>" + ex.StackTrace); } return(View(ProductPage_M.Init(wxEditAddrParam, openid, total_fee))); }
public ActionResult <dynamic> GetOpenidAndAccessToken(string code = "") { JsApiPay jsApiPay = new JsApiPay(_httpContext); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token string result = jsApiPay.GetOpenidAndAccessToken(code); if (!string.IsNullOrEmpty(result)) { return(result); } return(new { jsApiPay.Openid, jsApiPay.Access_Token }); } catch (Exception ex) { return(ex.Message); } }
} //H5调起JS API参数 public string Page_Load(string id, HttpContextBase HttpContext, bool isfalse) { //LogHelper.Info("page load"); // System JsApiPay jsApiPay = new JsApiPay(HttpContext); try { //LogHelper.Error("开始获取1 orderId" + id); //LogHelper.Error("userId" + this.LoginUser.UserID); var entity = buyOrderManager.GetOrderInfoByCode(id, this.LoginUser.UserID); //LogHelper.Error("开始获取2"); string rmb_fee = Convert.ToInt32((entity.TotalAmount - (entity.Huoli / 100) - entity.Coupon) * 100).ToString(); //LogHelper.Error("rmb_fee= " + rmb_fee); //调用【网页授权获取用户信息】接口获取用户的openid和access_token //LogHelper.Error("开始获取3 id"); //LogHelper.Error("Session的openid"); if (isfalse) { //LogHelper.Error("jsApiPay获取openid"); jsApiPay.GetOpenidAndAccessToken(id, HttpContext); } //支付开始 if (HttpContext.Session["openid"] != null) { jsApiPay.openid = HttpContext.Session["openid"].ToString(); LogHelper.Error("id=" + id + "rmb_fee=" + rmb_fee); WxPayData wxPay = jsApiPay.GetUnifiedOrderResult(id, rmb_fee); } wxJsApiParam = jsApiPay.GetJsApiParameters(); return(wxJsApiParam); } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>"); } return(null); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.appid = appid; jsApiPay.appsecret = "53e3943476118a3dff21fb95848de6d7"; jsApiPay.GetOpenidAndAccessToken(); //ViewState["openid"] = jsApiPay.openid; Response.Write(jsApiPay.openid); BCWxJSAPIPayResult result = BCPay.BCPayByChannel(BCPay.PayChannel.WX_JSAPI.ToString(), 1, BCUtil.GetUUID(), "dotnet", null, null, jsApiPay.openid, null, null) as BCWxJSAPIPayResult; //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultCode + "</span><br/>"); //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultMsg + "</span><br/>"); if (result.resultCode == 0) { timeStamp = result.timestamp; noncestr = result.noncestr; package = result.package; paySign = result.paySign; signType = result.signType; } else { Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.errDetail + "</span><br/>"); } } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.appid = appid; jsApiPay.appsecret = "53e3943476118a3dff21fb95848de6d7"; jsApiPay.GetOpenidAndAccessToken(); //ViewState["openid"] = jsApiPay.openid; Response.Write(jsApiPay.openid); BCBill bill = new BCBill(BCPay.PayChannel.WX_JSAPI.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水"); bill.openId = jsApiPay.openid; try { BCBill resultBill = BCPay.BCPayByChannel(bill); timeStamp = resultBill.timestamp; noncestr = resultBill.noncestr; package = resultBill.package; paySign = resultBill.paySign; signType = resultBill.signType; } catch (Exception excption) { Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>"); } } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>"); } } }
protected void Page_Load(object sender, EventArgs e) { OrderInfo orderInfo = null; PackageInfo packageInfo = new PackageInfo(); SiteSettings masterSettings = SettingsManager.GetMasterSettings(); bool flag = this.Page.Request["IsOffline"].ToBool(); string a = this.Page.Request["from"].ToNullString().ToLower(); string text = this.Page.Request.QueryString.Get("orderId"); string empty = string.Empty; string empty2 = string.Empty; string userAgent = base.Request.UserAgent; if (userAgent.ToLower().IndexOf("micromessenger") > -1) { this.isWeiXin = true; } if (a == "appstore") { this.isOfflineOrder = "true"; if (string.IsNullOrEmpty(text)) { this.Page.Response.Write("<h2 style=\"color:red;width:100%; text-align:center;\">错误的订单号,不能进行支付!<h2>"); this.Page.Response.End(); } empty = text; decimal d = default(decimal); StoreCollectionInfo storeCollectionInfo = null; if (flag) { this.isOfflineOrder = "true"; storeCollectionInfo = StoresHelper.GetStoreCollectionInfo(text); if (storeCollectionInfo == null) { this.Page.Response.Write("<h2 style=\"color:red;width:100%; text-align:center;\">订单状态错误,不能进行支付!<h2>"); this.Page.Response.End(); } if (storeCollectionInfo.Status != 0) { this.Page.Response.Write("<h2 style=\"color:red;width:100%; text-align:center;\">订单状态错误,不能进行支付!<h2>"); this.Page.Response.End(); } d = storeCollectionInfo.PayAmount; } else { orderInfo = ShoppingProcessor.GetOrderInfo(text); if (orderInfo == null) { this.Page.Response.Write("<h2 style=\"color:red;width:100%; text-align:center;\">订单状态错误,不能进行支付!<h2>"); this.Page.Response.End(); } if (orderInfo.OrderStatus != OrderStatus.WaitBuyerPay) { this.Page.Response.Write("<h2 style=\"color:red;width:100%; text-align:center;\">订单状态错误,不能进行支付!<h2>"); this.Page.Response.End(); } this.IsServiceOrder = ((orderInfo.OrderType == OrderType.ServiceOrder) ? "true" : "false"); if (orderInfo.PreSaleId > 0) { if (!orderInfo.DepositDate.HasValue && orderInfo.OrderStatus == OrderStatus.WaitBuyerPay) { empty = orderInfo.OrderId; d = orderInfo.Deposit - orderInfo.BalanceAmount; } if (orderInfo.DepositDate.HasValue && orderInfo.OrderStatus == OrderStatus.WaitBuyerPay) { if (orderInfo.PayRandCode.ToInt(0) == 0) { int num = orderInfo.PayRandCode.ToInt(0); num = ((num >= 100) ? (num + 1) : 100); orderInfo.PayRandCode = num.ToString(); OrderHelper.UpdateOrderPaymentTypeOfAPI(orderInfo); } empty = orderInfo.PayOrderId; d = orderInfo.FinalPayment; } } else { empty = orderInfo.PayOrderId; d = orderInfo.GetTotal(true); } } packageInfo.Body = text; packageInfo.NotifyUrl = Globals.GetProtocal(HttpContext.Current) + "://" + $"{this.Page.Request.Url.Host}/pay/AppStore_wxPay"; packageInfo.OutTradeNo = empty; packageInfo.TotalFee = (int)(d * 100m); if (orderInfo != null) { packageInfo.OutTradeNo = orderInfo.PayOrderId; packageInfo.Attach = empty2; } else { packageInfo.OutTradeNo = empty; packageInfo.Attach = empty2; } if (packageInfo.TotalFee < decimal.One) { packageInfo.TotalFee = decimal.One; } } else { if (string.IsNullOrEmpty(text)) { this.Page.Response.Write("<h2 style=\"color:red;width:100%; text-align:center;\">订单状态错误,不能进行支付!<h2>"); this.Page.Response.End(); } orderInfo = OrderHelper.GetOrderInfo(text); if (orderInfo == null) { this.Page.Response.Write("<h2 style=\"color:red;width:100%; text-align:center;\">订单状态错误,不能进行支付!<h2>"); this.Page.Response.End(); } if (orderInfo.OrderStatus != OrderStatus.WaitBuyerPay) { this.Page.Response.Write("<h2 style=\"color:red;width:100%; text-align:center;\">订单状态错误,不能进行支付!<h2>"); this.Page.Response.End(); } this.IsServiceOrder = ((orderInfo.OrderType == OrderType.ServiceOrder) ? "true" : "false"); empty = text; this.isFightGroup = ((orderInfo.FightGroupId > 0) ? "true" : "false"); decimal d2 = default(decimal); if (orderInfo.PreSaleId > 0) { if (!orderInfo.DepositDate.HasValue && orderInfo.OrderStatus == OrderStatus.WaitBuyerPay) { empty = orderInfo.OrderId; d2 = ((orderInfo.Deposit - orderInfo.BalanceAmount > decimal.Zero) ? (orderInfo.Deposit - orderInfo.BalanceAmount) : decimal.Zero); } if (orderInfo.DepositDate.HasValue && orderInfo.OrderStatus == OrderStatus.WaitBuyerPay) { if (orderInfo.PayRandCode.ToInt(0) == 0) { int num2 = orderInfo.PayRandCode.ToInt(0); num2 = ((num2 >= 100) ? (num2 + 1) : 100); orderInfo.PayRandCode = num2.ToString(); OrderHelper.UpdateOrderPaymentTypeOfAPI(orderInfo); } empty = orderInfo.PayOrderId; d2 = ((orderInfo.FinalPayment > decimal.Zero) ? orderInfo.FinalPayment : decimal.Zero); } } else { empty = orderInfo.OrderId; d2 = orderInfo.GetTotal(true); } packageInfo.Body = orderInfo.OrderId + orderInfo.PayRandCode; packageInfo.NotifyUrl = Globals.GetProtocal(HttpContext.Current) + "://" + $"{this.Page.Request.Url.Host}/pay/wx_Pay"; if (orderInfo.OrderType != OrderType.ServiceOrder && orderInfo.OrderSource == OrderSource.Applet) { packageInfo.NotifyUrl = Globals.GetProtocal(HttpContext.Current) + "://" + $"{this.Page.Request.Url.Host}/pay/O2OApplet_Pay"; } packageInfo.OutTradeNo = orderInfo.PayOrderId; packageInfo.Attach = empty2; packageInfo.TotalFee = (int)(d2 * 100m); if (packageInfo.TotalFee < decimal.One) { packageInfo.TotalFee = decimal.One; } } string text2 = masterSettings.WeixinAppId; string appSecret = masterSettings.WeixinAppSecret; string text3 = masterSettings.WeixinPartnerID; string text4 = masterSettings.WeixinPartnerKey; string text5 = masterSettings.Main_Mch_ID; string text6 = masterSettings.Main_AppId; if (a != "appstore") { if (orderInfo.OrderType == OrderType.ServiceOrder && orderInfo.OrderSource != OrderSource.WeiXin) { text2 = masterSettings.O2OAppletAppId; appSecret = masterSettings.O2OAppletAppSecrect; text3 = masterSettings.O2OAppletMchId; text4 = masterSettings.O2OAppletKey; text5 = ""; text6 = ""; } else if (orderInfo.OrderSource == OrderSource.Applet) { text2 = masterSettings.WxAppletAppId; appSecret = masterSettings.WxAppletAppSecrect; text3 = masterSettings.WxApplectMchId; text4 = masterSettings.WxApplectKey; text5 = ""; text6 = ""; } } string text7 = ""; MemberInfo user = HiContext.Current.User; if (user.UserId > 0 && a != "appstore") { MemberOpenIdInfo memberOpenIdInfo = null; if (orderInfo.OrderType == OrderType.ServiceOrder && orderInfo.OrderSource != OrderSource.WeiXin) { memberOpenIdInfo = user.MemberOpenIds.FirstOrDefault((MemberOpenIdInfo item) => item.OpenIdType.ToLower() == "hishop.plugins.openid.o2owxapplet"); if (memberOpenIdInfo != null) { text7 = memberOpenIdInfo.OpenId; } } else if (orderInfo.OrderSource == OrderSource.Applet) { memberOpenIdInfo = user.MemberOpenIds.FirstOrDefault((MemberOpenIdInfo item) => item.OpenIdType.ToLower() == "hishop.plugins.openid.wxapplet"); if (memberOpenIdInfo != null) { text7 = memberOpenIdInfo.OpenId; } } else { memberOpenIdInfo = user.MemberOpenIds.FirstOrDefault((MemberOpenIdInfo item) => item.OpenIdType.ToLower() == "hishop.plugins.openid.weixin"); if (memberOpenIdInfo != null && user.IsDefaultDevice) { text7 = memberOpenIdInfo.OpenId; } } } if (string.IsNullOrEmpty(text7)) { PayConfig payConfig = new PayConfig(); payConfig.AppId = text2; payConfig.Key = text4; payConfig.MchID = text3; payConfig.AppSecret = appSecret; JsApiPay jsApiPay = new JsApiPay(); try { NameValueCollection openidAndAccessToken = JsApiPay.GetOpenidAndAccessToken(this.Page, payConfig.AppId, payConfig.AppSecret, false); if (openidAndAccessToken.HasKeys()) { text7 = openidAndAccessToken["openId"]; } } catch (Exception ex) { if (!(ex is ThreadAbortException)) { IDictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary.Add("AppId", payConfig.AppId); dictionary.Add("Key", payConfig.Key); dictionary.Add("MchID", payConfig.MchID); dictionary.Add("AppSecret", payConfig.AppSecret); dictionary.Add("Exception", ex.Message); dictionary.Add("StackTrace", ex.StackTrace); dictionary.Add("TargetSite", ex.TargetSite.ToString()); Globals.WriteLog(dictionary, "获取用户OpenId失败", "", "", "GetOpenId"); } } } if (!string.IsNullOrEmpty(text6) && !string.IsNullOrEmpty(text5)) { packageInfo.sub_openid = text7; } else { packageInfo.OpenId = text7; } PayClient payClient = null; payClient = ((string.IsNullOrEmpty(text6) || string.IsNullOrEmpty(text5)) ? new PayClient(text2, appSecret, text3, text4, "", "", "", "") : new PayClient(text6, appSecret, text5, text4, "", text3, text2, "")); PayRequestInfo req = payClient.BuildPayRequest(packageInfo); this.pay_json = this.ConvertPayJson(req); this.pay_uri = this.ConvertPayUri(req); if (!this.isWeiXin) { base.Response.Redirect(this.pay_uri); } }
/// <summary> /// 是否已经认签委托扣款 /// </summary> /// <param name="code"></param> /// <returns></returns> public JsonResult IsSign(string code, string openid, string nickname, string latitude, string longitude, string city, string mode = "0") { city = (city == null) ? "" :(city == "切换城市")?"": city; bool RNameChecked = false, needCheck = (ConfigurationManager.AppSettings["RNameNeedCheck"] == "1") ? true : false; if (string.IsNullOrEmpty(openid)) { var pay = new JsApiPay(this.Request); pay.GetOpenidAndAccessToken(city); openid = pay.openid; } var bus = new Bus(this.DataSource); var isDebt = bus.isDebt(openid, city); var isSign = (!string.IsNullOrEmpty(city)) ? bus.isSign(openid, WxPayConfig.APPID(city), city) : false; var user = bus.GetEntrustinfo(openid, WxPayConfig.APPID(city), WxPayConfig.getMCHID(city)); var hzuser = bus.GetEntrustinfo(openid, WxPayConfig.APPID(city), WxPayConfig.getMCHID("杭州市")); var wxuser = bus.GetUserInfo(openid, WxPayConfig.APPID(city)); nickname = (string.IsNullOrEmpty(nickname)) ? "" : nickname; var exdata = bus.Sign(openid, nickname, Request.UserHostAddress, city); if (user != null) { user.DataDriver = this.DataSource; if (!string.IsNullOrEmpty(nickname)) { user.FldNickname = nickname; } user.FldLatitude = latitude; if (!string.IsNullOrEmpty(city)) { user.FldCity = city.Replace("undefined", ""); } user.FldLongitude = longitude; user.Store(); } if (wxuser != null) { wxuser.DataDriver = this.DataSource; if (!string.IsNullOrEmpty(nickname)) { wxuser.Nickname = nickname; } wxuser.City = city; wxuser.Latitude = latitude; wxuser.Longitude = longitude; if (string.IsNullOrEmpty(wxuser.Mobile) && hzuser != null && !string.IsNullOrEmpty(hzuser.FldMobile)) { wxuser.Mobile = hzuser.FldMobile; } wxuser.Store(); RNameChecked = wxuser.RNameChecked == 1 ? true : false; } var wxpay = new WxPayApi(); bool bindMobile = !string.IsNullOrEmpty(wxuser.Mobile); if (!string.IsNullOrEmpty(wxuser.Mobile) && needCheck == false) { needCheck = (wxuser.Mobile.iEqualsArr(ConfigurationManager.AppSettings["RNameCheckPhones"])) ? true : false; } string[] valarray = new string[] { "乐清市" }; // new string[] { "乐清市", "杭州市" }; string[] keyarray = new string[] { "乐清城市公交乘车码" }; //new string[] { "乐清城市公交乘车码", "杭州城市公交乘车码" }; bool showcard = nickname.iEqualsArr("司令大人,XLsn0w,xiangling别") ? true : false; switch (mode) { case "1": valarray = new string[] { "乐清市", "常熟市" }; keyarray = new string[] { "乐清城市公交乘车码", "常熟城市公交乘车码" }; break; case "2": valarray = new string[] { "杭州市" }; keyarray = new string[] { "演示" }; break; case "3": valarray = new string[] { "福州市" }; keyarray = new string[] { "福州市" }; break; } return(Json(new { exdata = exdata, isSign = isSign, openid = openid, TimeStamp = WxPayApi.GenerateTimeStamp(), bindMobile = bindMobile, RNameChecked = RNameChecked, needCheck = needCheck, isDebt = isDebt, valarray = valarray, keyarray = keyarray, showcard = showcard }, JsonRequestBehavior.AllowGet)); }
protected void Page_Load(object sender, EventArgs e) { log.Info("*******************微信支付处理开始****************************"); string orderId = Request.QueryString["oid"]; string state = Request.QueryString["state"]; string openId = Request.QueryString["openid"]; if (!string.IsNullOrEmpty(state) && string.IsNullOrEmpty(orderId)) { orderId = state; } log.Info("WXPay.Send---->orderId--->" + orderId + "&&openID=" + openId + "&&state" + state); JsApiPay jsApiPay = new JsApiPay(this); if (string.IsNullOrEmpty(openId)) { jsApiPay.GetOpenidAndAccessToken(orderId); openId = jsApiPay.openid; log.Info("WXPay.Send 获得---->openid:" + openId); if (string.IsNullOrEmpty(openId)) { log.Info("依然没有得到openid"); return; } else { log.Info("即将刷新送出openID和Oid"); Response.Redirect("/pay/weixin/send.aspx?oid=" + orderId + "&&openid=" + openId); } } else { //付款金额,必填 decimal total_fee = 0; if (!string.IsNullOrEmpty(orderId)) { log.Info("订单号:" + orderId); try { OrderDetail orderDetail = obll.OrderDetail(orderId); OrderDetailPay od = new OrderDetailPay(); od.OrderDetailsPayInit(orderId, orderDetail); total_fee = od.Price * 100; //JSAPI支付预处理 // jsApiPay.total_fee = Convert.ToInt32(total_fee); string body = orderDetail.opList[0].ProductName + "x" + orderDetail.opList[0].Num; WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(body, orderId, Convert.ToInt32(total_fee), openId); packString = jsApiPay.GetJsApiParameters(); //获取H5调起JS API参数 log.Info("WXPay.Send---->wxJsApiParam : " + packString); /** * Wxpay.WxPayHelper wxPayHelper = new Wxpay.WxPayHelper(); * //先设置基本信息 * wxPayHelper.SetAppId(_APPID); * wxPayHelper.SetAppKey(_APPSECRET); * wxPayHelper.SetPartnerKey(_KEY); * wxPayHelper.SetSignType("SHA1"); * * //设置请求package信息 * wxPayHelper.SetParameter("bank_type", "WX"); * wxPayHelper.SetParameter("body", orderDetail.opList[0].ProductName + "x" + orderDetail.opList[0].Num); * log.Info("body:" + orderDetail.opList[0].ProductName + "x" + orderDetail.opList[0].Num); * wxPayHelper.SetParameter("partner", _MCHID); * wxPayHelper.SetParameter("out_trade_no", orderId.ToString()); * wxPayHelper.SetParameter("total_fee", total_fee.ToString()); * log.Info("total_fee:" + total_fee); * wxPayHelper.SetParameter("fee_type", "1"); * wxPayHelper.SetParameter("notify_url", ConfigurationManager.AppSettings["notifyUrl"]); * wxPayHelper.SetParameter("spbill_create_ip", Request.UserHostAddress); * wxPayHelper.SetParameter("input_charset", "UTF-8"); * packString = wxPayHelper.CreateBizPackage();****/ } catch (Exception ex) { log.Info(ex.Message + ex.StackTrace); } } else { log.Info("xxxOrderID 为空xxx"); } } log.Info("*******************微信支付处理结束****************************"); }