ZhiYeJianKang_PeiXun/Song.Site/Pay/Weixin/ProductPage.aspx.cs

89 lines
3.2 KiB
C#
Raw Normal View History

2025-02-20 15:41:53 +08:00
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WxPayAPI
{
public partial class ProductPage : System.Web.UI.Page
{
/// <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;}
protected void Page_Load(object sender, EventArgs e)
{
Log.Info(this.GetType().ToString(), "page load");
if (!IsPostBack)
{
JsApiPay jsApiPay = new JsApiPay(this);
try
{
//调用【网页授权获取用户信息】接口获取用户的openid和access_token
jsApiPay.GetOpenidAndAccessToken();
//获取收货地址js函数入口参数
wxEditAddrParam = jsApiPay.GetEditAddressParameters();
ViewState["openid"] = jsApiPay.openid;
}
catch (Exception ex)
{
Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
Button1.Visible = false;
Button2.Visible = false;
Label1.Visible = false;
Label2.Visible = false;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string total_fee = "1";
if(ViewState["openid"] != null)
{
string openid = ViewState["openid"].ToString();
string url = "JsApiPayPage.aspx?openid=" + openid + "&total_fee=" + total_fee;
Response.Redirect(url);
}
else
{
Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面缺少参数,请返回重试" + "</span>");
Button1.Visible = false;
Button2.Visible = false;
Label1.Visible = false;
Label2.Visible = false;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string total_fee = "2";
if (ViewState["openid"] != null)
{
string openid = ViewState["openid"].ToString();
string url = "JsApiPayPage.aspx?openid=" + openid + "&total_fee=" + total_fee;
Response.Redirect(url);
}
else
{
Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面缺少参数,请返回重试" + "</span>");
Button1.Visible = false;
Button2.Visible = false;
Label1.Visible = false;
Label2.Visible = false;
}
}
}
}