asp.net 微信支付源码demo 官方坑爹

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
using System.Web.Script.Serialization;
using System.Configuration;
//using LitJson;

namespace WxPayAPI
{
public partial class _Default : System.Web.UI.Page
{
protected string code="";
public string website = ConfigurationManager.AppSettings["website"].ToString();
protected void Page_Load(object sender, EventArgs e)
{

if (Request.QueryString["code"] == null)
Response.Redirect("../user.aspx");
else
code = Request.QueryString["code"];


//Log.Info(this.GetType().ToString(), "page load");

//string postcodeUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";

//string weburl = website+"web/wechat/bucaoxin/user.aspx";

//JavaScriptSerializer Jss = new JavaScriptSerializer();
code
//string url = string.Format(postcodeUrl, WxPayConfig.APPID, weburl);

//HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
//HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//string respText = "";
//using (Stream resStream = response.GetResponseStream())
//{
// StreamReader reader = new StreamReader(resStream, Encoding.Default);
// respText = reader.ReadToEnd();
// resStream.Close();
//}
//Dictionary<string, object> respDic = (Dictionary<string, object>)Jss.DeserializeObject(respText);
// code = respDic["code"].ToString();


}
}

}



--------------------------------------------------


using HModel;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using weikeweixin.web.wechat.cs;

namespace WxPayAPI
{
    public partial class ProductPage :userbase
    {
        /// <summary>
        /// 调用js获取收货地址时需要传入的参数
        /// 格式:json串
        /// 包含以下字段:
        ///     appid:公众号id
        ///     scope: 填写“jsapi_address”,获得编辑地址权限
        ///     signType:签名方式,目前仅支持SHA1
        ///     addrSign: 签名,由appid、url、timestamp、noncestr、accesstoken参与签名
        ///     timeStamp:时间戳
        ///     nonceStr: 随机字符串
        /// </summary>
        public static string wxEditAddrParam {get;set;}
        public string web = ConfigurationManager.AppSettings["website"].ToString()+ "web/wechat/bucaoxin/wxpay/example/JsApiPayPage.aspx?openid=";

        public string person = "", price = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {

                    if (Request.QueryString["id"] != null)
                    {
                        string id = Request.QueryString["id"].ToString();
                        ek_user u = Bll.Bll_ek_user.GetEntityById(id);

                       // Bll.Bll_ek_userorder.GetEntityById(ek_userorder._.uaskuid == id&&ek_userorder._.uenddate.b);

                        person = u.cname;
                        price = u.fee;

                        //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                        jsApiPay.GetOpenidAndAccessToken();
                       // MessageBox.Show(Page, id);

                        //获取收货地址js函数入口参数
                        // wxEditAddrParam = jsApiPay.GetEditAddressParameters();
                        Session["openid"] = jsApiPay.openid;



                    }
                    else {
                        Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试。【参数有问题】</span>");
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试"+ex.Message + "</span>");
                    
                }
            }
        }

        protected void btnPay_Click(object sender, EventArgs e)
        {
            if (Session["openid"] != null)
            {

                string openid = Session["openid"].ToString();
                string url = web + openid + "&id="+Request.QueryString["id"];
                Response.Redirect(url);
            }
            else
            {
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面缺少参数,请返回重试" + "</span>");
             
            }
        }
        
     
    }
}


-------------------------------------------



using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Threading;
using LitJson;
using System.Web.Security;
using weikeweixin.web.wechat.cs;
using HModel;
using weikebuluo.Common;
using weikebuluo.DBUtility;

namespace WxPayAPI
{
    public partial class JsApiPayPage : userbase
    {
        public DateTime GetDataBaseDate()
        {
            string strSql = " select getdate()";
            string date = DbHelperSQL.GetSingle(strSql.ToString()).ToString();
            return DateTime.Parse(date);
        }
        public static string wxJsApiParam { get; set; } //H5调起JS API参数

