经过摸索,给calc.xycost.com网站加上了用户自助付费成为会员功能,其中的支付环节是重点,下面是简要的过程:

我采用的是迅虎支付(虎皮椒支付),以此为例:pay.cs的内容,注意跳转链接无法使用通用的&字符,会提示错误。只能使用;号再在程序中解析,当然更好的方法是使用URL路由。

public string Index(string grade, string money, string UserID)
{
    var json = new JObject();

    try
    {
       trade_order_id = GenerateOutTradeNo();//网站生成订单号

        var dic = new Dictionary<string, string>
        {
            {"version", "1.1"},
            {"lang", "zh-cn"},
            {"plugins", "test-001"},
            {"appid", ""},//appid
            {"appsecret", ""},//appsecret
            {"trade_order_id", trade_order_id},//订单号Generate.GenerateOutTradeNo()
            {"payment", "wechat"},//支付类型
            {"total_fee", money},//金额
            {"title", HttpUtility.UrlEncode("BIM")},//标题,中文需要编码“HttpUtility.UrlEncode()”
            {"time", GetCurrentTimestamp().ToString()},//时间戳
            {"notify_url", "https://calc.xycost.com/login/notify.ashx"},//通知链接http://localhost:62443/通知链接https://calc.xycost.com/login/notify.ashx
            {"return_url", $"https://calc.xycost.com/login/user.aspx?UserID={UserID};money={money};grade={grade};trade_order_id={trade_order_id}"},//跳转链接
            {"nonce_str", GenerateRandomString()},//随机字符串
        };

        dic.Add("hash", Sign(dic));

        var sr = JsonConvert.DeserializeObject<SamplesResult>(PostHttp(dic));

        json.Add(new JProperty("openid", sr.Openid));
        json.Add(new JProperty("url", sr.Url));
        json.Add(new JProperty("errcode", sr.Errcode));
        json.Add(new JProperty("errmsg", sr.Errmsg));
        json.Add(new JProperty("hash", sr.Hash));

    }
    catch (Exception e)
    {
        throw e;
    }

    return json.ToString();
}

回调函数notify.ashx,注意下面的内容在VS中无法直接编辑,需要手动记事本添加

<%@ WebHandler Language=”C#” CodeBehind=”notify.ashx.cs” Class=”EngineeringConstructionCost.Login.NotifyHandler” %>

notify.ashx.cs的内容

using System.Web;

namespace EngineeringConstructionCost.Login
{
public class NotifyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// 读取请求参数
HttpRequest request = context.Request;
string tradeOrderId = request.Params["trade_order_id"];
string totalFee = request.Params["total_fee"];
string transactionId = request.Params["transaction_id"];
string plugins = request.Params["plugins"];
string status = request.Params["status"];
string hash = request.Params["hash"];

        // 返回成功响应
        HttpResponse response = context.Response;
        response.ContentType = "text/plain";
        response.Write("success");
    }

    public bool IsReusable
    {
        get { return false; }
    }
}}

0

评论0

请先
GB 5768.1~8-系列图集 道路交通标志和标线-高清无水印PDF下载
GB 5768.1~8-系列图集 道路交通标志和标线-高清无水印PDF下载
8分钟前 有人购买 去瞅瞅看

社交账号快速登录

微信扫一扫关注
扫码关注后会自动登录网站