本篇文章主要介绍了"微信扫码支付aspnetC#实现步骤",主要涉及到aspnet方面的内容,对于.NETjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下:
支付提交页面: [HttpPost]public ActionResult index(decimal amount){//生成订单10位序列号,...
支付提交页面:

[HttpPost]
public ActionResult index(decimal amount)
{
//生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
string order_no = DateTime.Now.ToString("yyyyMMddHHmmss") + TenpayUtil.BuildRandomStr(4);
//这里是数据操作,代码已删除
ViewData["weixin_pay_qr_code"] = string.Format("/get_qrcode?product_id={0}", order_no);
return View();
}

输出二维码:

public void get_qrcode(string product_id)
{
WxPayHelper helper = new WxPayHelper();
Dictionary dic = new Dictionary();
dic.Add("appid", config_util.mp_weixin_appid);
dic.Add("mch_id", config_util.weixin_mch_id);
dic.Add("nonce_str", TenpayUtil.getNoncestr());
dic.Add("product_id", product_id);
dic.Add("time_stamp", TenpayUtil.getTimestamp());
dic.Add("sign", helper.GetSign(dic));
string url = WxPayHelper.FormatBizQueryParaMap(dic, false);//这里不要url编码
string code = "weixin://wxpay/bizpayurl?" + url;
var qrc = Create_ImgCode(code, 6);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
qrc.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] bytes = ms.GetBuffer(); //byte[] bytes= ms.ToArray(); 这两句都可以,至于区别么,下面有解释
ms.Close();
Response.BinaryWrite(bytes);
return;
}

原生拉取微信支付代码:

public ContentResult index()
{
if (Request.RequestType == "POST")
{
try
{
WxPayHelper helper = new WxPayHelper();
StreamReader reader = new StreamReader(Request.InputStream);
String xmlData = reader.ReadToEnd();
helper.ReceivePostXmlData(xmlData);
common_util.WriteLog("接收post来的xmlData=" + xmlData);
if (helper.CheckSign())
{
common_util.WriteLog("签名验证通过");
string product_id = helper.GetProductId();
common_util.WriteLog("产品id=" + product_id);
string order_no = product_id;if (产品ID存在)
{
#region 业务处理
helper.SetParameter("body", "用户充值,用户号:" + item.user_id);
helper.SetParameter("out_trade_no", order_no);
helper.SetParameter("total_fee", (item.amount * 100).ToString("#"));//这里单位是分
helper.SetParameter("notify_url", "http//www.openweixin.com.cn/notify");
helper.SetParameter("trade_type", "NATIVE");
string prepay_id = helper.GetPrepayId();
common_util.WriteLog("prepay_id=" + prepay_id);
if (!string.IsNullOrEmpty(prepay_id))
{
helper.SetReturnParameter("return_code", "SUCCESS");
helper.SetReturnParameter("result_code", "SUCCESS");
helper.SetReturnParameter("prepay_id", prepay_id);
helper.SetReturnParameter("appid", helper.GetAppId);
helper.SetReturnParameter("mch_id", helper.GetMch_Id);
helper.SetReturnParameter("nonce_str", TenpayUtil.getNoncestr());
}
else
{
helper.SetReturnParameter("return_code", "SUCCESS");//返回状态码
helper.SetReturnParameter("result_code", "FAIL");//业务结果
helper.SetReturnParameter("err_code_des", "预订单生产失败");
}
#endregion
}
else
{
helper.SetReturnParameter("return_code", "SUCCESS");//返回状态码
helper.SetReturnParameter("result_code", "FAIL");//业务结果
helper.SetReturnParameter("err_code_des", "此商品无效");//业务结果
}
}
else
{
helper.SetReturnParameter("return_code", "FAIL");
helper.SetReturnParameter("return_msg", "签名失败");
common_util.WriteLog("签名验证没有通过");
}
string xmlStr = helper.GetReturnXml();
common_util.WriteLog("返回xml=" + xmlStr);
Response.ContentType = "text/xml";
Response.Clear();
Response.Write(xmlStr);
Response.End();
}
catch (Exception ex)
{
common_util.WriteLog("异常了" + ex);
}
}
return Content("OK");
}

支付成功通知页面:
