时间:2021-05-18
本文实例为大家分享了微信JS SDK支付的具体代码,供大家参考,具体内容如下
模型层实体类:
public class JsEntities { /// <summary> /// 公众号id /// </summary> public string appId { get; set; } /// <summary> /// 时间戳 /// </summary> public string timeStamp { get; set; } /// <summary> /// 随机字符串 /// </summary> public string nonceStr { get; set; } /// <summary> /// 订单详情扩展字符串 /// </summary> public string package { get; set; } /// <summary> /// 签名类型 /// </summary> public string signType { get; set; } /// <summary> /// 签名 /// </summary> public string paySign { get; set; } } public class UnifyEntities { /// <summary> /// 公众账号ID /// </summary> public string appid { get; set; } /// <summary> /// 微信支付分配的商户号 /// </summary> public string mch_id { get; set; } /// <summary> /// 微信支付分配的终端设备号 /// </summary> public string device_info { get; set; } /// <summary> /// 随机字符串,不长于32位 /// </summary> public string nonce_str { get; set; } /// <summary> /// 签名 /// </summary> public string sign { get; set; } /// <summary> /// 商品描述最大长度127 /// </summary> public string body { get; set; } /// <summary> /// 附加数据,原样返回 /// </summary> public string attach { get; set; } /// <summary> /// 商户系统内部的订单号,32 个字符内、可包含字母,确保在商户系统唯一,详细说明 /// </summary> public string out_trade_no { get; set; } /// <summary> /// 订单总金额,单位为分,不能带小数点 /// </summary> public string total_fee { get; set; } /// <summary> /// 终端IP /// </summary> public string spbill_create_ip { get; set; } /// <summary> /// 交易起始时间 /// </summary> public string time_start { get; set; } /// <summary> /// 交易结束时间 /// </summary> public string time_expire { get; set; } /// <summary> /// 接收微信支付成功通知 /// </summary> public string notify_url { get; set; } /// <summary> /// JSAPI、NATIVE、APP /// </summary> public string trade_type { get; set; } /// <summary> /// 用户在商户appid下的唯一标识,trade_type为JSAPI 时,此参数必传 /// </summary> public string openid { get; set; } /// <summary> /// 只在 trade_type 为 NATIVE 时需要填写。此id为二维码中包含的商品ID,商户自行维护。 /// </summary> public string product_id { get; set; } } public class UnifyReceive { /// <summary> /// SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断 /// </summary> public string return_code { get; set; } /// <summary> /// 返回信息,如非空,为错误原因 /// </summary> public string return_msg { get; set; } /// <summary> /// 微信分配的公众账号ID /// </summary> public string appid { get; set; } /// <summary> /// 微信支付分配的商户号 /// </summary> public string mch_id { get; set; } /// <summary> /// 随机字符串,不长于32位 /// </summary> public string nonce_str { get; set; } /// <summary> /// 签名 /// </summary> public string sign { get; set; } /// <summary> /// 业务结果 /// </summary> public string result_code { get; set; } /// <summary> /// 预支付ID /// </summary> public string prepay_id { get; set; } /// <summary> /// 交易类型 /// </summary> public string trade_type { get; set; } /// <summary> /// 二维码链接 /// </summary> public string code_url { get; set; } public UnifyReceive(string xml) { XElement doc = XElement.Parse(xml); return_code = doc.Element("return_code").Value; return_msg = doc.Element("return_msg").Value; if (return_code == "SUCCESS") { appid = doc.Element("appid").Value; mch_id = doc.Element("mch_id").Value; nonce_str = doc.Element("nonce_str").Value; sign = doc.Element("sign").Value; result_code = doc.Element("result_code").Value; if (result_code == "SUCCESS") { trade_type = doc.Element("trade_type").Value; prepay_id = doc.Element("prepay_id").Value; if (trade_type == "NATIVE") { code_url = doc.Element("code_url").Value; } trade_type = doc.Element("trade_type").Value; } } } }TestJs.aspx内容:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JsPay.aspx.cs" Inherits="WeChatPayDemo.JsPay" %><html xmlns="http://puteHash(data); md5.Clear(); string str = ""; for (int i = 0; i < md5data.Length; i++) { str += md5data[i].ToString("x").PadLeft(2, '0'); } return str; } #endregion public static string HttpPost(string url, string param) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; StreamWriter requestStream = null; WebResponse response = null; string responseStr = null; try { requestStream = new StreamWriter(request.GetRequestStream()); requestStream.Write(param); requestStream.Close(); response = request.GetResponse(); if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEnd(); reader.Close(); } } catch (Exception) { throw; } finally { request = null; requestStream = null; response = null; } return responseStr; } /// <summary> /// datetime转换为unixtime /// </summary> /// <param name="time"></param> /// <returns></returns> public static int ConvertDateTimeInt(System.DateTime time) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); return (int)(time - startTime).TotalSeconds; } public static bool WriteTxt(string str) { try { FileStream fs = new FileStream(HttpContext.Current.Request.MapPath("/bugLog.txt"), FileMode.Append); StreamWriter sw = new StreamWriter(fs); //开始写入 sw.WriteLine(str); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); } catch (Exception) { return false; } return true; } /// <summary> /// 生成二维码流 /// </summary> /// <param name="qrcontent"></param> /// <returns></returns> public static MemoryStream GetQrCodeStream(string qrcontent) { //误差校正水平 ErrorCorrectionLevel ecLevel = ErrorCorrectionLevel.M; //空白区域 QuietZoneModules quietZone = QuietZoneModules.Zero; int ModuleSize = 120;//大小 QrCode qrCode; var encoder = new QrEncoder(ecLevel); //对内容进行编码,并保存生成的矩阵 if (encoder.TryEncode(qrcontent,out qrCode)) { var render = new GraphicsRenderer(new FixedCodeSize(ModuleSize, quietZone)); MemoryStream stream = new MemoryStream(); render.WriteToStream(qrCode.Matrix, ImageFormat.Jpeg,stream); return stream; } return null; } public static void GetQrCode(string qrcontent) { MemoryStream ms = GetQrCodeStream(qrcontent); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ContentType = "image/Png"; HttpContext.Current.Response.BinaryWrite(ms.ToArray()); } }}本文已被整理到了《ASP.NET微信开发教程汇总》,欢迎大家学习阅读。
为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本部分需要用到微信的js-sdk,微信js-sdk是微信公众平台面向网页开发者提供的基于微信内的网页开发工具包。通过使用微信js-sdk,网页开发者可借助微信高
最近开发微信公众号内嵌H5页面,使用vue搭建的项目,由于业务需求,需要实现微信自定义分享功能,所以项目中集成微信JS-SDK。微信JS-SDK是微信公众平台面
asp.net中html标签代码:复制代码代码如下:普通的html标签:复制代码代码如下:对于ASP.NET或普通的HTML标签,下面JS代码都适用:复制代码代
测试js的接口功能,我用的是BAE服务器不是SAE服务器。SAE服务器不能写入文件,测试会出问题。什么叫js-sdk,我先演示js-sdk接口的具体作用。我在微
用于记录接入微信JS-SDK的坑,以后方便查询第一次接入公众号微信支付、分享、定位等等的坑的时候,心里是迷茫而又恐惧。因为,听说坑特别多,后来发现自己的亲身体验