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