/// <summary> /// native扫码支付 /// </summary> /// <returns></returns> public string Code3() { string postStr = @"<xml><appid><![CDATA[wx2c2f2e7b5b62daa1]]></appid> <openid><![CDATA[o8r91jjmQWUqO8zrq4rxL0QVTEYs]]></openid> <mch_id><![CDATA[1246407101]]></mch_id> <is_subscribe><![CDATA[Y]]></is_subscribe> <nonce_str><![CDATA[x20MklmXIxrD7cGE]]></nonce_str> <product_id><![CDATA[888654444]]></product_id> <sign><![CDATA[77B6BAE35570D78DE1BA99B99CD7803B]]></sign> </xml> "; System.IO.File.AppendAllText(HttpContext.Server.MapPath("") + "native.txt", postStr + ":" + DateTime.Now.ToSafeString() + "\r\n\r\n"); SortedDictionary <string, string> dic = TenpayUtil.GetInfoFromXml(postStr); string osign = dic["sign"];//微信sign string sign = TenpayUtil.getsign(dic, "43804496F28A4F0FBF1195AA0F1Abcde");//自己加密后的sign #region 取到的各种值 string appid = dic["appid"]; string openid = dic["openid"]; string mach_id = dic["mch_id"]; string is_subscribe = dic["is_subscribe"]; string nonce_str = dic["nonce_str"]; string product_id = dic["product_id"]; #endregion System.IO.File.AppendAllText(HttpContext.Server.MapPath("") + "native.txt", product_id + ":" + DateTime.Now.ToSafeString() + "\r\n\r\n"); #region 统一下单 UnifiedOrder order = new UnifiedOrder(); order.appid = "wx2c2f2e7b5b62daa1"; order.attach = "vinson1"; order.body = "微信扫码回调测试product_id:" + product_id;//订单描述 order.device_info = ""; order.mch_id = "1246407101"; order.nonce_str = TenpayUtil.getNoncestr(); //随机字符串 order.notify_url = "http://mobile.mj100.com/test/h?id=100"; //回调网址 order.openid = openid; order.out_trade_no = "20156666978542323" + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); //订单号 order.trade_type = "NATIVE"; order.spbill_create_ip = Request.UserHostAddress; order.total_fee = 1; //order.total_fee = 1; string prepay_id = tenpay.TenpayUtil.getPrepay_id(order, "43804496F28A4F0FBF1195AA0F1Abcde");//商户key #endregion System.IO.File.AppendAllText(HttpContext.Server.MapPath("") + "native.txt", prepay_id + ":" + DateTime.Now.ToSafeString() + "\r\n\r\n"); #region 响应请求 SortedDictionary <string, string> pdic = new SortedDictionary <string, string>(); pdic.Add("return_code", "SUCCESS"); pdic.Add("return_msg", ""); pdic.Add("appid", appid); pdic.Add("mch_id", mach_id); pdic.Add("nonce_str", nonce_str); pdic.Add("prepay_id", prepay_id); pdic.Add("result_code", "SUCCESS"); pdic.Add("err_code_des", ""); string nesign = TenpayUtil.getsign(pdic, "43804496F28A4F0FBF1195AA0F1Abcde"); pdic.Add("sign", nesign); StringBuilder sbPay = new StringBuilder(); foreach (KeyValuePair <string, string> k in pdic) { if (k.Key == "attach" || k.Key == "body" || k.Key == "sign") { sbPay.Append("<" + k.Key + "><![CDATA[" + k.Value + "]]></" + k.Key + ">"); } else { sbPay.Append("<" + k.Key + ">" + k.Value + "</" + k.Key + ">"); } } string return_string = string.Format("<xml>{0}</xml>", sbPay.ToString().TrimEnd(',')); #endregion System.IO.File.AppendAllText(HttpContext.Server.MapPath("") + "native.txt", return_string + ":" + DateTime.Now.ToSafeString() + "\r\n\r\n"); return(return_string); }
/// <summary> /// native第一种扫码支付 /// </summary> /// <returns></returns> public string Code2() { try { #region 获取到请求的值 Stream s = System.Web.HttpContext.Current.Request.InputStream; byte[] b = new byte[s.Length]; s.Read(b, 0, (int)s.Length); string postStr = Encoding.UTF8.GetString(b); #endregion SortedDictionary <string, string> dic = TenpayUtil.GetInfoFromXml(postStr); string osign = dic["sign"];//微信sign string sign = TenpayUtil.getsign(dic, tenpay.WeChartConfigItem.key);//自己加密后的sign #region 取到的各种值 string appid = dic["appid"]; string openid = dic["openid"]; string mach_id = dic["mch_id"]; string is_subscribe = dic["is_subscribe"]; string nonce_str = dic["nonce_str"]; string product_id = dic["product_id"];//产品id或者订单号 #endregion // System.IO.File.AppendAllText(HttpContext.Server.MapPath("") + "native.txt", product_id + ":" + DateTime.Now.ToSafeString() + "\r\n\r\n"); #region 统一下单 UnifiedOrder order = new UnifiedOrder(); order.appid = tenpay.WeChartConfigItem.appid; order.attach = "vinson1"; order.body = "微信扫码回调测试product_id:" + product_id;//订单描述 order.device_info = ""; order.mch_id = tenpay.WeChartConfigItem.mch_id; order.nonce_str = TenpayUtil.getNoncestr(); //随机字符串 order.notify_url = "http://mobile.mj100.com/test/h?id=100"; //回调网址 order.openid = openid; order.out_trade_no = "20156666978542323" + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); //订单号 order.trade_type = "NATIVE"; order.spbill_create_ip = Request.UserHostAddress; order.total_fee = 1; //order.total_fee = 1; string prepay_id = tenpay.TenpayUtil.getPrepay_id(order, tenpay.WeChartConfigItem.key);//商户key #endregion // System.IO.File.AppendAllText(HttpContext.Server.MapPath("") + "native.txt", prepay_id + ":" + DateTime.Now.ToSafeString() + "\r\n\r\n"); #region 响应请求 SortedDictionary <string, string> pdic = new SortedDictionary <string, string>(); pdic.Add("return_code", "SUCCESS"); pdic.Add("return_msg", ""); pdic.Add("appid", appid); pdic.Add("mch_id", mach_id); pdic.Add("nonce_str", nonce_str); pdic.Add("prepay_id", prepay_id); pdic.Add("result_code", "SUCCESS"); pdic.Add("err_code_des", ""); string nesign = TenpayUtil.getsign(pdic, tenpay.WeChartConfigItem.key); pdic.Add("sign", nesign); StringBuilder sbPay = new StringBuilder(); foreach (KeyValuePair <string, string> k in pdic) { if (k.Key == "attach" || k.Key == "body" || k.Key == "sign") { sbPay.Append("<" + k.Key + "><![CDATA[" + k.Value + "]]></" + k.Key + ">"); } else { sbPay.Append("<" + k.Key + ">" + k.Value + "</" + k.Key + ">"); } } string return_string = string.Format("<xml>{0}</xml>", sbPay.ToString().TrimEnd(',')); #endregion return(return_string); } catch (Exception e) { System.IO.File.AppendAllText(HttpContext.Server.MapPath("") + "native.txt", e.Message + ":" + DateTime.Now.ToSafeString() + "\r\n\r\n"); return(""); } }