微信登录
<script src="https://res./connect/zh_CN/htmledition/js/wxLogin.js"></script>// 第三方登录-微信$("#wechatAppBtn").click(function () {var obj = new WxLogin({id: "wxCode",//div的idappid: "wxc4304e69d9430781",//后台申请的appidscope: "snsapi_login",//写死redirect_uri: encodeURI("/webnew/login_wx.aspx"),//扫描二维码后跳转的页面state: "",style: "black",//二维码黑白风格href: ""});$(".maskCon").show();});<div style="width: 80%;margin: 0 auto;"><div id="wechatAppBtn" style="width: 40px;margin: 0 auto;cursor:pointer;"><img src="../images/icon_wechatApp.png" style="width: 100%;vertical-align: middle;"/></div>
protected void Page_Load(object sender, EventArgs e){string code = Request.QueryString["code"];if (code == null) { code = ""; }if (string.IsNullOrEmpty(code)){Response.Write("<script language='javascript'>");Response.Write("alert('code不能为空!');");Response.Write("history.back();");Response.Write("</script>");}string APPID = "wxc4304e69dwangjp";string SECRET = "wangjpwangjpwangjp";string strUrl = "https://api./sns/oauth2/access_token?appid=" + APPID + "&secret=" + SECRET + "&code=" + code + "&grant_type=authorization_code";string content = yzin.GetPage(strUrl);JObject obj = JObject.Parse(content);string openid = obj["openid"].ToString();if (string.IsNullOrEmpty(openid)){Response.Redirect("login.aspx");return;}Response.Cookies["openid_wx"].Value = openid;// 第三方app返回的idResponse.Cookies["openid_type"].Value = "0";// 第三方类型 0:微信// TODO 根据openid查询}
微信支付
// 支付$("#Button1").click(function () {payType = $("input[type='radio']:checked").val();console.log("[payType]"+payType);$("#payListCon").hide();if(payType == "0"){// 线下付款$("#xxzfCon").show();}else{ //支付宝、微信、paypalapi("pcpay", {"equipmentType": "PC", "lang": localStorage.getItem("lang"), "ubh": localStorage.getItem("ubh"), "order_id": orderid,"pay_type":payType}, function () {loading({ Des: "加载中" });}, function (data) { window.location.href = data.detail.url + '?' + data.detail.key;loading({ Des: "" });}, function (error) {//noneBtnOMsg({ Des: error.responseJSON.Message });loading({ Des: "" });});}});
public class pcpayController : ApiController{public IEnumerable<string> Get(){return new string[] { "value1", "value2" };}[HttpPost][CustomActionFilter]//[CustomExcepFilter]// POST api/<controller>public ApiResult Post(ApiRequest body){List<NotEmpty> temp = new List<NotEmpty>(){new NotEmpty(){ value = body.order_id,err = "order_id参数不能为空"},new NotEmpty(){ value = body.pay_type,err = "pay_type参数不能为空"}};yzin.isEmpty(temp);string lang = yzin.getStr(body.lang);string equipmentType = yzin.getStr(body.equipmentType);string order_id = yzin.getStr(body.order_id);string pay_type = yzin.getStr(body.pay_type);Hashtable jg = new Hashtable();connection con = new connection();DataTable dt1 = new DataTable();dt1 = con.ExeSql("select fid,bh,money from orders where id=" + order_id + " and zt=1 and del=0");if (dt1.Rows.Count <= 0){throw new Exception("该订单不存在");}string url = "", key = "order_id=" + order_id + "&lang=" + lang;if (pay_type == "1"){url = "/alipay.aspx";//支付宝}else if (pay_type == "2"){url = "/wechatPay.aspx";//微信}else if (pay_type == "3"){url = "/paypalpay.aspx";//paypal}jg.Add("url", url);//支付域名urljg.Add("key", key);//支付字串return ApiResult.ret((int)ApiResult.enum_result.success, string.Empty, yzin.toJsonObj(jg));}}
public partial class wechatPay : System.Web.UI.Page{connection con = new connection();DataTable dt1;DataTable dt2;public string senddata = "";ProjectLog log = new ProjectLog();protected void Page_Load(object sender, EventArgs e){try{string order_id = Request.QueryString["order_id"];//订单idstring lang = Request.QueryString["lang"];//订单语言string udevlx = "PC";//手机类型android/iosif (order_id != ""){dt1 = con.ExeSql("select fid,bh,money from orders where id=" + order_id + " and money>0 and zt=1 and del=0");if (dt1.Rows.Count > 0){string paymc = "", paybh = dt1.Rows[0]["bh"].ToString(), payjg = (Convert.ToDouble(dt1.Rows[0]["money"].ToString()) * 100).ToString();dt2 = con.ExeSql("select exhibitions.mc,exhibitions.emc,pavilion.mc as pavilion,booth.mc as booth,booth.jg,booth.mj,booth.kk from booth inner join pavilion on pavilion.id=booth.pavid inner join exhibitions on exhibitions.id=pavilion.exhiid and booth.id=" + dt1.Rows[0]["fid"].ToString());if (dt2.Rows.Count > 0){paymc += translate.content(lang, dt2.Rows[0]["mc"].ToString(), dt2.Rows[0]["emc"].ToString());paymc += " " + dt2.Rows[0]["pavilion"].ToString();paymc += " " + dt2.Rows[0]["booth"].ToString();if (udevlx.ToLower() == "android" || udevlx.ToLower() == "ios"){//senddata = WeChat_Pay.Pay_APP(paybh, paymc, payjg, udevlx);}else if (udevlx.ToLower() == "pc"){senddata = WeChat_Pay.Pay_PC(paybh, paymc, payjg, udevlx);string addr1 = "upload/ewm/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";string addr2 = Server.MapPath("upload/ewm/") + DateTime.Now.ToString("yyyy-MM-dd") + "\\";if (!Directory.Exists(addr2)) { Directory.CreateDirectory(addr2); }string ewm0 = DateTime.Now.ToString("yyyyMMddHHmmssfff") + yzin.tu_rnd() + "_1.png";string ewm = DateTime.Now.ToString("yyyyMMddHHmmssfff") + yzin.tu_rnd() + ".png";string nr1 = senddata;//二维码内容QRCodeEncoder qrCodeEncoder1 = new QRCodeEncoder();qrCodeEncoder1.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;qrCodeEncoder1.QRCodeScale = 16;qrCodeEncoder1.QRCodeVersion = 0;qrCodeEncoder1.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;Bitmap image1 = qrCodeEncoder1.Encode(nr1);MemoryStream MStream1 = new MemoryStream();image1.Save(MStream1, System.Drawing.Imaging.ImageFormat.Png);FileStream fs1 = new FileStream(addr2 + ewm0, FileMode.CreateNew, FileAccess.ReadWrite);BinaryWriter bw1 = new BinaryWriter(fs1, UTF8Encoding.UTF8);byte[] by1 = MStream1.ToArray();for (int i = 0; i < MStream1.ToArray().Length; i++){bw1.Write(by1[i]);}fs1.Close();//二维码文件添加水印后保存完成BuildWatermark(addr2 + ewm0, Server.MapPath("images/wechat.png"), addr2 + ewm, 5);//5正中央if (File.Exists(addr2 + ewm0)){File.Delete(addr2 + ewm0);}con.ExeSql("update orders set wechatpay_ewm='" + addr1 + ewm + "' where id=" + order_id);Response.Redirect("web/wechat_paying.aspx?paybh=" + paybh + "&lang=" + lang);}else if (udevlx.ToLower() == "wechat"){//senddata = WeChat_Pay.Pay_WX(paybh, paymc, payjg, udevlx);//Response.Redirect("wx/wx_pay.aspx?data=" + senddata);}}}}}catch (Exception ex){Response.Write(ex.Message);}}public void BuildWatermark(string rSrcImgPath, string rMarkImgPath, string rDstImgPath, int location){//进行水印添加处理--------------------------------------------//加载文件Image Cover = Image.FromFile(rSrcImgPath);//加载水印文件//string shuiyin = "images/watermark.png";//System.Drawing.Image water = System.Drawing.Image.FromFile(Request.MapPath(rMarkImgPath));Image water = Image.FromFile(rMarkImgPath);//创建画布Graphics g = Graphics.FromImage(Cover);if (location == 1)//左上方{//在image上绘制水印g.DrawImage(water, new Rectangle(0, 0, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel);}else if (location == 2)//左下方{//在image上绘制水印g.DrawImage(water, new Rectangle(0, Cover.Height - water.Height, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel);}else if (location == 3)//右上方{//在image上绘制水印g.DrawImage(water, new Rectangle(Cover.Width - water.Width, 0, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel);}else if (location == 4)//右下方{//在image上绘制水印g.DrawImage(water, new Rectangle(Cover.Width - water.Width, Cover.Height - water.Height, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel);}else if (location == 5)//正中间{//在image上绘制水印g.DrawImage(water, new Rectangle((Cover.Width - water.Width) / 2, (Cover.Height - water.Height) / 2, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel);}else{//在image上绘制水印g.DrawImage(water, new Rectangle(Cover.Width - water.Width, Cover.Height - water.Height, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel);}//释放画布g.Dispose();//释放水印图片water.Dispose();Cover.Save(rDstImgPath);//保存打过水印的图片Cover.Dispose();}}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="wechat_paying.aspx.cs" Inherits="schenk_booth_web.web.wechat_paying" %><!DOCTYPE html><html xmlns="/1999/xhtml"><head runat="server"><script src="../js/i18n.js" type="text/javascript"></script><meta charset="utf-8" /><meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /><meta http-equiv="Pragma" content="no-cache" /><meta http-equiv="Expires" content="0" /><title></title><link href="../css/global.css" type="text/css" rel="stylesheet" /><style>.curbody {background: url('../images/bg1.png') no-repeat;background-size: 100% auto;background-position: center bottom;background-attachment: fixed;}</style></head><body class="curbody"><form id="form1" runat="server"><div id="top" class="top"><!-- <iframe width="100%" style="height: 60px;" src="top.html" frameborder="no" border="0" marginwidth="0"marginheight="0" scrolling="no"></iframe> --></div><div style="margin: 30px auto; width: 1200px;"><div style="width: 600px; border-radius: 10px; background: #ffffff; padding: 30px 0; margin-top: 100px;" class="auto tc"><p style="font-size: 16px; padding: 20px 0px 0px 0px;"><%=pay_mc %></p><p style="font-size: 18px; color: #DE2520; padding: 20px 0; font-weight: bold;"><%=pay_jg %></p><p><%=pay_ewm %></p></div></div><div style="height: 20px; clear: both;"> </div><div id="footer"></div><script src="../js/jquery-3.1.0.min.js" type="text/javascript"></script><script src="../js/jquery-loading.js" type="text/javascript"></script><script src="../js/jquery-mask.js" type="text/javascript"></script><script src="../js/global.js" type="text/javascript"></script><script type="text/javascript">var paybh = getQueryVariable("paybh");var pay_type = getQueryVariable("paytype");// var payzt = "0";$(function () {// 加载头部和底部$("#top").load("top.html");$("#footer").load("footer.html");$("body").css("height", parseInt($(window).height()) - 100);setInterval(function () {// if (payzt == "0") {pay_zt();// }}, 3000);});function pay_zt() {$.ajax({type: "POST",url: "/api/api/pay_zt",contentType: "application/json;charset=utf-8",dataType: "json",data: JSON.stringify({ 'paybh': paybh }),success: function (data) {if (data.code == "100") {if (data.detail.zt == "1") {location.href = 'myOrder.html?type=0';}}}});}</script></form></body></html>
public partial class wechat_paying : System.Web.UI.Page{connection con = new connection();DataTable dt1;DataTable dt2;public string pay_mc = "";public string pay_jg = "";public string pay_ewm = "";protected void Page_Load(object sender, EventArgs e){string paybh = Request.QueryString["paybh"];//订单编号string lang = Request.QueryString["lang"];//订单语言dt1 = con.ExeSql("select fid,money,wechatpay_ewm from orders where bh='" + paybh + "' and zt=1 and del=0");if (dt1.Rows.Count > 0){dt2 = con.ExeSql("select exhibitions.mc,exhibitions.emc,pavilion.mc as pavilion,booth.mc as booth,booth.jg,booth.mj,booth.kk from booth inner join pavilion on pavilion.id=booth.pavid inner join exhibitions on exhibitions.id=pavilion.exhiid and booth.id=" + dt1.Rows[0]["fid"].ToString());if (dt2.Rows.Count > 0){pay_mc = translate.content(lang, dt2.Rows[0]["mc"].ToString(), dt2.Rows[0]["emc"].ToString());pay_mc += " " + dt2.Rows[0]["pavilion"].ToString();pay_mc += " " + dt2.Rows[0]["booth"].ToString();pay_jg = dt1.Rows[0]["money"].ToString() + " 元";pay_ewm = "<img src='../" + dt1.Rows[0]["wechatpay_ewm"].ToString() + "' style='width:300px; margin:5px;' />";}dt1.Clear();}dt1.Clear();}}
wechat_Return_url在微信官网中配置
public partial class wechat_Return_url : System.Web.UI.Page{connection con = new connection();DataTable dt1;protected void Page_Load(object sender, EventArgs e){string header = Request.Headers.ToString();//http头string header_Serial = Request.Headers["Wechatpay-Serial"].ToString();//http头平台证书序列号string header_Nonce = Request.Headers["Wechatpay-Nonce"].ToString();//http头应答随机串string header_Timestamp = Request.Headers["Wechatpay-Timestamp"].ToString();//http头应答时间戳string header_Signature = Request.Headers["Wechatpay-Signature"].ToString();//http头应答签名Stream postData = Request.InputStream;//bodyStreamReader sRead = new StreamReader(postData);string postContent = yzin.lr(sRead.ReadToEnd().ToString());if (postContent != null && postContent != "" && postContent.IndexOf("{") > -1){con.ExeSql("insert into tmp (x1,x2,x3,x4,x5,x6,x7,x8)values('微信支付回调','" + DateTime.Now.ToString() + "','" + postContent + "','" + header + "','" + header_Serial + "','" + header_Nonce + "','" + header_Timestamp + "','" + header_Signature + "')");JObject obj1 = JObject.Parse(postContent);string jg = WeChat_Pay.AesGcmDecrypt(obj1["resource"]["associated_data"].ToString(), obj1["resource"]["nonce"].ToString(), obj1["resource"]["ciphertext"].ToString());con.ExeSql("insert into tmp (x1,x2,x3,x4)values('微信支付回调解密','" + DateTime.Now.ToString() + "','" + postContent + "','" + jg + "')");JObject obj2 = JObject.Parse(jg);if (obj2["trade_state"].ToString() == "SUCCESS"){dt1 = con.ExeSql("select id from orders where bh='" + obj2["out_trade_no"].ToString() + "' and zt=1 and del=0");if (dt1.Rows.Count > 0){con.ExeSql("update orders set num='" + obj2["transaction_id"].ToString() + "',paytime='" + Convert.ToDateTime(obj2["success_time"].ToString()).ToString() + "',pay_openid='" + obj2["payer"]["openid"].ToString() + "',zt='2' where id=" + dt1.Rows[0]["id"].ToString());pay_success.fin(obj2["out_trade_no"].ToString());}dt1.Clear();}else{//con.ExeSql("update exhi_com_srv set alipay='" + obj2["transaction_id"].ToString() + "',pay_platform='" + obj2["trade_type"].ToString() + "',bank_type='" + obj2["bank_type"].ToString() + "',pay_openid='" + obj2["payer"]["openid"].ToString() + "',paysj='" + Convert.ToDateTime(obj2["success_time"].ToString()).ToString() + "',zt='2' where number='" + obj2["out_trade_no"].ToString() + "' and zt=0 and del=0");}}}}
接口方式开发
alipay
wechatpay
pay_zt