        JsApiPay jsApiPay = null;
        public int res = 0;
        public string uid = "0";
        protected void Page_Load(object sender, EventArgs e)
        {


            if (Request.QueryString["action"] != null && (Request.QueryString["id"] != null))
            {
                if (Request.QueryString["action"] == "updateorder")
                {
                    string uid = Request.QueryString["id"].ToString();
                    ek_userorder order = Bll.Bll_ek_userorder.GetEntityById(uid);
                    order.Attach();
                    order.ustate = 2; //
                    int res = Bll.Bll_ek_userorder.UpdateEntity(order);
                      
                    try
                    {
                        //自动变成会员
                        ek_user u = Bll.Bll_ek_user.GetEntityById(order.uaskuid);
                        u.Attach();
                        if (u.ctype == "游客")
                        {
                            u.ctype = "会员";
                            int resu = Bll.Bll_ek_user.UpdateEntity(u);
                        }
                    }
                    catch (Exception ex)
                    {

                        FileOperate.WriteErrorLog("", ex, "");
                    }
                    Response.Write(res);
                    Response.End();
                }

            }
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                if (Request.QueryString["openid"] != null && Request.QueryString["id"] != null)
                {
                    string openid = Request.QueryString["openid"];
                    string id = Request.QueryString["id"];

                    //检测是否给当前页面传递了相关参数
                    if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(id))
                    {
                        Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
                        Log.Error(this.GetType().ToString(), "没有参数错误...");
                        // submit.Visible = false;
                        return;
                    }

                    ek_user u = Bll.Bll_ek_user.GetEntityById(id);
                    if (u != null)
                    {
                        try
                        {
                            int total_fee = int.Parse(u.fee) * 100;
                            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                            jsApiPay = new JsApiPay(this);
                            jsApiPay.openid = openid;
                            jsApiPay.total_fee = total_fee;
                            jsApiPay.body = "咨询费用";
                            jsApiPay.goods_tag = "咨询费用/年";
                            jsApiPay.out_trade_no = WxPayApi.GenerateOutTradeNo();

                            DateTime date = GetDataBaseDate();
                            ek_userorder order = new ek_userorder();
                            order.utradeno = jsApiPay.out_trade_no;
                            order.umark = "咨询费用";
                            order.uaskuid = user.id;
                            order.upaydate = date;
                            order.uanswerid = u.id;
                            order.upaymoney = decimal.Parse(u.fee);
                            order.uenddate = date.AddYears(1);
                            order.uscore = 0;
                            order.uasksay = "";
                            order.uadvice = "";
                            order.utime = date;
                            order.ustate = 1;  // 1未付款 2已付款

                            res = Bll.Bll_ek_userorder.InsertEntity(order);
                             
                            uid = u.id.ToString();

                            //JSAPI支付预处理

                            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                            wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数                    
                            Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                            //在页面上显示订单信息


                            string htmlstr = "";


                            htmlstr += "订单号:" + jsApiPay.out_trade_no + " <br/><br/>";
                            htmlstr += "咨询师:" + u.cname + " <br/><br/>";
                            htmlstr += "开始时间:" + order.upaydate + " <br/><br/>";
                            htmlstr += "结束时间:" + order.uenddate + " <br/><br/>";
                            htmlstr += "年费金额:" + u.fee + "元 <br/><br/>";
                            htmlstr += "当前订单生成,请耐心等待...";

                            Response.Write("<div style='padding:10px 20px; font-size:20px;color:#fff; background-color:#ff6a00; '>订单详情</div><br/>");
                            Response.Write("<span style='color:#00CD00;font-size:20px'>" + htmlstr + "</span>");

                            //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "-" + wxJsApiParam + "</span>");
                        }
                        catch (Exception ex)
                        {
                            FileOperate.WriteErrorLog("", ex, "");
                            Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试.<a href='../../userinfo.aspx'>返回个人中心</a></span>");
                        }
                    }
                }
            }
        }
    }
}

下载地址

http://yunpan.cn/cFhkjEgbrXtiH  访问密码 3cae



ASP.NET 微信开发源码是为了在ASP.NET平台上实现微信开发而提供的源代码。微信开发是指利用微信提供的开发接口和功能,开发出基于微信平台的应用程序或网站,以实现与微信用户的交互和功能扩展。 ASP.NET是一种用于构建Web应用程序和网站的开发框架,而微信开发源码则是在ASP.NET框架下,基于微信公众平台或企业微信开发接口,实现了与微信的集成和功能开发。它包括了与微信平台的交互代码、消息处理代码、用户验证代码、素材管理代码等一系列功能模块的实现。 使用ASP.NET微信开发源码,可以方便地实现微信公众号或企业微信的开发需求,例如消息回复、菜单管理、用户管理、素材上传下载等功能。借助ASP.NET框架的优势,可以高效地处理微信用户的请求,并根据需要进行业务逻辑处理和数据交互。 ASP.NET微信开发源码通常会包含一个可扩展的框架,使开发者能够快速搭建一个与微信平台对接的应用程序。开发者可以根据自己的需求和业务场景,对源码进行定制和扩展,以实现更复杂的功能或个性化的交互体验。 在使用ASP.NET微信开发源码进行微信开发时,需要了解微信平台的开发接口和规范,并熟悉ASP.NET框架的开发方式与特点。通过合理利用ASP.NET微信开发源码,可以快速、高效地开发出符合微信用户需求的应用程序,并与微信平台进行无缝对接。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值