public static SortedDictionary <string, object> UnifiedOrderAPP(SortedDictionary <string, object> dic, string appkey, int timeOut = 6) { dic.Add("device_info", WeiXinHelper.device_info); dic.Add("nonce_str", WeiXinHelper.GetNonce_str()); dic.Add("sign", WeiXinHelper.GetMakeSignAPP(dic, appkey)); string xml = WeiXinHelper.WxPayDataToXml(dic); string xml2 = WeiXinHelper.Post(xml, WeiXinHelper.orderurl, false, timeOut); return(WeiXinHelper.WxPayDataFromXml(xml2)); }
public static SortedDictionary <string, object> UnifiedOrder(SortedDictionary <string, object> dic, int timeOut = 6) { dic.Add("appid", WeiXinHelper.appid); dic.Add("mch_id", WeiXinHelper.mch_id); dic.Add("device_info", WeiXinHelper.device_info); dic.Add("sign", WeiXinHelper.GetMakeSign(dic)); string xml = WeiXinHelper.WxPayDataToXml(dic); string xml2 = WeiXinHelper.Post(xml, WeiXinHelper.orderurl, false, timeOut); return(WeiXinHelper.WxPayDataFromXml(xml2)); }
public static SortedDictionary <string, object> OrderQuery(SortedDictionary <string, object> dic, int timeOut = 6) { dic.Add("appid", WeiXinHelper.appid); dic.Add("mch_id", WeiXinHelper.mch_id); dic.Add("nonce_str", WeiXinHelper.GetNonce_str()); dic.Add("sign", WeiXinHelper.GetMakeSign(dic)); string xml = WeiXinHelper.WxPayDataToXml(dic); string xml2 = WeiXinHelper.Post(xml, WeiXinHelper.orderquery, false, timeOut); return(WeiXinHelper.WxPayDataFromXml(xml2)); }
public static string GetMakeSignAPP(SortedDictionary <string, object> dic, string appkey) { string text = WeiXinHelper.ToUrl(dic); text = text + "&key=" + appkey; System.Security.Cryptography.MD5 mD = System.Security.Cryptography.MD5.Create(); byte[] array = mD.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text)); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); byte[] array2 = array; for (int i = 0; i < array2.Length; i++) { byte b = array2[i]; stringBuilder.Append(b.ToString("x2")); } return(stringBuilder.ToString().ToUpper()); }
protected void Page_Load(object sender, EventArgs e) { string returnMsg = "<xml> <return_code><![CDATA[{0}]]></return_code> <return_msg><![CDATA[{1}]]></return_msg> </xml>"; SortedDictionary <string, object> dic = WeiXinHelper.GetReturnData(); string sign = dic["sign"].ToString(); if (dic["return_code"].ToString() == "SUCCESS") { string signLocal = WeiXinHelper.GetMakeSign(dic); if (sign == signLocal) { decimal amount = Convert.ToDecimal(dic["total_fee"]) / 100M; if (dic["result_code"].ToString() == "SUCCESS") { ShareDetialInfo detailInfo = new ShareDetialInfo(); detailInfo.OrderID = dic["out_trade_no"].ToString(); detailInfo.IPAddress = Utility.UserIP; detailInfo.PayAmount = amount; Message umsg = FacadeManage.aideTreasureFacade.FilliedOnline(detailInfo, 0); Response.Write(string.Format(returnMsg, "SUCCESS", "支付成功!")); } else { Response.Write(string.Format(returnMsg, "FAIL", "微信交易失败!")); } } else { Response.Write(string.Format(returnMsg, "FAIL", "签名错误!")); } } else { Response.Write(string.Format(returnMsg, "FAIL", "微信交易失败!")); } }
protected void Page_Load(object sender, System.EventArgs e) { string format = "<xml> <return_code><![CDATA[{0}]]></return_code> <return_msg><![CDATA[{1}]]></return_msg> </xml>"; SortedDictionary <string, object> returnData = WeiXinHelper.GetReturnData(); string a = returnData["sign"].ToString(); if (!(returnData["return_code"].ToString() == "SUCCESS")) { base.Response.Write(string.Format(format, "FAIL", "微信交易失败!")); } else { string makeSign = WeiXinHelper.GetMakeSign(returnData); if (!(a == makeSign)) { base.Response.Write(string.Format(format, "FAIL", "签名错误!")); } else { decimal payAmount = System.Convert.ToDecimal(returnData["total_fee"]) / 100m; if (returnData["result_code"].ToString() == "SUCCESS") { ShareDetialInfo shareDetialInfo = new ShareDetialInfo(); shareDetialInfo.OrderID = returnData["out_trade_no"].ToString(); shareDetialInfo.IPAddress = Utility.UserIP; shareDetialInfo.PayAmount = payAmount; FacadeManage.aideTreasureFacade.FilliedOnline(shareDetialInfo, 0); base.Response.Write(string.Format(format, "SUCCESS", "支付成功!")); } else { base.Response.Write(string.Format(format, "FAIL", "微信交易失败!")); } } } }
/// <summary> /// 提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void btnPay_Click(object sender, EventArgs e) { string strAccounts = CtrlHelper.GetText(txtPayAccounts); string strReAccounts = CtrlHelper.GetText(txtPayReAccounts); int amount = CtrlHelper.GetInt(txtPayAmount, 0); if (strAccounts == "") { RenderAlertInfo(true, "抱歉,请输入充值帐号。", 2); return; } if (strReAccounts != strAccounts) { RenderAlertInfo(true, "抱歉,两次输入的帐号不一致。", 2); return; } // 验证是否合法的金额 if (amount <= 0) { RenderAlertInfo(true, "请输入正确的充值金额", 2); return; } // 支付方法 string orderid = PayHelper.GetOrderIDByPrefix("WX"); OnLineOrder onlineOrder = new OnLineOrder(); onlineOrder.ShareID = 401; onlineOrder.OrderID = orderid; if (Fetch.GetUserCookie() == null) { onlineOrder.OperUserID = 0; } else { onlineOrder.OperUserID = Fetch.GetUserCookie().UserID; } onlineOrder.Accounts = strAccounts; onlineOrder.OrderAmount = amount; onlineOrder.IPAddress = GameRequest.GetUserIP(); //生成订单 Message umsg = FacadeManage.aideTreasureFacade.RequestOrder(onlineOrder); if (!umsg.Success) { RenderAlertInfo(true, umsg.Content, 2); return; } //随机字符串 string nonce_str = WeiXinHelper.GetNonce_str(); //商品描述 string body = "充值游戏豆"; //商户订单号 string out_trade_no = orderid; //交易金额(分为单位) int total_fee = Convert.ToInt32(amount * 100); //终端IP string spbill_create_ip = Utility.UserIP; //回调地址 string notify_url = "http://" + Request.Url.Authority + "/Pay/WX/WxpayNotify.aspx"; //商品ID string product_id = orderid.Substring(2, orderid.Length - 2); SortedDictionary <string, object> dic = new SortedDictionary <string, object>(); dic.Add("nonce_str", nonce_str); dic.Add("body", body); dic.Add("trade_type", "NATIVE"); dic.Add("out_trade_no", out_trade_no); dic.Add("total_fee", total_fee); dic.Add("spbill_create_ip", spbill_create_ip); dic.Add("notify_url", notify_url); dic.Add("product_id", product_id); pnlContinue.Visible = false; RenderAlertInfo(false, "页面正跳转到支付平台,请稍候。。。", 2); SortedDictionary <string, object> result = WeiXinHelper.UnifiedOrder(dic, 10); string code = result["return_code"].ToString(); StringBuilder builder = new StringBuilder(); builder.AppendLine(CreateInputHidden("return_code", code)); builder.AppendLine(CreateInputHidden("return_msg", result["return_msg"].ToString())); if (code == "SUCCESS") { builder.AppendLine(CreateInputHidden("code_url", result["code_url"].ToString())); builder.AppendLine(CreateInputHidden("orderID", orderid)); builder.AppendLine(CreateInputHidden("amount", amount.ToString())); } formData = builder.ToString(); js = "<script>window.onload = function() { document.forms[0].submit(); }</script>"; }
public void btnPay_Click(object sender, System.EventArgs e) { string text = CtrlHelper.GetText(this.txtPayAccounts); string text2 = CtrlHelper.GetText(this.txtPayReAccounts); int @int = CtrlHelper.GetInt(this.txtPayAmount, 0); if (text == "") { this.RenderAlertInfo(true, "抱歉,请输入充值帐号。", 2); } else { if (text2 != text) { this.RenderAlertInfo(true, "抱歉,两次输入的帐号不一致。", 2); } else { if (@int <= 0) { this.RenderAlertInfo(true, "请输入正确的充值金额", 2); } else { string orderIDByPrefix = PayHelper.GetOrderIDByPrefix("WX"); OnLineOrder onLineOrder = new OnLineOrder(); onLineOrder.ShareID = 401; onLineOrder.OrderID = orderIDByPrefix; if (Fetch.GetUserCookie() == null) { onLineOrder.OperUserID = 0; } else { onLineOrder.OperUserID = Fetch.GetUserCookie().UserID; } onLineOrder.Accounts = text; onLineOrder.OrderAmount = @int; onLineOrder.IPAddress = GameRequest.GetUserIP(); Message message = FacadeManage.aideTreasureFacade.RequestOrder(onLineOrder); if (!message.Success) { this.RenderAlertInfo(true, message.Content, 2); } else { string nonce_str = WeiXinHelper.GetNonce_str(); string value = "充值游戏豆"; string value2 = orderIDByPrefix; int num = System.Convert.ToInt32(@int * 100); string userIP = Utility.UserIP; string value3 = "http://" + base.Request.Url.Authority + "/Pay/WX/WxpayNotify.aspx"; string value4 = orderIDByPrefix.Substring(2, orderIDByPrefix.Length - 2); SortedDictionary <string, object> sortedDictionary = new SortedDictionary <string, object>(); sortedDictionary.Add("nonce_str", nonce_str); sortedDictionary.Add("body", value); sortedDictionary.Add("trade_type", "NATIVE"); sortedDictionary.Add("out_trade_no", value2); sortedDictionary.Add("total_fee", num); sortedDictionary.Add("spbill_create_ip", userIP); sortedDictionary.Add("notify_url", value3); sortedDictionary.Add("product_id", value4); this.pnlContinue.Visible = false; this.RenderAlertInfo(false, "页面正跳转到支付平台,请稍候。。。", 2); SortedDictionary <string, object> sortedDictionary2 = WeiXinHelper.UnifiedOrder(sortedDictionary, 10); string text3 = sortedDictionary2["return_code"].ToString(); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.AppendLine(this.CreateInputHidden("return_code", text3)); stringBuilder.AppendLine(this.CreateInputHidden("return_msg", sortedDictionary2["return_msg"].ToString())); if (text3 == "SUCCESS") { stringBuilder.AppendLine(this.CreateInputHidden("code_url", sortedDictionary2["code_url"].ToString())); stringBuilder.AppendLine(this.CreateInputHidden("orderID", orderIDByPrefix)); stringBuilder.AppendLine(this.CreateInputHidden("amount", @int.ToString())); } this.formData = stringBuilder.ToString(); this.js = "<script>window.onload = function() { document.forms[0].submit(); }</script>"; } } } } }